From abcc6413733da05102f81faee524d7bf12d9f606 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Wed, 14 May 2025 10:22:28 +0200 Subject: [PATCH] Fix spack.repo.is_package_module (#50464) --- lib/spack/spack/repo.py | 4 +++- lib/spack/spack/test/repo.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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")