From 4735809373ab3a2d2ff5209c122745a930057cc2 Mon Sep 17 00:00:00 2001 From: Toon Verstraelen Date: Tue, 4 Jun 2024 20:59:51 +0200 Subject: [PATCH] Remove import_resources try-except block These weird imports were only relevant for Python versions that are past their end of life: 3.6 and older. --- iodata/test/common.py | 6 +----- iodata/test/test_charmm.py | 7 ++----- iodata/test/test_chgcar.py | 7 ++----- iodata/test/test_cli.py | 6 +----- iodata/test/test_cp2klog.py | 7 ++----- iodata/test/test_cube.py | 7 ++----- iodata/test/test_extxyz.py | 7 ++----- iodata/test/test_fchk.py | 6 +----- iodata/test/test_fcidump.py | 6 +----- iodata/test/test_gamess.py | 7 ++----- iodata/test/test_gaussianinput.py | 7 ++----- iodata/test/test_gaussianlog.py | 7 ++----- iodata/test/test_gromacs.py | 7 ++----- iodata/test/test_inputs.py | 6 +----- iodata/test/test_iodata.py | 7 ++----- iodata/test/test_json.py | 7 +------ iodata/test/test_locpot.py | 7 ++----- iodata/test/test_mol2.py | 6 +----- iodata/test/test_molden.py | 6 +----- iodata/test/test_molekel.py | 6 +----- iodata/test/test_mwfn.py | 7 ++----- iodata/test/test_orcalog.py | 7 ++----- iodata/test/test_overlap.py | 6 +----- iodata/test/test_pdb.py | 6 +----- iodata/test/test_poscar.py | 6 +----- iodata/test/test_qchemlog.py | 7 ++----- iodata/test/test_sdf.py | 6 +----- iodata/test/test_wfn.py | 7 +------ iodata/test/test_wfx.py | 6 +----- iodata/test/test_xyz.py | 6 +----- 30 files changed, 44 insertions(+), 152 deletions(-) diff --git a/iodata/test/common.py b/iodata/test/common.py index 68080495..e528cc6b 100644 --- a/iodata/test/common.py +++ b/iodata/test/common.py @@ -20,6 +20,7 @@ import os from contextlib import contextmanager +from importlib.resources import as_file, files from typing import Optional import numpy as np @@ -31,11 +32,6 @@ from ..overlap import compute_overlap from ..utils import FileFormatWarning -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - __all__ = [ "compute_mulliken_charges", "compute_1rdm", diff --git a/iodata/test/test_charmm.py b/iodata/test/test_charmm.py index 8a7ea6cc..fb887eea 100644 --- a/iodata/test/test_charmm.py +++ b/iodata/test/test_charmm.py @@ -18,16 +18,13 @@ # -- """Test iodata.formats.orcalog module.""" +from importlib.resources import as_file, files + from numpy.testing import assert_allclose, assert_equal from ..api import load_one from ..utils import amu, angstrom -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_crambin(): # test CHARMM crd file of crambin diff --git a/iodata/test/test_chgcar.py b/iodata/test/test_chgcar.py index e9ee2df2..507bf322 100644 --- a/iodata/test/test_chgcar.py +++ b/iodata/test/test_chgcar.py @@ -18,17 +18,14 @@ # -- """Test iodata.formats.chgcar module.""" +from importlib.resources import as_file, files + import numpy as np from numpy.testing import assert_allclose, assert_equal from ..api import load_one from ..utils import angstrom, volume -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_chgcar_oxygen(): with as_file(files("iodata.test.data").joinpath("CHGCAR.oxygen")) as fn: diff --git a/iodata/test/test_cli.py b/iodata/test/test_cli.py index 110bef61..848429f1 100644 --- a/iodata/test/test_cli.py +++ b/iodata/test/test_cli.py @@ -22,17 +22,13 @@ import os import subprocess import sys +from importlib.resources import as_file, files from numpy.testing import assert_allclose, assert_equal from ..__main__ import convert from ..api import load_many, load_one -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def _check_convert_one(myconvert, tmpdir): outfn = os.path.join(tmpdir, "tmp.xyz") diff --git a/iodata/test/test_cp2klog.py b/iodata/test/test_cp2klog.py index 299edc73..9c3a73bb 100644 --- a/iodata/test/test_cp2klog.py +++ b/iodata/test/test_cp2klog.py @@ -18,6 +18,8 @@ # -- """Test iodata.formats.cp2klog module.""" +from importlib.resources import as_file, files + import pytest from numpy.testing import assert_allclose, assert_equal @@ -25,11 +27,6 @@ from ..overlap import compute_overlap from .common import check_orthonormal, truncated_file -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_atom_si_uks(): with as_file(files("iodata.test.data").joinpath("atom_si.cp2k.out")) as fn_out: diff --git a/iodata/test/test_cube.py b/iodata/test/test_cube.py index 543eedec..0f1df526 100644 --- a/iodata/test/test_cube.py +++ b/iodata/test/test_cube.py @@ -18,16 +18,13 @@ # -- """Test iodata.formats.cube module.""" +from importlib.resources import as_file, files + import numpy as np from numpy.testing import assert_allclose, assert_equal from ..api import dump_one, load_one -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_aelta(): with as_file(files("iodata.test.data").joinpath("aelta.cube")) as fn_cube: diff --git a/iodata/test/test_extxyz.py b/iodata/test/test_extxyz.py index 9362c5fd..5b3ecb6e 100644 --- a/iodata/test/test_extxyz.py +++ b/iodata/test/test_extxyz.py @@ -18,17 +18,14 @@ # -- """Test iodata.formats.extxyz module.""" +from importlib.resources import as_file, files + import numpy as np from numpy.testing import assert_allclose, assert_equal from ..api import load_many, load_one from ..utils import angstrom -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_fcc_extended(): with as_file(files("iodata.test.data").joinpath("al_fcc.xyz")) as fn_xyz: diff --git a/iodata/test/test_fchk.py b/iodata/test/test_fchk.py index 54d69525..f82a3482 100644 --- a/iodata/test/test_fchk.py +++ b/iodata/test/test_fchk.py @@ -19,6 +19,7 @@ """Test iodata.formats.fchk module.""" import os +from importlib.resources import as_file, files from typing import Optional import numpy as np @@ -31,11 +32,6 @@ from .common import check_orthonormal, compare_mols, compute_1rdm, load_one_warning from .test_molekel import compare_mols_diff_formats -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_fchk_nonexistent(): with ( diff --git a/iodata/test/test_fcidump.py b/iodata/test/test_fcidump.py index c06545a4..c956709b 100644 --- a/iodata/test/test_fcidump.py +++ b/iodata/test/test_fcidump.py @@ -19,17 +19,13 @@ """Test iodata.formats.fcidump module.""" import os +from importlib.resources import as_file, files import numpy as np from numpy.testing import assert_allclose, assert_equal from ..api import dump_one, load_one -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_fcidump_psi4_h2(): with as_file(files("iodata.test.data").joinpath("FCIDUMP.psi4.h2")) as fn: diff --git a/iodata/test/test_gamess.py b/iodata/test/test_gamess.py index 07208255..b3bf3396 100644 --- a/iodata/test/test_gamess.py +++ b/iodata/test/test_gamess.py @@ -18,16 +18,13 @@ # -- """Test iodata.formats.gamess module.""" +from importlib.resources import as_file, files + from numpy.testing import assert_allclose, assert_equal from ..api import load_one from ..utils import angstrom -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_one_gamess_punch(): with as_file(files("iodata.test.data").joinpath("PCGamess_PUNCH.dat")) as f: diff --git a/iodata/test/test_gaussianinput.py b/iodata/test/test_gaussianinput.py index 330e06da..5ddaa5aa 100644 --- a/iodata/test/test_gaussianinput.py +++ b/iodata/test/test_gaussianinput.py @@ -18,17 +18,14 @@ # -- """Test iodata.formats.gaussianinput module.""" +from importlib.resources import as_file, files + import numpy as np from numpy.testing import assert_allclose, assert_equal, assert_raises from ..api import load_one from ..utils import angstrom -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_water_com(): # test .com with Link 0 section diff --git a/iodata/test/test_gaussianlog.py b/iodata/test/test_gaussianlog.py index fe29aaea..60321adc 100644 --- a/iodata/test/test_gaussianlog.py +++ b/iodata/test/test_gaussianlog.py @@ -18,15 +18,12 @@ # -- """Test iodata.formats.log module.""" +from importlib.resources import as_file, files + from numpy.testing import assert_allclose, assert_equal from ..api import load_one -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def load_log_helper(fn_log): """Load a testing Gaussian log file with iodata.load_one.""" diff --git a/iodata/test/test_gromacs.py b/iodata/test/test_gromacs.py index 4ef1eb24..39bc51c5 100644 --- a/iodata/test/test_gromacs.py +++ b/iodata/test/test_gromacs.py @@ -18,16 +18,13 @@ # -- """Test iodata.formats.gromacs module.""" +from importlib.resources import as_file, files + from numpy.testing import assert_allclose, assert_equal from ..api import load_many, load_one from ..utils import nanometer, picosecond -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_water(): # test gro file of one water diff --git a/iodata/test/test_inputs.py b/iodata/test/test_inputs.py index 9bd8b7cb..5c949057 100644 --- a/iodata/test/test_inputs.py +++ b/iodata/test/test_inputs.py @@ -19,6 +19,7 @@ """Test iodata.inputs module.""" import os +from importlib.resources import as_file, files import numpy as np @@ -26,11 +27,6 @@ from ..iodata import IOData from ..utils import angstrom -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def check_load_input_and_compare(fname: str, fname_expected: str): """Load saved input file and compare to expected input file. diff --git a/iodata/test/test_iodata.py b/iodata/test/test_iodata.py index a7124074..6ac36036 100644 --- a/iodata/test/test_iodata.py +++ b/iodata/test/test_iodata.py @@ -19,6 +19,8 @@ # ruff: noqa: SLF001 """Test iodata.iodata module.""" +from importlib.resources import as_file, files + import numpy as np import pytest from numpy.testing import assert_allclose, assert_equal @@ -27,11 +29,6 @@ from ..overlap import compute_overlap from .common import compute_1rdm -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_typecheck(): m = IOData(atcoords=np.array([[1, 2, 3], [2, 3, 1]])) diff --git a/iodata/test/test_json.py b/iodata/test/test_json.py index 4b205c20..028bcb1c 100644 --- a/iodata/test/test_json.py +++ b/iodata/test/test_json.py @@ -20,6 +20,7 @@ import json import os +from importlib.resources import as_file, files import numpy as np import pytest @@ -27,12 +28,6 @@ from ..api import dump_one, load_one from ..utils import FileFormatError, FileFormatWarning -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - - # Tests for qcschema_molecule # GEOMS: dict of str: NDArray(N, 3) GEOMS = { diff --git a/iodata/test/test_locpot.py b/iodata/test/test_locpot.py index 814a9fb4..9ddf8dd3 100644 --- a/iodata/test/test_locpot.py +++ b/iodata/test/test_locpot.py @@ -18,16 +18,13 @@ # -- """Test iodata.formats.locpot module.""" +from importlib.resources import as_file, files + from numpy.testing import assert_allclose, assert_equal from ..api import load_one from ..utils import angstrom, electronvolt, volume -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_locpot_oxygen(): with as_file(files("iodata.test.data").joinpath("LOCPOT.oxygen")) as fn: diff --git a/iodata/test/test_mol2.py b/iodata/test/test_mol2.py index babebe5c..ec1eb585 100644 --- a/iodata/test/test_mol2.py +++ b/iodata/test/test_mol2.py @@ -19,6 +19,7 @@ """Test iodata.formats.mol2 module.""" import os +from importlib.resources import as_file, files import pytest from numpy.testing import assert_allclose, assert_equal @@ -28,11 +29,6 @@ from ..utils import angstrom from .common import truncated_file -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_mol2_load_one(): # test mol2 one structure diff --git a/iodata/test/test_molden.py b/iodata/test/test_molden.py index bab0e8df..bc48257a 100644 --- a/iodata/test/test_molden.py +++ b/iodata/test/test_molden.py @@ -20,6 +20,7 @@ import os import warnings +from importlib.resources import as_file, files import attrs import numpy as np @@ -33,11 +34,6 @@ from ..utils import FileFormatWarning, LineIterator, angstrom from .common import check_orthonormal, compare_mols, compute_mulliken_charges -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_molden_li2_orca(): with ( diff --git a/iodata/test/test_molekel.py b/iodata/test/test_molekel.py index da4cd20b..c938aed4 100644 --- a/iodata/test/test_molekel.py +++ b/iodata/test/test_molekel.py @@ -20,6 +20,7 @@ import os import warnings +from importlib.resources import as_file, files from typing import Optional from numpy.testing import assert_allclose, assert_equal @@ -30,11 +31,6 @@ from ..utils import angstrom from .common import check_orthonormal, compare_mols, compute_mulliken_charges, load_one_warning -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def compare_mols_diff_formats(mol1, mol2): """Compare two IOData objects loaded from different formats.""" diff --git a/iodata/test/test_mwfn.py b/iodata/test/test_mwfn.py index d4e08a00..4ccfd85a 100644 --- a/iodata/test/test_mwfn.py +++ b/iodata/test/test_mwfn.py @@ -18,17 +18,14 @@ # -- """Test iodata.formats.mwfn module.""" +from importlib.resources import as_file, files + import numpy as np from numpy.testing import assert_allclose, assert_equal from ..api import load_one from ..overlap import compute_overlap -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def load_helper(fn): """Load a test file with iodata.iodata.load_one.""" diff --git a/iodata/test/test_orcalog.py b/iodata/test/test_orcalog.py index 60c5e819..7db49c55 100644 --- a/iodata/test/test_orcalog.py +++ b/iodata/test/test_orcalog.py @@ -18,17 +18,14 @@ # -- """Test iodata.formats.orcalog module.""" +from importlib.resources import as_file, files + import numpy as np from numpy.testing import assert_allclose, assert_equal from ..api import load_one from ..utils import angstrom -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_water_number(): with as_file(files("iodata.test.data").joinpath("water_orca.out")) as fn: diff --git a/iodata/test/test_overlap.py b/iodata/test/test_overlap.py index 6ad705a2..fe3846fd 100644 --- a/iodata/test/test_overlap.py +++ b/iodata/test/test_overlap.py @@ -19,6 +19,7 @@ """Test iodata.overlap & iodata.overlap_accel modules.""" import itertools +from importlib.resources import as_file, files import attrs import numpy as np @@ -29,11 +30,6 @@ from ..basis import MolecularBasis, Shell, convert_conventions from ..overlap import OVERLAP_CONVENTIONS, compute_overlap, factorial2 -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - @pytest.mark.parametrize( ("inp", "out"), [(0, 1), (1, 1), (2, 2), (3, 3), (4, 8), (5, 15), (-1, 1), (-2, 0)] diff --git a/iodata/test/test_pdb.py b/iodata/test/test_pdb.py index 956a1c8f..2420f945 100644 --- a/iodata/test/test_pdb.py +++ b/iodata/test/test_pdb.py @@ -19,6 +19,7 @@ """Test iodata.formats.pdb module.""" import os +from importlib.resources import as_file, files import numpy as np import pytest @@ -27,11 +28,6 @@ from ..api import dump_many, dump_one, load_many, load_one from ..utils import FileFormatWarning, angstrom -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - @pytest.mark.parametrize("case", ["single", "single_model"]) def test_load_water(case): diff --git a/iodata/test/test_poscar.py b/iodata/test/test_poscar.py index 13979e7e..7bc31770 100644 --- a/iodata/test/test_poscar.py +++ b/iodata/test/test_poscar.py @@ -19,6 +19,7 @@ """Test iodata.formats.poscar module.""" import os +from importlib.resources import as_file, files import numpy as np from numpy.testing import assert_allclose, assert_equal @@ -26,11 +27,6 @@ from ..api import dump_one, load_one from ..utils import angstrom, volume -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_poscar_water(): with as_file(files("iodata.test.data").joinpath("POSCAR.water")) as fn: diff --git a/iodata/test/test_qchemlog.py b/iodata/test/test_qchemlog.py index e7d78fd8..6bcbb330 100644 --- a/iodata/test/test_qchemlog.py +++ b/iodata/test/test_qchemlog.py @@ -18,6 +18,8 @@ # -- """Test iodata.formats.qchemlog module.""" +from importlib.resources import as_file, files + import numpy as np from numpy.testing import assert_allclose, assert_equal @@ -25,11 +27,6 @@ from ..formats.qchemlog import load_qchemlog_low from ..utils import LineIterator, angstrom, kjmol -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_qchemlog_low_h2o(): """Test load_qchemlog_low with water_hf_ccpvtz_freq_qchem.out.""" diff --git a/iodata/test/test_sdf.py b/iodata/test/test_sdf.py index 04554dde..9b4e590a 100644 --- a/iodata/test/test_sdf.py +++ b/iodata/test/test_sdf.py @@ -19,6 +19,7 @@ """Test iodata.formats.sdf module.""" import os +from importlib.resources import as_file, files import pytest from numpy.testing import assert_allclose, assert_equal @@ -27,11 +28,6 @@ from ..utils import FileFormatError, angstrom from .common import truncated_file -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_sdf_load_one_example(): # test sdf one structure diff --git a/iodata/test/test_wfn.py b/iodata/test/test_wfn.py index 538095c0..952f2812 100644 --- a/iodata/test/test_wfn.py +++ b/iodata/test/test_wfn.py @@ -19,6 +19,7 @@ """Test iodata.formats.wfn module.""" import os +from importlib.resources import as_file, files import numpy as np from numpy.testing import assert_allclose, assert_equal @@ -29,12 +30,6 @@ from ..utils import LineIterator from .common import check_orthonormal, compare_mols, compute_mulliken_charges -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - - # TODO: removed density, kin, nucnuc checks diff --git a/iodata/test/test_wfx.py b/iodata/test/test_wfx.py index 67106034..0174f179 100644 --- a/iodata/test/test_wfx.py +++ b/iodata/test/test_wfx.py @@ -19,6 +19,7 @@ """Test iodata.formats.wfn module.""" import os +from importlib.resources import as_file, files from typing import Optional import numpy as np @@ -37,11 +38,6 @@ truncated_file, ) -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def helper_load_data_wfx(fn_wfx): """Load a testing WFX file with iodata.formats.wfx.load_data_wfx.""" diff --git a/iodata/test/test_xyz.py b/iodata/test/test_xyz.py index c0b3afe3..7adefc48 100644 --- a/iodata/test/test_xyz.py +++ b/iodata/test/test_xyz.py @@ -19,6 +19,7 @@ """Test iodata.formats.xyz module.""" import os +from importlib.resources import as_file, files import numpy as np from numpy.testing import assert_allclose, assert_equal @@ -27,11 +28,6 @@ from ..formats.xyz import DEFAULT_ATOM_COLUMNS from ..utils import angstrom -try: - from importlib_resources import as_file, files -except ImportError: - from importlib.resources import as_file, files - def test_load_water_number(): # test xyz with atomic numbers