diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py index b67d5e3b510..f7e66cc7be9 100644 --- a/lib/spack/spack/repo.py +++ b/lib/spack/spack/repo.py @@ -90,7 +90,7 @@ def __init__(self, fullname: str, repo: "Repo", package_name: str) -> None: def path_stats(self, path): stats = dict(super().path_stats(path)) - stats["size"] += len(self.prepend) + 1 + stats["size"] += len(self.prepend) return stats def get_data(self, path): diff --git a/lib/spack/spack/test/audit.py b/lib/spack/spack/test/audit.py index d8bd3a11b8d..f4e81f42e67 100644 --- a/lib/spack/spack/test/audit.py +++ b/lib/spack/spack/test/audit.py @@ -28,9 +28,6 @@ (["invalid-selfhosted-gitlab-patch-url"], ["PKG-DIRECTIVES", "PKG-PROPERTIES"]), # This package has a stand-alone test method in build-time callbacks (["fail-test-audit"], ["PKG-PROPERTIES"]), - # This package implements and uses several deprecated stand-alone - # test methods - (["fail-test-audit-deprecated"], ["PKG-DEPRECATED-ATTRIBUTES"]), # This package has stand-alone test methods without non-trivial docstrings (["fail-test-audit-docstring"], ["PKG-PROPERTIES"]), # This package has a stand-alone test method without an implementation @@ -54,6 +51,30 @@ def test_package_audits(packages, expected_errors, mock_packages): assert not actual_errors, msg +@pytest.mark.parametrize( + "packages,expected_errors", + [ + # This package implements and uses several deprecated stand-alone test methods + (["fail-test-audit-deprecated"], ["PKG-DEPRECATED-ATTRIBUTES"]) + ], +) +@pytest.mark.xfail( + reason="inspect.getsource is not aware of package api v1 injected import statements" +) +def test_packge_audits_broken_by_magic_package_api_v1_injected_line( + packages, expected_errors, mock_packages +): + reports = spack.audit.run_group("packages", pkgs=packages) + + # Check that errors were reported only for the expected failure + actual_errors = [check for check, errors in reports if errors] + msg = "\n".join([str(e) for _, errors in reports for e in errors]) + if expected_errors: + assert expected_errors == actual_errors, msg + else: + assert not actual_errors, msg + + # Data used in the test below to audit the double definition of a compiler _double_compiler_definition = [ { diff --git a/lib/spack/spack/test/data/conftest/diff-test/package-0.txt b/lib/spack/spack/test/data/conftest/diff-test/package-0.txt index 9c42cc031a3..6b019d19626 100644 --- a/lib/spack/spack/test/data/conftest/diff-test/package-0.txt +++ b/lib/spack/spack/test/data/conftest/diff-test/package-0.txt @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) +from spack.build_systems.autotools import AutotoolsPackage from spack.package import * diff --git a/lib/spack/spack/test/data/conftest/diff-test/package-1.txt b/lib/spack/spack/test/data/conftest/diff-test/package-1.txt index 43e6c749b16..84ca6edd44f 100644 --- a/lib/spack/spack/test/data/conftest/diff-test/package-1.txt +++ b/lib/spack/spack/test/data/conftest/diff-test/package-1.txt @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) +from spack.build_systems.autotools import AutotoolsPackage from spack.package import * diff --git a/lib/spack/spack/test/data/conftest/diff-test/package-2.txt b/lib/spack/spack/test/data/conftest/diff-test/package-2.txt index b384756eda3..2b5b23aa136 100644 --- a/lib/spack/spack/test/data/conftest/diff-test/package-2.txt +++ b/lib/spack/spack/test/data/conftest/diff-test/package-2.txt @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) +from spack.build_systems.autotools import AutotoolsPackage from spack.package import * diff --git a/lib/spack/spack/test/package_class.py b/lib/spack/spack/test/package_class.py index 0300b21dfa8..82d9bea00ad 100644 --- a/lib/spack/spack/test/package_class.py +++ b/lib/spack/spack/test/package_class.py @@ -20,7 +20,6 @@ import spack.deptypes as dt import spack.error import spack.install_test -import spack.package import spack.package_base import spack.spec import spack.store @@ -241,7 +240,7 @@ def test_cache_extra_sources_fails(install_mockery): def test_package_exes_and_libs(): with pytest.raises(spack.error.SpackError, match="defines both"): - class BadDetectablePackage(spack.package.Package): + class BadDetectablePackage(spack.package_base.PackageBase): executables = ["findme"] libraries = ["libFindMe.a"] @@ -249,7 +248,7 @@ class BadDetectablePackage(spack.package.Package): def test_package_url_and_urls(): UrlsPackage = type( "URLsPackage", - (spack.package.Package,), + (spack.package_base.PackageBase,), { "__module__": "spack.pkg.builtin.urls_package", "url": "https://www.example.com/url-package-1.0.tgz", @@ -265,7 +264,7 @@ def test_package_url_and_urls(): def test_package_license(): LicensedPackage = type( "LicensedPackage", - (spack.package.Package,), + (spack.package_base.PackageBase,), {"__module__": "spack.pkg.builtin.licensed_package"}, ) diff --git a/lib/spack/spack/test/repo.py b/lib/spack/spack/test/repo.py index d6467ffd954..f4f97d9cca6 100644 --- a/lib/spack/spack/test/repo.py +++ b/lib/spack/spack/test/repo.py @@ -440,7 +440,7 @@ def test_repo_v2_module_and_class_to_package_name(tmp_path: pathlib.Path, capsys (repo_dir / "packages" / "_1example_2_test").mkdir() (repo_dir / "packages" / "_1example_2_test" / "package.py").write_text( """ -from spack.package import Package +from spack.build_systems.generic import Package class _1example2Test(Package): pass diff --git a/share/spack/templates/mock-repository/package.pyt b/share/spack/templates/mock-repository/package.pyt index a4a52ec700c..e8f7bae8194 100644 --- a/share/spack/templates/mock-repository/package.pyt +++ b/share/spack/templates/mock-repository/package.pyt @@ -1,3 +1,4 @@ +from spack.build_systems.generic import Package from spack.package import * class {{ cls_name }}(Package):