From e9cfb2cc4c9b8f6c129e48b4374782375c2b6a70 Mon Sep 17 00:00:00 2001 From: Lukas Turcani Date: Thu, 4 Jul 2024 15:01:33 +0100 Subject: [PATCH] Fix lints (#177) --- .github/workflows/tests.yml | 2 +- pyproject.toml | 3 ++- .../calculators/extractors/utilities.py | 5 +---- .../_internal/calculators/orca_calculators.py | 4 ++-- .../_internal/calculators/xtb_calculators.py | 4 ++-- src/stko/_internal/optimizers/collapser.py | 8 +++---- src/stko/_internal/optimizers/gulp.py | 20 +++++++++++------- src/stko/_internal/optimizers/macromodel.py | 21 ++++++++----------- src/stko/_internal/optimizers/utilities.py | 10 ++------- src/stko/_internal/optimizers/xtb.py | 16 +++++++------- 10 files changed, 43 insertions(+), 50 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8061a663..1133aa2f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: python-version: "3.11" cache: "pip" - run: "pip install '.[dev]'" - - run: ruff . + - run: ruff check . mypy: runs-on: ubuntu-22.04 steps: diff --git a/pyproject.toml b/pyproject.toml index 8cde8c16..b06c8de7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,8 @@ maintainers = [ { name = "Lukas Turcani", email = "lukasturcani93@gmail.com" }, ] dependencies = [ - "rdkit", + "numpy==1.26.4", # remove pin when ecosystem updates to 2.0 + "rdkit==2023.9.5", # remove pin when type issues are resolved "stk", "networkx", ] diff --git a/src/stko/_internal/calculators/extractors/utilities.py b/src/stko/_internal/calculators/extractors/utilities.py index efd23382..0f09eb94 100644 --- a/src/stko/_internal/calculators/extractors/utilities.py +++ b/src/stko/_internal/calculators/extractors/utilities.py @@ -17,7 +17,4 @@ def check_line(line: str, option: str, options_dict: dict[str, str]) -> bool: Returns ``True`` if the desired string is present. """ - if options_dict[option] in line: - return True - - return False + return options_dict[option] in line diff --git a/src/stko/_internal/calculators/orca_calculators.py b/src/stko/_internal/calculators/orca_calculators.py index ef26d049..8e1fa4d4 100644 --- a/src/stko/_internal/calculators/orca_calculators.py +++ b/src/stko/_internal/calculators/orca_calculators.py @@ -248,13 +248,13 @@ def _run_orca( # noqa: PLR0913 with out_file.open("w") as f: # Note that sp.call will hold the program until # completion of the calculation. - sp.call( + sp.call( # noqa: S602 cmd, stdin=sp.PIPE, stdout=f, stderr=sp.PIPE, # Shell is required to run complex arguments. - shell=True, # noqa: S602 + shell=True, ) self._check_outcome(out_file) if self._discard_output: diff --git a/src/stko/_internal/calculators/xtb_calculators.py b/src/stko/_internal/calculators/xtb_calculators.py index 0aa90d64..a7da18f2 100644 --- a/src/stko/_internal/calculators/xtb_calculators.py +++ b/src/stko/_internal/calculators/xtb_calculators.py @@ -323,13 +323,13 @@ def _run_xtb( with out_file.open("w") as f: # Note that sp.call will hold the program until # completion of the calculation. - sp.call( + sp.call( # noqa: S602 cmd, stdin=sp.PIPE, stdout=f, stderr=sp.PIPE, # Shell is required to run complex arguments. - shell=True, # noqa: S602 + shell=True, ) finally: os.chdir(init_dir) diff --git a/src/stko/_internal/optimizers/collapser.py b/src/stko/_internal/optimizers/collapser.py index 69b001a2..dcaa4bdf 100644 --- a/src/stko/_internal/optimizers/collapser.py +++ b/src/stko/_internal/optimizers/collapser.py @@ -661,10 +661,10 @@ def _output_top_lines(self) -> str: def _plot_progess( # noqa: PLR0913 self, - steps: abc.Iterable, - maxds: abc.Iterable, - spots: abc.Iterable, - npots: abc.Iterable, + steps: list, + maxds: list, + spots: list, + npots: list, output_dir: Path, ) -> None: fig, ax = plt.subplots(figsize=(8, 5)) diff --git a/src/stko/_internal/optimizers/gulp.py b/src/stko/_internal/optimizers/gulp.py index 4347ed02..cb61669c 100644 --- a/src/stko/_internal/optimizers/gulp.py +++ b/src/stko/_internal/optimizers/gulp.py @@ -5,6 +5,7 @@ import shutil import subprocess as sp import uuid +import warnings from pathlib import Path import stk @@ -547,12 +548,15 @@ def assign_FF(self, mol: stk.Molecule) -> None: # noqa: N802 The molecule to be optimized. """ - FutureWarning( - "We have found some minor discrepancies in this " - "assignment algorithm, which is based off rdkit code. " - "Changes should come soon. This UFF optimisation should " - " not be your final step! Due to this, some tests in " - "test_uff_assign_ff.py have been muted." + warnings.warn( + FutureWarning( + "We have found some minor discrepancies in this " + "assignment algorithm, which is based off rdkit code. " + "Changes should come soon. This UFF optimisation should " + " not be your final step! Due to this, some tests in " + "test_uff_assign_ff.py have been muted." + ), + stacklevel=2, ) metal_atoms = get_metal_atoms(mol) @@ -595,13 +599,13 @@ def _run_gulp(self, in_file: Path, out_file: Path) -> None: with out_file.open("w") as f: # Note that sp.call will hold the program until completion # of the calculation. - sp.call( + sp.call( # noqa: S602 cmd, stdin=sp.PIPE, stdout=f, stderr=sp.PIPE, # Shell is required to run complex arguments. - shell=True, # noqa: S602 + shell=True, ) def extract_final_energy(self, out_file: Path) -> float: diff --git a/src/stko/_internal/optimizers/macromodel.py b/src/stko/_internal/optimizers/macromodel.py index a313024a..722f9923 100644 --- a/src/stko/_internal/optimizers/macromodel.py +++ b/src/stko/_internal/optimizers/macromodel.py @@ -137,8 +137,8 @@ def _run_bmin(self, mol: stk.Molecule, run_name: str) -> None: incomplete = True while incomplete: - process = sp.Popen( - opt_cmd, # noqa: S603 + process = sp.Popen( # noqa: S603 + opt_cmd, stdout=sp.PIPE, stderr=sp.STDOUT, universal_newlines=True, @@ -227,8 +227,8 @@ def _kill_bmin(self, run_name: str) -> None: incomplete = True while incomplete: - out = sp.run( - cmd, # noqa: S603 + out = sp.run( # noqa: S603 + cmd, stdout=sp.PIPE, stderr=sp.STDOUT, text=True, @@ -248,8 +248,8 @@ def _kill_bmin(self, run_name: str) -> None: output = name start = time.time() while name in output: - output = sp.run( - cmd, # noqa: S603 + output = sp.run( # noqa: S603 + cmd, stdout=sp.PIPE, stderr=sp.STDOUT, text=True, @@ -303,10 +303,7 @@ def _license_found( with Path(f"{run_name}.log").open() as f: log_file = f.read() - if "Could not check out a license for mmlibs" in log_file: - return False - - return True + return "Could not check out a license for mmlibs" not in log_file @staticmethod def _get_com_line( # noqa: PLR0913 @@ -344,8 +341,8 @@ def _run_structconvert(self, input_path: Path, output_path: Path) -> None: while incomplete: # Execute the file conversion. try: - convrt_return = sp.run( - convrt_cmd, # noqa: S603 + convrt_return = sp.run( # noqa: S603 + convrt_cmd, stdout=sp.PIPE, stderr=sp.STDOUT, text=True, diff --git a/src/stko/_internal/optimizers/utilities.py b/src/stko/_internal/optimizers/utilities.py index 05405ef4..8ba189ac 100644 --- a/src/stko/_internal/optimizers/utilities.py +++ b/src/stko/_internal/optimizers/utilities.py @@ -306,10 +306,7 @@ def has_h_atom(bond: stk.Bond) -> bool: """ if bond.get_atom1().get_atomic_number() == 1: return True - if bond.get_atom2().get_atomic_number() == 1: - return True - - return False + return bond.get_atom2().get_atomic_number() == 1 def has_metal_atom(bond: stk.Bond, metal_atoms: list[stk.Atom]) -> bool: @@ -328,10 +325,7 @@ def has_metal_atom(bond: stk.Bond, metal_atoms: list[stk.Atom]) -> bool: """ if bond.get_atom1() in metal_atoms: return True - if bond.get_atom2() in metal_atoms: - return True - - return False + return bond.get_atom2() in metal_atoms def metal_atomic_numbers() -> abc.Iterable: diff --git a/src/stko/_internal/optimizers/xtb.py b/src/stko/_internal/optimizers/xtb.py index 40ccd91d..0b78504f 100644 --- a/src/stko/_internal/optimizers/xtb.py +++ b/src/stko/_internal/optimizers/xtb.py @@ -376,13 +376,13 @@ def _run_xtb(self, xyz: str, out_file: Path | str) -> None: with out_file.open("w") as f: # Note that sp.call will hold the program until completion # of the calculation. - sp.call( + sp.call( # noqa: S602 cmd, stdin=sp.PIPE, stdout=f, stderr=sp.PIPE, # Shell is required to run complex arguments. - shell=True, # noqa: S602 + shell=True, ) def _write_detailed_control(self) -> None: @@ -804,13 +804,13 @@ def _run_crest(self, xyz: str, out_file: Path | str) -> None: with out_file.open("w") as f: # Note that sp.call will hold the program until completion # of the calculation. - sp.call( + sp.call( # noqa: S602 cmd, stdin=sp.PIPE, stdout=f, stderr=sp.PIPE, # Shell is required to run complex arguments. - shell=True, # noqa: S602 + shell=True, ) def _run_optimization( @@ -1050,13 +1050,13 @@ def _run_xtb(self, xyz: str, out_file: Path | str) -> None: with out_file.open("w") as f: # Note that sp.call will hold the program until completion # of the calculation. - sp.call( + sp.call( # noqa: S602 cmd, stdin=sp.PIPE, stdout=f, stderr=sp.PIPE, # Shell is required to run complex arguments. - shell=True, # noqa: S602 + shell=True, ) def _run_optimization( @@ -1392,13 +1392,13 @@ def _run_crest(self, xyz: Path, out_file: Path) -> None: with out_file.open("w") as f: # Note that sp.call will hold the program until completion # of the calculation. - sp.call( + sp.call( # noqa: S602 cmd, stdin=sp.PIPE, stdout=f, stderr=sp.PIPE, # Shell is required to run complex arguments. - shell=True, # noqa: S602 + shell=True, ) def _run_optimization(