More tests
This commit is contained in:
parent
9fe2796e9d
commit
944b3dad3f
@ -240,6 +240,24 @@ def setup_parser(subparser):
|
||||
default=lambda: spack.config.default_modify_scope(),
|
||||
help="configuration scope to modify",
|
||||
)
|
||||
set_parser.add_argument(
|
||||
"--include-file",
|
||||
help="specs which Spack should always try to add to a mirror"
|
||||
" (listed in a file, one per line)",
|
||||
)
|
||||
set_parser.add_argument(
|
||||
"--include-specs",
|
||||
help="specs which Spack should always try to add to a mirror (specified on command line)",
|
||||
)
|
||||
set_parser.add_argument(
|
||||
"--exclude-file",
|
||||
help="specs which Spack should not try to add to a mirror"
|
||||
" (listed in a file, one per line)",
|
||||
)
|
||||
set_parser.add_argument(
|
||||
"--exclude-specs",
|
||||
help="specs which Spack should not try to add to a mirror (specified on command line)",
|
||||
)
|
||||
arguments.add_connection_args(set_parser, False)
|
||||
|
||||
# List
|
||||
@ -317,6 +335,30 @@ def _default_variable(id_):
|
||||
return None
|
||||
|
||||
|
||||
def _manage_filters(args, mirror) -> bool:
|
||||
include_specs = []
|
||||
if args.include_file:
|
||||
include_specs.extend(specs_from_text_file(args.include_file, concretize=False))
|
||||
if args.include_specs:
|
||||
include_specs.extend(spack.cmd.parse_specs(str(args.include_specs).split()))
|
||||
if include_specs:
|
||||
# round trip specs to assure they are valid
|
||||
mirror.update({"include": [str(s) for s in include_specs]})
|
||||
|
||||
exclude_specs = []
|
||||
if args.exclude_file:
|
||||
exclude_specs.extend(specs_from_text_file(args.exclude_file, concretize=False))
|
||||
if args.exclude_specs:
|
||||
exclude_specs.extend(spack.cmd.parse_specs(str(args.exclude_specs).split()))
|
||||
if exclude_specs:
|
||||
# round trip specs to assure they are valid
|
||||
mirror.update({"exclude": [str(s) for s in exclude_specs]})
|
||||
if include_specs or exclude_specs:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def mirror_add(args):
|
||||
"""add a mirror to Spack"""
|
||||
if (
|
||||
@ -387,23 +429,7 @@ def mirror_add(args):
|
||||
else:
|
||||
mirror = spack.mirrors.mirror.Mirror(args.url, name=args.name)
|
||||
|
||||
include_specs = []
|
||||
if args.include_file:
|
||||
include_specs.extend(specs_from_text_file(args.include_file, concretize=False))
|
||||
if args.include_specs:
|
||||
include_specs.extend(spack.cmd.parse_specs(str(args.include_specs).split()))
|
||||
if include_specs:
|
||||
# round trip specs to assure they are valid
|
||||
mirror.update({"include": [str(s) for s in include_specs]})
|
||||
|
||||
exclude_specs = []
|
||||
if args.exclude_file:
|
||||
exclude_specs.extend(specs_from_text_file(args.exclude_file, concretize=False))
|
||||
if args.exclude_specs:
|
||||
exclude_specs.extend(spack.cmd.parse_specs(str(args.exclude_specs).split()))
|
||||
if exclude_specs:
|
||||
# round trip specs to assure they are valid
|
||||
mirror.update({"exclude": [str(s) for s in exclude_specs]})
|
||||
_manage_filters(args, mirror)
|
||||
|
||||
spack.mirrors.utils.add(mirror, args.scope)
|
||||
|
||||
@ -465,6 +491,7 @@ def _configure_mirror(args):
|
||||
changes["source"] = "source" in args.type
|
||||
|
||||
changed = entry.update(changes, direction)
|
||||
changed = changed | _manage_filters(args, entry)
|
||||
|
||||
if changed:
|
||||
mirrors[args.name] = entry.to_dict()
|
||||
@ -507,7 +534,10 @@ def specs_from_text_file(filename, concretize=False):
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
specs_in_file = f.readlines()
|
||||
specs_in_file = [s.strip() for s in specs_in_file]
|
||||
return spack.cmd.parse_specs(" ".join(specs_in_file), concretize=concretize)
|
||||
if concretize:
|
||||
return spack.cmd.parse_specs(" ".join(specs_in_file), concretize=True)
|
||||
else:
|
||||
return spack.cmd.parse_specs(specs_in_file, concretize=False)
|
||||
|
||||
|
||||
def concrete_specs_from_user(args):
|
||||
|
@ -561,3 +561,28 @@ def test_mirror_add_set_autopush(mutable_config):
|
||||
mirror("set", "--autopush", "example")
|
||||
assert spack.config.get("mirrors:example") == {"url": "http://example.com", "autopush": True}
|
||||
mirror("remove", "example")
|
||||
|
||||
|
||||
def test_mirror_add_filters(mutable_config, tmpdir):
|
||||
exclude_path = os.path.join(str(tmpdir), "test-exclude.txt")
|
||||
with open(exclude_path, "w", encoding="utf-8") as exclude_file:
|
||||
exclude_file.write(
|
||||
"""\
|
||||
mpich@3.0.1:3.0.2
|
||||
mpich@1.0
|
||||
"""
|
||||
)
|
||||
include_path = os.path.join(str(tmpdir), "test-include.txt")
|
||||
with open(include_path, "w", encoding="utf-8") as include_file:
|
||||
include_file.write(
|
||||
"""\
|
||||
build_type=Debug
|
||||
gcc-runtime
|
||||
"""
|
||||
)
|
||||
mirror("add", "--exclude-specs", "foo", "example", "http://example.com")
|
||||
assert spack.config.get("mirrors:example") == {"url": "http://example.com", "exclude": ["foo"]}
|
||||
mirror("set", "--include-specs", "+shared", "example")
|
||||
assert spack.config.get("mirrors:example") == {"url": "http://example.com", "exclude": ["foo"], "include": ["+shared"]}
|
||||
mirror("set", "--include-file", include_path,"--exclude-file", exclude_path, "example")
|
||||
assert spack.config.get("mirrors:example") == {"url": "http://example.com", "exclude": ["mpich@3.0.1:3.0.2", "mpich@1.0"], "include": ["build_type=Debug", "gcc-runtime"]}
|
||||
|
Loading…
Reference in New Issue
Block a user