diff options
author | Harmen Stoppels <harmenstoppels@gmail.com> | 2023-01-18 11:45:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-18 11:45:58 +0100 |
commit | fef0f47d658c09415f7e0761f3f00c27cfd8a410 (patch) | |
tree | ac46ba4b40cc3a82dd6dd3615551ccd239bc1de6 | |
parent | 20575ca96aaa43440d3583f68266133fa3e65dfc (diff) | |
download | spack-fef0f47d658c09415f7e0761f3f00c27cfd8a410.tar.gz spack-fef0f47d658c09415f7e0761f3f00c27cfd8a410.tar.bz2 spack-fef0f47d658c09415f7e0761f3f00c27cfd8a410.tar.xz spack-fef0f47d658c09415f7e0761f3f00c27cfd8a410.zip |
spack mirror create takes local paths only (#34992)
spack mirror create cannot work with urls, so it shouldn't promote local
paths to file urls.
-rw-r--r-- | lib/spack/spack/cmd/mirror.py | 43 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/mirror.py | 14 |
2 files changed, 14 insertions, 43 deletions
diff --git a/lib/spack/spack/cmd/mirror.py b/lib/spack/spack/cmd/mirror.py index 7d5f96c5c2..837c9ad64f 100644 --- a/lib/spack/spack/cmd/mirror.py +++ b/lib/spack/spack/cmd/mirror.py @@ -9,6 +9,7 @@ import llnl.util.lang as lang import llnl.util.tty as tty import llnl.util.tty.colify as colify +import spack.caches import spack.cmd import spack.cmd.common.arguments as arguments import spack.concretize @@ -18,7 +19,6 @@ import spack.mirror import spack.repo import spack.spec import spack.util.path -import spack.util.url as url_util import spack.util.web as web_util from spack.error import SpackError from spack.util.spack_yaml import syaml_dict @@ -374,11 +374,9 @@ def versions_per_spec(args): return num_versions -def create_mirror_for_individual_specs(mirror_specs, directory_hint, skip_unstable_versions): - present, mirrored, error = spack.mirror.create( - directory_hint, mirror_specs, skip_unstable_versions - ) - tty.msg("Summary for mirror in {}".format(directory_hint)) +def create_mirror_for_individual_specs(mirror_specs, path, skip_unstable_versions): + present, mirrored, error = spack.mirror.create(path, mirror_specs, skip_unstable_versions) + tty.msg("Summary for mirror in {}".format(path)) process_mirror_stats(present, mirrored, error) @@ -396,19 +394,6 @@ def process_mirror_stats(present, mirrored, error): sys.exit(1) -def local_mirror_url_from_user(directory_hint): - """Return a file:// url pointing to the local mirror to be used. - - Args: - directory_hint (str or None): directory where to create the mirror. If None, - defaults to "config:source_cache". - """ - mirror_directory = spack.util.path.canonicalize_path( - directory_hint or spack.config.get("config:source_cache") - ) - return url_util.path_to_file_url(mirror_directory) - - def mirror_create(args): """Create a directory to be used as a spack mirror, and fill it with package archives. @@ -439,9 +424,12 @@ def mirror_create(args): "The option '--all' already implies mirroring all versions for each package.", ) + # When no directory is provided, the source dir is used + path = args.directory or spack.caches.fetch_cache_location() + if args.all and not ev.active_environment(): create_mirror_for_all_specs( - directory_hint=args.directory, + path=path, skip_unstable_versions=args.skip_unstable_versions, selection_fn=not_excluded_fn(args), ) @@ -449,7 +437,7 @@ def mirror_create(args): if args.all and ev.active_environment(): create_mirror_for_all_specs_inside_environment( - directory_hint=args.directory, + path=path, skip_unstable_versions=args.skip_unstable_versions, selection_fn=not_excluded_fn(args), ) @@ -458,16 +446,15 @@ def mirror_create(args): mirror_specs = concrete_specs_from_user(args) create_mirror_for_individual_specs( mirror_specs, - directory_hint=args.directory, + path=path, skip_unstable_versions=args.skip_unstable_versions, ) -def create_mirror_for_all_specs(directory_hint, skip_unstable_versions, selection_fn): +def create_mirror_for_all_specs(path, skip_unstable_versions, selection_fn): mirror_specs = all_specs_with_all_versions(selection_fn=selection_fn) - local_push_url = local_mirror_url_from_user(directory_hint=directory_hint) mirror_cache, mirror_stats = spack.mirror.mirror_cache_and_stats( - local_push_url, skip_unstable_versions=skip_unstable_versions + path, skip_unstable_versions=skip_unstable_versions ) for candidate in mirror_specs: pkg_cls = spack.repo.path.get_pkg_class(candidate.name) @@ -477,13 +464,11 @@ def create_mirror_for_all_specs(directory_hint, skip_unstable_versions, selectio process_mirror_stats(*mirror_stats.stats()) -def create_mirror_for_all_specs_inside_environment( - directory_hint, skip_unstable_versions, selection_fn -): +def create_mirror_for_all_specs_inside_environment(path, skip_unstable_versions, selection_fn): mirror_specs = concrete_specs_from_environment(selection_fn=selection_fn) create_mirror_for_individual_specs( mirror_specs, - directory_hint=directory_hint, + path=path, skip_unstable_versions=skip_unstable_versions, ) diff --git a/lib/spack/spack/test/cmd/mirror.py b/lib/spack/spack/test/cmd/mirror.py index 30697b4122..99b92ae00f 100644 --- a/lib/spack/spack/test/cmd/mirror.py +++ b/lib/spack/spack/test/cmd/mirror.py @@ -302,20 +302,6 @@ class TestMirrorCreate(object): spack.cmd.mirror.mirror_create(args) @pytest.mark.parametrize( - "cli_args,expected_end", - [ - ({"directory": None}, os.path.join("source")), - ({"directory": os.path.join("foo", "bar")}, os.path.join("foo", "bar")), - ], - ) - def test_mirror_path_is_valid(self, cli_args, expected_end, config): - args = MockMirrorArgs(**cli_args) - local_push_url = spack.cmd.mirror.local_mirror_url_from_user(args.directory) - assert local_push_url.startswith("file:") - assert os.path.isabs(local_push_url.replace("file://", "")) - assert local_push_url.endswith(expected_end) - - @pytest.mark.parametrize( "cli_args,not_expected", [ ( |