Add a maintainers directive (#35083)
fixes #34879 This commit adds a new maintainer directive, which by default extend the list of maintainers for a given package. The directive is backward compatible with the current practice of having a "maintainers" list declared at the class level.
This commit is contained in:
committed by
GitHub
parent
75f1077b4b
commit
cc2ae9f270
@@ -70,7 +70,7 @@ class {class_name}({base_class_name}):
|
||||
|
||||
# FIXME: Add a list of GitHub accounts to
|
||||
# notify when the package is updated.
|
||||
# maintainers = ["github_user1", "github_user2"]
|
||||
# maintainers("github_user1", "github_user2")
|
||||
|
||||
{versions}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ class OpenMpi(Package):
|
||||
"conflicts",
|
||||
"depends_on",
|
||||
"extends",
|
||||
"maintainers",
|
||||
"provides",
|
||||
"patch",
|
||||
"variant",
|
||||
@@ -767,6 +768,22 @@ def build_system(*values, **kwargs):
|
||||
)
|
||||
|
||||
|
||||
@directive(dicts=())
|
||||
def maintainers(*names: str):
|
||||
"""Add a new maintainer directive, to specify maintainers in a declarative way.
|
||||
|
||||
Args:
|
||||
names: GitHub username for the maintainer
|
||||
"""
|
||||
|
||||
def _execute_maintainer(pkg):
|
||||
maintainers_from_base = getattr(pkg, "maintainers", [])
|
||||
# Here it is essential to copy, otherwise we might add to an empty list in the parent
|
||||
pkg.maintainers = list(sorted(set(maintainers_from_base + list(names))))
|
||||
|
||||
return _execute_maintainer
|
||||
|
||||
|
||||
class DirectiveError(spack.error.SpackError):
|
||||
"""This is raised when something is wrong with a package directive."""
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
maintainers = spack.main.SpackCommand("maintainers")
|
||||
|
||||
MAINTAINED_PACKAGES = ["maintainers-1", "maintainers-2", "maintainers-3", "py-extension1"]
|
||||
|
||||
|
||||
def split(output):
|
||||
"""Split command line output into an array."""
|
||||
@@ -23,14 +25,12 @@ def split(output):
|
||||
|
||||
def test_maintained(mock_packages):
|
||||
out = split(maintainers("--maintained"))
|
||||
assert out == ["maintainers-1", "maintainers-2"]
|
||||
assert out == MAINTAINED_PACKAGES
|
||||
|
||||
|
||||
def test_unmaintained(mock_packages):
|
||||
out = split(maintainers("--unmaintained"))
|
||||
assert out == sorted(
|
||||
set(spack.repo.all_package_names()) - set(["maintainers-1", "maintainers-2"])
|
||||
)
|
||||
assert out == sorted(set(spack.repo.all_package_names()) - set(MAINTAINED_PACKAGES))
|
||||
|
||||
|
||||
def test_all(mock_packages, capfd):
|
||||
@@ -43,6 +43,14 @@ def test_all(mock_packages, capfd):
|
||||
"maintainers-2:",
|
||||
"user2,",
|
||||
"user3",
|
||||
"maintainers-3:",
|
||||
"user0,",
|
||||
"user1,",
|
||||
"user2,",
|
||||
"user3",
|
||||
"py-extension1:",
|
||||
"user1,",
|
||||
"user2",
|
||||
]
|
||||
|
||||
with capfd.disabled():
|
||||
@@ -58,23 +66,34 @@ def test_all_by_user(mock_packages, capfd):
|
||||
with capfd.disabled():
|
||||
out = split(maintainers("--all", "--by-user"))
|
||||
assert out == [
|
||||
"user0:",
|
||||
"maintainers-3",
|
||||
"user1:",
|
||||
"maintainers-1",
|
||||
"maintainers-1,",
|
||||
"maintainers-3,",
|
||||
"py-extension1",
|
||||
"user2:",
|
||||
"maintainers-1,",
|
||||
"maintainers-2",
|
||||
"maintainers-2,",
|
||||
"maintainers-3,",
|
||||
"py-extension1",
|
||||
"user3:",
|
||||
"maintainers-2",
|
||||
"maintainers-2,",
|
||||
"maintainers-3",
|
||||
]
|
||||
|
||||
with capfd.disabled():
|
||||
out = split(maintainers("--all", "--by-user", "user1", "user2"))
|
||||
assert out == [
|
||||
"user1:",
|
||||
"maintainers-1",
|
||||
"maintainers-1,",
|
||||
"maintainers-3,",
|
||||
"py-extension1",
|
||||
"user2:",
|
||||
"maintainers-1,",
|
||||
"maintainers-2",
|
||||
"maintainers-2,",
|
||||
"maintainers-3,",
|
||||
"py-extension1",
|
||||
]
|
||||
|
||||
|
||||
@@ -116,16 +135,16 @@ def test_maintainers_list_fails(mock_packages, capfd):
|
||||
def test_maintainers_list_by_user(mock_packages, capfd):
|
||||
with capfd.disabled():
|
||||
out = split(maintainers("--by-user", "user1"))
|
||||
assert out == ["maintainers-1"]
|
||||
assert out == ["maintainers-1", "maintainers-3", "py-extension1"]
|
||||
|
||||
with capfd.disabled():
|
||||
out = split(maintainers("--by-user", "user1", "user2"))
|
||||
assert out == ["maintainers-1", "maintainers-2"]
|
||||
assert out == ["maintainers-1", "maintainers-2", "maintainers-3", "py-extension1"]
|
||||
|
||||
with capfd.disabled():
|
||||
out = split(maintainers("--by-user", "user2"))
|
||||
assert out == ["maintainers-1", "maintainers-2"]
|
||||
assert out == ["maintainers-1", "maintainers-2", "maintainers-3", "py-extension1"]
|
||||
|
||||
with capfd.disabled():
|
||||
out = split(maintainers("--by-user", "user3"))
|
||||
assert out == ["maintainers-2"]
|
||||
assert out == ["maintainers-2", "maintainers-3"]
|
||||
|
||||
@@ -68,3 +68,19 @@ def test_error_on_anonymous_dependency(config, mock_packages):
|
||||
pkg = spack.repo.path.get_pkg_class("a")
|
||||
with pytest.raises(spack.directives.DependencyError):
|
||||
spack.directives._depends_on(pkg, "@4.5")
|
||||
|
||||
|
||||
@pytest.mark.regression("34879")
|
||||
@pytest.mark.parametrize(
|
||||
"package_name,expected_maintainers",
|
||||
[
|
||||
("maintainers-1", ["user1", "user2"]),
|
||||
# Reset from PythonPackage
|
||||
("py-extension1", ["user1", "user2"]),
|
||||
# Extends maintainers-1
|
||||
("maintainers-3", ["user0", "user1", "user2", "user3"]),
|
||||
],
|
||||
)
|
||||
def test_maintainer_directive(config, mock_packages, package_name, expected_maintainers):
|
||||
pkg_cls = spack.repo.path.get_pkg_class(package_name)
|
||||
assert pkg_cls.maintainers == expected_maintainers
|
||||
|
||||
Reference in New Issue
Block a user