diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py index 394aaf6b404..4f6e3578ac1 100644 --- a/lib/spack/spack/repo.py +++ b/lib/spack/spack/repo.py @@ -55,7 +55,9 @@ def is_package_module(fullname: str) -> bool: """Check if the given module is a package module.""" - return fullname.startswith(PKG_MODULE_PREFIX_V1) or fullname.startswith(PKG_MODULE_PREFIX_V2) + return fullname.startswith(PKG_MODULE_PREFIX_V1) or ( + fullname.startswith(PKG_MODULE_PREFIX_V2) and fullname.endswith(".package") + ) def namespace_from_fullname(fullname: str) -> str: diff --git a/lib/spack/spack/test/repo.py b/lib/spack/spack/test/repo.py index 13a3cb63de1..d6467ffd954 100644 --- a/lib/spack/spack/test/repo.py +++ b/lib/spack/spack/test/repo.py @@ -523,3 +523,10 @@ def test_subdir_in_v2(): with pytest.raises(spack.repo.BadRepoError, match="Must be a valid Python module name"): spack.repo._validate_and_normalize_subdir(subdir="123", root="root", package_api=(2, 0)) + + +def test_is_package_module(): + assert spack.repo.is_package_module("spack.pkg.something.something") + assert spack.repo.is_package_module("spack_repo.foo.bar.baz.package") + assert not spack.repo.is_package_module("spack_repo.builtin.build_systems.cmake") + assert not spack.repo.is_package_module("spack.something.else")