Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: Enable tests for python 3.12 #305

Merged
merged 4 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- os: ubuntu-latest
special: ['no optional']
version: '3.11'
- os: ubuntu-latest
special: ['no optional']
version: '3.12'
- os: ubuntu-latest
special: ['CP2K', '6.1', 'ssmp']
version: '3.11'
Expand Down Expand Up @@ -84,15 +87,20 @@ jobs:
with:
python-version: ${{ matrix.version }}

# TODO: Remove the manual h5py building once h5py 3.10 has been released with cp312 wheels
- name: Install dependencies
run: |
pip install --upgrade pip
case "${{ matrix.special[0] }}" in
"pre-release")
pip install --pre -e .[test] --upgrade --force-reinstall
pip install git+https://github.com/NLeSC/noodles@master --upgrade
;;
"no optional")
if [[ "${{ matrix.version }}" == '3.12' ]]; then
sudo apt-get update
sudo apt-get install libhdf5-dev
pip install git+https://github.com/h5py/h5py@89e1e2e78d7fb167d2a67c9a8354ced6491160fe
fi
pip install -e .[test-no-optional]
;;
*)
Expand Down
7 changes: 0 additions & 7 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,3 @@ build:
# Optionally set the version of Python and requirements required to build your docs
conda:
environment: doc_environment.yml

python:
install:
- method: pip
path: .
extra_requirements:
- doc
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def reload_qmflows() -> Generator[None, None, None]:
def configure_plams_logger() -> "Generator[None, None, None]":
"""Remove the date/time prefix from the PLAMS logging output."""
# Ensure the plams.config dict is populated by firing up plams.init once
with open(os.devnull, "w") as f1, tempfile.TemporaryDirectory() as f2:
with open(os.devnull, "w", encoding="utf8") as f1, tempfile.TemporaryDirectory() as f2:
with contextlib.redirect_stdout(f1), InitRestart(f2):
pass

