allow packages to request no submodules be updated (#40409)
* allow packages to request no submodules be updated when self.submodules is a callable function * Extend the test added in Allow more fine-grained control over what submodules are updated: part 2 #27293 to include this case * Update the type signature for the submodules arg of version() in directives.py --------- Co-authored-by: tjfulle <tjfulle@users.noreply.github.com>
This commit is contained in:
parent
d31e503e5b
commit
79087d08d9
3 changed files with 39 additions and 5 deletions
|
@ -34,7 +34,7 @@ class OpenMpi(Package):
|
||||||
import functools
|
import functools
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
from typing import Any, Callable, List, Optional, Set, Tuple, Union
|
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Set, Tuple, Union
|
||||||
|
|
||||||
import llnl.util.lang
|
import llnl.util.lang
|
||||||
import llnl.util.tty.color
|
import llnl.util.tty.color
|
||||||
|
@ -57,6 +57,9 @@ class OpenMpi(Package):
|
||||||
VersionLookupError,
|
VersionLookupError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
import spack.package_base
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"DirectiveError",
|
"DirectiveError",
|
||||||
"DirectiveMeta",
|
"DirectiveMeta",
|
||||||
|
@ -349,6 +352,7 @@ def remove_directives(arg):
|
||||||
return _decorator
|
return _decorator
|
||||||
|
|
||||||
|
|
||||||
|
SubmoduleCallback = Callable[["spack.package_base.PackageBase"], Union[str, List[str], bool]]
|
||||||
directive = DirectiveMeta.directive
|
directive = DirectiveMeta.directive
|
||||||
|
|
||||||
|
|
||||||
|
@ -380,7 +384,7 @@ def version(
|
||||||
tag: Optional[str] = None,
|
tag: Optional[str] = None,
|
||||||
branch: Optional[str] = None,
|
branch: Optional[str] = None,
|
||||||
get_full_repo: Optional[bool] = None,
|
get_full_repo: Optional[bool] = None,
|
||||||
submodules: Optional[bool] = None,
|
submodules: Union[SubmoduleCallback, Optional[bool]] = None,
|
||||||
submodules_delete: Optional[bool] = None,
|
submodules_delete: Optional[bool] = None,
|
||||||
# other version control
|
# other version control
|
||||||
svn: Optional[str] = None,
|
svn: Optional[str] = None,
|
||||||
|
|
|
@ -929,7 +929,10 @@ def clone(self, dest=None, commit=None, branch=None, tag=None, bare=False):
|
||||||
git_commands = []
|
git_commands = []
|
||||||
submodules = self.submodules
|
submodules = self.submodules
|
||||||
if callable(submodules):
|
if callable(submodules):
|
||||||
submodules = list(submodules(self.package))
|
submodules = submodules(self.package)
|
||||||
|
if submodules:
|
||||||
|
if isinstance(submodules, str):
|
||||||
|
submodules = [submodules]
|
||||||
git_commands.append(["submodule", "init", "--"] + submodules)
|
git_commands.append(["submodule", "init", "--"] + submodules)
|
||||||
git_commands.append(["submodule", "update", "--recursive"])
|
git_commands.append(["submodule", "update", "--recursive"])
|
||||||
elif submodules:
|
elif submodules:
|
||||||
|
|
|
@ -363,3 +363,30 @@ def test_gitsubmodules_delete(
|
||||||
assert not os.path.isdir(file_path)
|
assert not os.path.isdir(file_path)
|
||||||
file_path = os.path.join(s.package.stage.source_path, "third_party/submodule1")
|
file_path = os.path.join(s.package.stage.source_path, "third_party/submodule1")
|
||||||
assert not os.path.isdir(file_path)
|
assert not os.path.isdir(file_path)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.disable_clean_stage_check
|
||||||
|
def test_gitsubmodules_falsey(
|
||||||
|
mock_git_repository, default_mock_concretization, mutable_mock_repo, monkeypatch
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Test GitFetchStrategy behavior when callable submodules returns Falsey
|
||||||
|
"""
|
||||||
|
|
||||||
|
def submodules_callback(package):
|
||||||
|
return False
|
||||||
|
|
||||||
|
type_of_test = "tag-branch"
|
||||||
|
t = mock_git_repository.checks[type_of_test]
|
||||||
|
|
||||||
|
# Construct the package under test
|
||||||
|
s = default_mock_concretization("git-test")
|
||||||
|
args = copy.copy(t.args)
|
||||||
|
args["submodules"] = submodules_callback
|
||||||
|
monkeypatch.setitem(s.package.versions, Version("git"), args)
|
||||||
|
s.package.do_stage()
|
||||||
|
with working_dir(s.package.stage.source_path):
|
||||||
|
file_path = os.path.join(s.package.stage.source_path, "third_party/submodule0/r0_file_0")
|
||||||
|
assert not os.path.isfile(file_path)
|
||||||
|
file_path = os.path.join(s.package.stage.source_path, "third_party/submodule1/r0_file_1")
|
||||||
|
assert not os.path.isfile(file_path)
|
||||||
|
|
Loading…
Reference in a new issue