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.
This commit is contained in:
Harmen Stoppels 2023-01-18 11:45:58 +01:00 committed by Massimiliano Culpo
parent 390112fc76
commit fffca98a02
2 changed files with 14 additions and 45 deletions

View File

@ -9,6 +9,7 @@
import llnl.util.tty as tty import llnl.util.tty as tty
import llnl.util.tty.colify as colify import llnl.util.tty.colify as colify
import spack.caches
import spack.cmd import spack.cmd
import spack.cmd.common.arguments as arguments import spack.cmd.common.arguments as arguments
import spack.concretize import spack.concretize
@ -356,12 +357,9 @@ def versions_per_spec(args):
return num_versions return num_versions
def create_mirror_for_individual_specs(mirror_specs, directory_hint, skip_unstable_versions): def create_mirror_for_individual_specs(mirror_specs, path, skip_unstable_versions):
local_push_url = local_mirror_url_from_user(directory_hint) present, mirrored, error = spack.mirror.create(path, mirror_specs, skip_unstable_versions)
present, mirrored, error = spack.mirror.create( tty.msg("Summary for mirror in {}".format(path))
local_push_url, mirror_specs, skip_unstable_versions
)
tty.msg("Summary for mirror in {}".format(local_push_url))
process_mirror_stats(present, mirrored, error) process_mirror_stats(present, mirrored, error)
@ -379,21 +377,6 @@ def process_mirror_stats(present, mirrored, error):
sys.exit(1) 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")
)
tmp_mirror = spack.mirror.Mirror(mirror_directory)
local_url = url_util.format(tmp_mirror.push_url)
return local_url
def mirror_create(args): def mirror_create(args):
"""Create a directory to be used as a spack mirror, and fill it with """Create a directory to be used as a spack mirror, and fill it with
package archives. package archives.
@ -424,9 +407,12 @@ def mirror_create(args):
"The option '--all' already implies mirroring all versions for each package.", "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(): if args.all and not ev.active_environment():
create_mirror_for_all_specs( create_mirror_for_all_specs(
directory_hint=args.directory, path=path,
skip_unstable_versions=args.skip_unstable_versions, skip_unstable_versions=args.skip_unstable_versions,
selection_fn=not_excluded_fn(args), selection_fn=not_excluded_fn(args),
) )
@ -434,7 +420,7 @@ def mirror_create(args):
if args.all and ev.active_environment(): if args.all and ev.active_environment():
create_mirror_for_all_specs_inside_environment( create_mirror_for_all_specs_inside_environment(
directory_hint=args.directory, path=path,
skip_unstable_versions=args.skip_unstable_versions, skip_unstable_versions=args.skip_unstable_versions,
selection_fn=not_excluded_fn(args), selection_fn=not_excluded_fn(args),
) )
@ -443,16 +429,15 @@ def mirror_create(args):
mirror_specs = concrete_specs_from_user(args) mirror_specs = concrete_specs_from_user(args)
create_mirror_for_individual_specs( create_mirror_for_individual_specs(
mirror_specs, mirror_specs,
directory_hint=args.directory, path=path,
skip_unstable_versions=args.skip_unstable_versions, 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) 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( 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: for candidate in mirror_specs:
pkg_cls = spack.repo.path.get_pkg_class(candidate.name) pkg_cls = spack.repo.path.get_pkg_class(candidate.name)
@ -462,13 +447,11 @@ def create_mirror_for_all_specs(directory_hint, skip_unstable_versions, selectio
process_mirror_stats(*mirror_stats.stats()) process_mirror_stats(*mirror_stats.stats())
def create_mirror_for_all_specs_inside_environment( def create_mirror_for_all_specs_inside_environment(path, skip_unstable_versions, selection_fn):
directory_hint, skip_unstable_versions, selection_fn
):
mirror_specs = concrete_specs_from_environment(selection_fn=selection_fn) mirror_specs = concrete_specs_from_environment(selection_fn=selection_fn)
create_mirror_for_individual_specs( create_mirror_for_individual_specs(
mirror_specs, mirror_specs,
directory_hint=directory_hint, path=path,
skip_unstable_versions=skip_unstable_versions, skip_unstable_versions=skip_unstable_versions,
) )

View File

@ -333,20 +333,6 @@ def test_error_conditions(self, cli_args, error_str):
with pytest.raises(spack.error.SpackError, match=error_str): with pytest.raises(spack.error.SpackError, match=error_str):
spack.cmd.mirror.mirror_create(args) 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( @pytest.mark.parametrize(
"cli_args,not_expected", "cli_args,not_expected",
[ [