Fix spack.repo.is_package_module (#50464)

This commit is contained in:
Harmen Stoppels 2025-05-14 10:22:28 +02:00 committed by GitHub
parent abcef565a8
commit abcc641373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -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:

View File

@ -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")