diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6736225f0e9..62559c8fc65 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,11 +52,10 @@ jobs: split: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] runs-on: ${{ matrix.config.os }} - env: - PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }} MPLBACKEND: Agg # non-interactive backend for matplotlib - + PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }} + PYTHONWARNDEFAULTENCODING: "true" # PEP 597: Enable optional EncodingWarning steps: - name: Check out repo uses: actions/checkout@v4 @@ -106,6 +105,8 @@ jobs: - name: pytest split ${{ matrix.split }} env: + MPLBACKEND: Agg # non-interactive backend for matplotlib + PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }} PMG_TEST_FILES_DIR: "${{ github.workspace }}/tests/files" run: | micromamba activate pmg diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d57d1fa0207..5dbb8143a68 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.1 + rev: v0.9.0 hooks: - id: ruff args: [--fix, --unsafe-fixes] @@ -22,7 +22,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.13.0 + rev: v1.14.1 hooks: - id: mypy @@ -65,6 +65,6 @@ repos: args: [--drop-empty-cells, --keep-output] - repo: https://github.com/RobertCraigie/pyright-python - rev: v1.1.389 + rev: v1.1.391 hooks: - id: pyright diff --git a/dev_scripts/chemenv/explicit_permutations.py b/dev_scripts/chemenv/explicit_permutations.py index f3225fa5293..96dd93ff829 100644 --- a/dev_scripts/chemenv/explicit_permutations.py +++ b/dev_scripts/chemenv/explicit_permutations.py @@ -93,5 +93,5 @@ class Algo: cg._algorithms = [ExplicitPermutationsAlgorithm(permutations=explicit_permutations)] new_geom_dir = "new_geometry_files" os.makedirs(new_geom_dir, exist_ok=True) - with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w") as file: + with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w", encoding="utf-8") as file: json.dump(cg.as_dict(), file) diff --git a/dev_scripts/chemenv/explicit_permutations_plane_algorithm.py b/dev_scripts/chemenv/explicit_permutations_plane_algorithm.py index 87f7ec9088d..951788cb242 100644 --- a/dev_scripts/chemenv/explicit_permutations_plane_algorithm.py +++ b/dev_scripts/chemenv/explicit_permutations_plane_algorithm.py @@ -159,5 +159,5 @@ if test == "y": cg._algorithms = new_algos cg_dict = cg.as_dict() - with open(f"../coordination_geometries_files_new/{cg_symbol}.json", mode="w") as file: + with open(f"../coordination_geometries_files_new/{cg_symbol}.json", mode="w", encoding="utf-8") as file: json.dump(cg_dict, file) diff --git a/dev_scripts/chemenv/get_plane_permutations_optimized.py b/dev_scripts/chemenv/get_plane_permutations_optimized.py index f1b399193aa..f2e2e8ff9b2 100644 --- a/dev_scripts/chemenv/get_plane_permutations_optimized.py +++ b/dev_scripts/chemenv/get_plane_permutations_optimized.py @@ -444,5 +444,5 @@ def random_permutations_iterator(initial_permutation, n_permutations): if test == "y": new_geom_dir = "new_geometry_files" os.makedirs(new_geom_dir, exist_ok=True) - with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w") as file: + with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w", encoding="utf-8") as file: json.dump(cg.as_dict(), file) diff --git a/dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py b/dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py index c14b5f9709d..6e1aa545e80 100644 --- a/dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py +++ b/dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py @@ -171,7 +171,7 @@ def get_structure(self, morphing_factor): for morphing in self.morphing_description: if morphing["site_type"] != "neighbor": - raise ValueError(f"Key \"site_type\" is {morphing['site_type']} while it can only be neighbor") + raise ValueError(f'Key "site_type" is {morphing["site_type"]} while it can only be neighbor') site_idx = morphing["ineighbor"] + 1 if morphing["expansion_origin"] == "central_site": diff --git a/dev_scripts/chemenv/view_environment.py b/dev_scripts/chemenv/view_environment.py index f8eae1e02a6..e3a080b0eaf 100644 --- a/dev_scripts/chemenv/view_environment.py +++ b/dev_scripts/chemenv/view_environment.py @@ -29,8 +29,7 @@ vis = None while True: cg_symbol = input( - 'Enter symbol of the geometry you want to see, "l" to see the list ' - 'of existing geometries or "q" to quit : ' + 'Enter symbol of the geometry you want to see, "l" to see the list of existing geometries or "q" to quit : ' ) if cg_symbol == "q": break diff --git a/dev_scripts/potcar_scrambler.py b/dev_scripts/potcar_scrambler.py index 23cd1403eb9..4a5bb292a82 100644 --- a/dev_scripts/potcar_scrambler.py +++ b/dev_scripts/potcar_scrambler.py @@ -124,7 +124,7 @@ def scramble_single_potcar(self, potcar: PotcarSingle) -> str: return scrambled_potcar_str def to_file(self, filename: str) -> None: - with zopen(filename, mode="wt") as file: + with zopen(filename, mode="wt", encoding="utf-8") as file: file.write(self.scrambled_potcars_str) @classmethod diff --git a/dev_scripts/regen_libxcfunc.py b/dev_scripts/regen_libxcfunc.py index 7524f460030..64e5f982068 100755 --- a/dev_scripts/regen_libxcfunc.py +++ b/dev_scripts/regen_libxcfunc.py @@ -10,10 +10,11 @@ from __future__ import annotations import json -import os import sys from copy import deepcopy +from pymatgen.core import PKG_DIR + def parse_libxc_docs(path): """Parse libxc_docs.txt file, return dictionary {libxc_id: info_dict}.""" @@ -27,7 +28,7 @@ def parse_section(section): return int(dct["Number"]), dct dct = {} - with open(path) as file: + with open(path, encoding="utf-8") as file: section = [] for line in file: if not line.startswith("-"): @@ -62,7 +63,7 @@ def write_libxc_docs_json(xc_funcs, json_path): if desc is not None: xc_funcs[num][opt] = desc - with open(json_path, "w") as fh: + with open(json_path, "w", encoding="utf-8") as fh: json.dump(xc_funcs, fh) return xc_funcs @@ -85,8 +86,7 @@ def main(): xc_funcs = parse_libxc_docs(path) # Generate new JSON file in pycore - pmg_core = os.path.abspath("../pymatgen/core/") - json_path = f"{pmg_core}/libxc_docs.json" + json_path = f"{PKG_DIR}/core/libxc_docs.json" write_libxc_docs_json(xc_funcs, json_path) # Build new enum list. @@ -99,8 +99,8 @@ def main(): # Re-generate enumerations. # [0] read py module. - xc_funcpy_path = f"{pmg_core}/libxcfunc.py" - with open(xc_funcpy_path) as file: + xc_funcpy_path = f"{PKG_DIR}/core/libxcfunc.py" + with open(xc_funcpy_path, encoding="utf-8") as file: lines = file.readlines() # [1] insert new enum values in list diff --git a/dev_scripts/update_pt_data.py b/dev_scripts/update_pt_data.py index af007d819b4..252ffd3b999 100644 --- a/dev_scripts/update_pt_data.py +++ b/dev_scripts/update_pt_data.py @@ -13,7 +13,7 @@ from monty.serialization import dumpfn, loadfn from ruamel import yaml -from pymatgen.core import Element, get_el_sp +from pymatgen.core import PKG_DIR, Element, get_el_sp try: from bs4 import BeautifulSoup @@ -25,7 +25,7 @@ def parse_oxi_state(): data = loadfn(PTABLE_YAML_PATH) - with open("oxidation_states.txt") as file: + with open("oxidation_states.txt", encoding="utf-8") as file: oxi_data = file.read() oxi_data = re.sub("[\n\r]", "", oxi_data) patt = re.compile("