Expand Down
3 changes: 3 additions & 0 deletions doc_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ channels:
dependencies:
- python
- pandoc # pandoc on pypi is poorly maintaned; use conda-forge instead
- pip
- pip:
- .[doc]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ requires-python = ">=3.8"
dependencies = [
"more-itertools",
"h5py",
"numpy>=1.21",
"numpy>=1.21,<2",
"pandas",
"noodles>=0.3.3",
"plams==1.5.1",
Expand Down
2 changes: 1 addition & 1 deletion src/qmflows/packages/_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

def inithess() -> None:
hess_path = get_tmpfile_name("ADF_hessian_")
hess_file = open(hess_path, "w")
hess_file = open(hess_path, "w", encoding="utf8")

Check warning on line 61 in src/qmflows/packages/_scm.py

View check run for this annotation

Codecov / codecov/patch

src/qmflows/packages/_scm.py#L61

Added line #L61 was not covered by tests
hess_file.write(" ".join(['{:.6f}'.format(v) for v in value]))
settings.specific[package].geometry.inithess = hess_path.as_posix()

Expand Down
2 changes: 1 addition & 1 deletion src/qmflows/parsers/_cp2k_basis_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ def read_cp2k_basis(file: PathLike, *, allow_multiple_exponents: bool = False) -
Whether to allow the parsing of basis sets consisting of multiple exponent sets.

"""
with open(file, "r") as f:
with open(file, "r", encoding="utf8") as f:
return _read_basis(_BasisFileIter(f, start=1), allow_multiple_exponents)
8 changes: 4 additions & 4 deletions src/qmflows/parsers/_cp2k_orbital_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _find_mo_start(path: str | os.PathLike[str], unrestricted: bool) -> int | tu
and a single integer otherwise.

"""
with open(path, "r") as f:
with open(path, "r", encoding="utf8") as f:
# Find all headers, but skip restarts
enumerator = enumerate((h.strip("MO| \n") for h in f), start=1)
headers = [(i, h) for i, h in enumerator if "EIGENVALUES" in h]
Expand Down Expand Up @@ -153,7 +153,7 @@ def read_coefficients(

j0 = 0
j1 = 0
with open(path, "r") as f:
with open(path, "r", encoding="utf8") as f:
iterator = filter(None, (i.strip("MO| \n") for i in islice(f, start, None)))
for h in iterator:
# Each MO pair is preceded by their indices,
Expand Down Expand Up @@ -192,8 +192,8 @@ def read_coefficients(

def read_cp2k_number_of_orbitals(file_name: str | os.PathLike[str]) -> MO_metadata:
"""Extract the number of (occupied) orbitals and basis functions."""
with open(file_name, "r") as f:
kwargs: "dict[str, list[int]]" = defaultdict(list)
with open(file_name, "r", encoding="utf8") as f:
kwargs: defaultdict[str, list[int]] = defaultdict(list)
for line in f:
match = _ORBITAL_PATTERN.search(line)
if match is None:
Expand Down
10 changes: 5 additions & 5 deletions src/qmflows/parsers/cp2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def read_cp2k_xyz(path: PathLike, dtype: DTypeLike = np.float64) -> NDArray[Any]
Requires a CP2K ``*.xyz`` file.

"""
with open(path, 'r') as f:
with open(path, 'r', encoding="utf8") as f:
n_atom = int(next(f))
flat_iter = chain.from_iterable(_read_cp2k_xyz(f, n_atom))
ret = np.fromiter(flat_iter, dtype=dtype)
Expand Down Expand Up @@ -238,7 +238,7 @@ def read_cp2k_table(
**start**, **stop** and **step** can be used for specifiying the to-be parsed rows.

"""
with open(path, 'r') as f:
with open(path, 'r', encoding="utf8") as f:
flat_iter = (i.split()[column] for i in islice(f, start, stop, step))
return np.fromiter(flat_iter, dtype=dtype)

Expand All @@ -261,7 +261,7 @@ def read_cp2k_table_slc(
**start**, **stop** and **step** can be used for specifiying the to-be parsed rows.

"""
with open(path, 'r') as f:
with open(path, 'r', encoding="utf8") as f:
clm_slc = slice(column_start, column_stop, column_step)
row_slc = islice(f, row_start, row_stop, row_step)
flat_iter = chain.from_iterable(i.split()[clm_slc] for i in row_slc)
Expand Down Expand Up @@ -300,7 +300,7 @@ def read_cp2k_pressure(
major, _ = get_cp2k_version(path)

# Read the pressures
with open(path, 'r') as f:
with open(path, 'r', encoding="utf8") as f:
iterator = _get_pressure_iter(major, f)
return np.fromiter(islice(iterator, start, stop, step), dtype=dtype)

Expand All @@ -313,7 +313,7 @@ def get_cp2k_version(out_file: PathLike) -> CP2KVersion:

Returns :code:`(0, 0)` if the versions cannot be identified.
"""
with open(out_file, 'r') as f:
with open(out_file, 'r', encoding="utf8") as f:
for i in f:
i = i.strip()
if i.startswith("CP2K| version string:"):
Expand Down
2 changes: 1 addition & 1 deletion src/qmflows/parsers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def try_search_pattern(
) -> None | str:
"""Search for an specific pattern in a file."""
try:
with open(file_name, 'r') as f:
with open(file_name, 'r', encoding="utf8") as f:
for line in f:
if re.search(pat, line):
return line
Expand Down
2 changes: 1 addition & 1 deletion src/qmflows/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _read_result_file(result: Result, extension: str, max_line: int = 100) -> No
iterator = (os.path.join(root, i) for i in os.listdir(root)
if os.path.splitext(i)[1] == extension)
for i in iterator:
with open(i, "r") as f:
with open(i, "r", encoding="utf8") as f:
ret_list = f.readlines()
ret = "..." if len(ret_list) > max_line else ""
ret += "".join(ret_list[-max_line:])
Expand Down
5 changes: 4 additions & 1 deletion src/qmflows/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def file_to_context(file: int | PathLike | IO[Any],
"""
# path-like object
try:
if "encoding" not in kwargs:
kwargs["encoding"] = "utf8"
return open(file, **kwargs) # type: ignore

# a file-like object (hopefully)
Expand All @@ -148,7 +150,8 @@ def init_restart(

"""
is_init: bool = config.init
with open(os.devnull, 'w') as f, redirect_stdout(f): # Temporary supress printing
# Temporary supress printing
with open(os.devnull, 'w', encoding="utf8") as f, redirect_stdout(f):
init(path, folder)

# Parse variables
Expand Down
2 changes: 1 addition & 1 deletion test/test_special_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,6 @@ def test_cp2k_mm_keywords():
s.specific.cp2k.force_eval.mm.forcefield.parm_file_name = basename(
s.specific.cp2k.force_eval.mm.forcefield.parm_file_name)

with open(PATH / 'cp2k_mm_special_keyword.yaml', 'rb') as f:
with open(PATH / 'cp2k_mm_special_keyword.yaml', 'r', encoding="utf8") as f:
ref = yaml2Settings(f)
assertion.eq(s.specific, ref)
4 changes: 2 additions & 2 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def test_validate_status() -> None:
validate_status(result)
msg = str(rec.value)

with open(root / "cp2k_opt.out", "r") as f:
with open(root / "cp2k_opt.out", "r", encoding="utf8") as f:
out_ref = textwrap.indent("".join(f.readlines()[-100:]), 4 * " ")
with open(root / "cp2k_opt.err", "r") as f:
with open(root / "cp2k_opt.err", "r", encoding="utf8") as f:
err_ref = textwrap.indent("".join(f.readlines()[-100:]), 4 * " ")

assertion.contains(msg, out_ref)
Expand Down
2 changes: 1 addition & 1 deletion test/test_xyz_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_multiple_geometries():
"""Test the reading of multiples molecular geometries from a file."""
path_xyz = PATH / "molecules" / "five_points_ethylene.xyz"

with open(path_xyz, 'r') as f:
with open(path_xyz, 'r', encoding="utf8") as f:
ls = f.readlines()

xs = [''.join(x) for x in chunked(ls, 8)]
Expand Down
Loading