cmd/mirror.py: match CLI specs to concrete specs in env (#50307)

* cmd/mirror.py: match CLI specs to concrete specs in env

* Allow using 'mirror create -a/--all' to match multiple concrete specs

* remove unit test preventing 'mirror create -a <spec>'

* Add test_mirror_spec_from_env() unit test (cmd/mirror.py)
This commit is contained in:
Alex Richert 2025-05-21 01:40:14 -04:00 committed by GitHub
parent cca0eb6873
commit f01a442ad4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 11 deletions

View File

@ -514,17 +514,18 @@ def extend_with_dependencies(specs):
def concrete_specs_from_cli_or_file(args): def concrete_specs_from_cli_or_file(args):
tty.msg("Concretizing input specs")
if args.specs: if args.specs:
specs = spack.cmd.parse_specs(args.specs, concretize=True) specs = spack.cmd.parse_specs(args.specs, concretize=False)
if not specs: if not specs:
raise SpackError("unable to parse specs from command line") raise SpackError("unable to parse specs from command line")
if args.file: if args.file:
specs = specs_from_text_file(args.file, concretize=True) specs = specs_from_text_file(args.file, concretize=False)
if not specs: if not specs:
raise SpackError("unable to parse specs from file '{}'".format(args.file)) raise SpackError("unable to parse specs from file '{}'".format(args.file))
return specs
concrete_specs = spack.cmd.matching_specs_from_env(specs)
return concrete_specs
class IncludeFilter: class IncludeFilter:
@ -607,11 +608,6 @@ def process_mirror_stats(present, mirrored, error):
def mirror_create(args): def mirror_create(args):
"""create a directory to be used as a spack mirror, and fill it with package archives""" """create a directory to be used as a spack mirror, and fill it with package archives"""
if args.specs and args.all:
raise SpackError(
"cannot specify specs on command line if you chose to mirror all specs with '--all'"
)
if args.file and args.all: if args.file and args.all:
raise SpackError( raise SpackError(
"cannot specify specs with a file if you chose to mirror all specs with '--all'" "cannot specify specs with a file if you chose to mirror all specs with '--all'"

View File

@ -61,6 +61,26 @@ def test_mirror_from_env(mutable_mock_env_path, tmp_path, mock_packages, mock_fe
assert mirror_res == expected assert mirror_res == expected
# Test for command line-specified spec in concretized environment
def test_mirror_spec_from_env(mutable_mock_env_path, tmp_path, mock_packages, mock_fetch):
mirror_dir = str(tmp_path / "mirror-B")
env_name = "test"
env("create", env_name)
with ev.read(env_name):
add("simple-standalone-test@0.9")
concretize()
with spack.config.override("config:checksum", False):
mirror("create", "-d", mirror_dir, "simple-standalone-test")
e = ev.read(env_name)
assert set(os.listdir(mirror_dir)) == set([s.name for s in e.user_specs])
spec = e.concrete_roots()[0]
mirror_res = os.listdir(os.path.join(mirror_dir, spec.name))
expected = ["%s.tar.gz" % spec.format("{name}-{version}")]
assert mirror_res == expected
@pytest.fixture @pytest.fixture
def source_for_pkg_with_hash(mock_packages, tmpdir): def source_for_pkg_with_hash(mock_packages, tmpdir):
s = spack.concretize.concretize_one("trivial-pkg-with-valid-hash") s = spack.concretize.concretize_one("trivial-pkg-with-valid-hash")
@ -401,8 +421,7 @@ def test_all_specs_with_all_versions_dont_concretize(self):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"cli_args,error_str", "cli_args,error_str",
[ [
# Passed more than one among -f --all and specs # Passed more than one among -f --all
({"specs": "hdf5", "file": None, "all": True}, "cannot specify specs on command line"),
( (
{"specs": None, "file": "input.txt", "all": True}, {"specs": None, "file": "input.txt", "all": True},
"cannot specify specs with a file if", "cannot specify specs with a file if",