From aa2c18e4df926611226b2d128610c2e8bb639c9e Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Wed, 20 Nov 2024 16:15:28 +0100 Subject: [PATCH] spack style: import-check -> import, fix bugs, exclude spack.pkg (#47690) --- lib/spack/spack/cmd/modules/lmod.py | 1 + lib/spack/spack/cmd/modules/tcl.py | 1 + lib/spack/spack/cmd/style.py | 29 +++++++++++++------ lib/spack/spack/directives.py | 1 - lib/spack/spack/solver/asp.py | 1 + lib/spack/spack/test/cmd/ci.py | 1 + lib/spack/spack/test/cmd/pkg.py | 1 + lib/spack/spack/test/cmd/style.py | 23 +++++++++++++-- lib/spack/spack/test/config.py | 1 + lib/spack/spack/test/modules/common.py | 1 + lib/spack/spack/test/package_class.py | 1 + lib/spack/spack/util/path.py | 1 + lib/spack/spack/util/web.py | 1 + share/spack/spack-completion.fish | 4 +-- .../packages/find-externals1/package.py | 3 +- .../packages/py-test-callback/package.py | 3 +- .../repos/builtin/packages/chapel/package.py | 3 ++ .../builtin/packages/cray-fftw/package.py | 2 ++ .../repos/builtin/packages/pythia6/package.py | 4 +-- .../repos/builtin/packages/upcxx/package.py | 2 ++ 20 files changed, 63 insertions(+), 21 deletions(-) diff --git a/lib/spack/spack/cmd/modules/lmod.py b/lib/spack/spack/cmd/modules/lmod.py index 4fd6992a47a..3f2f7d2ec04 100644 --- a/lib/spack/spack/cmd/modules/lmod.py +++ b/lib/spack/spack/cmd/modules/lmod.py @@ -8,6 +8,7 @@ import spack.cmd.common.arguments import spack.cmd.modules import spack.config +import spack.modules import spack.modules.lmod diff --git a/lib/spack/spack/cmd/modules/tcl.py b/lib/spack/spack/cmd/modules/tcl.py index 4ca8ece7044..e31d5bcc46f 100644 --- a/lib/spack/spack/cmd/modules/tcl.py +++ b/lib/spack/spack/cmd/modules/tcl.py @@ -7,6 +7,7 @@ import spack.cmd.common.arguments import spack.cmd.modules import spack.config +import spack.modules import spack.modules.tcl diff --git a/lib/spack/spack/cmd/style.py b/lib/spack/spack/cmd/style.py index 5925d1120e5..9d164875ae2 100644 --- a/lib/spack/spack/cmd/style.py +++ b/lib/spack/spack/cmd/style.py @@ -15,6 +15,7 @@ from llnl.util.filesystem import working_dir import spack.paths +import spack.repo import spack.util.git from spack.util.executable import Executable, which @@ -38,7 +39,7 @@ def grouper(iterable, n, fillvalue=None): #: double-check the results of other tools (if, e.g., --fix was provided) #: The list maps an executable name to a method to ensure the tool is #: bootstrapped or present in the environment. -tool_names = ["import-check", "isort", "black", "flake8", "mypy"] +tool_names = ["import", "isort", "black", "flake8", "mypy"] #: warnings to ignore in mypy mypy_ignores = [ @@ -370,10 +371,19 @@ def run_black(black_cmd, file_list, args): def _module_part(root: str, expr: str): parts = expr.split(".") + # spack.pkg is for repositories, don't try to resolve it here. + if ".".join(parts[:2]) == spack.repo.ROOT_PYTHON_NAMESPACE: + return None while parts: f1 = os.path.join(root, "lib", "spack", *parts) + ".py" f2 = os.path.join(root, "lib", "spack", *parts, "__init__.py") - if os.path.exists(f1) or os.path.exists(f2): + + if ( + os.path.exists(f1) + # ensure case sensitive match + and f"{parts[-1]}.py" in os.listdir(os.path.dirname(f1)) + or os.path.exists(f2) + ): return ".".join(parts) parts.pop() return None @@ -389,7 +399,7 @@ def _run_import_check( out=sys.stdout, ): if sys.version_info < (3, 9): - print("import-check requires Python 3.9 or later") + print("import check requires Python 3.9 or later") return 0 is_use = re.compile(r"(?