summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-10-22 13:05:06 +0200
committerGitHub <noreply@github.com>2024-10-22 13:05:06 +0200
commitcbad3d464aceacc877f20e0c9ad2e1baded8bbf1 (patch)
tree38bf83e2c117c63fd4d62c6932c09d9708528dff
parentb56e7922957ce2edbf4526307cc90b1ab29c6eff (diff)
downloadspack-cbad3d464aceacc877f20e0c9ad2e1baded8bbf1.tar.gz
spack-cbad3d464aceacc877f20e0c9ad2e1baded8bbf1.tar.bz2
spack-cbad3d464aceacc877f20e0c9ad2e1baded8bbf1.tar.xz
spack-cbad3d464aceacc877f20e0c9ad2e1baded8bbf1.zip
buildcache: recognize . and .. as paths instead of names (#47105)
-rw-r--r--lib/spack/spack/cmd/common/arguments.py12
-rw-r--r--lib/spack/spack/mirror.py7
-rw-r--r--lib/spack/spack/test/mirror.py11
3 files changed, 19 insertions, 11 deletions
diff --git a/lib/spack/spack/cmd/common/arguments.py b/lib/spack/spack/cmd/common/arguments.py
index 456ad0f5ac..6a4a43e9e9 100644
--- a/lib/spack/spack/cmd/common/arguments.py
+++ b/lib/spack/spack/cmd/common/arguments.py
@@ -660,34 +660,32 @@ def mirror_name_or_url(m):
# accidentally to a dir in the current working directory.
# If there's a \ or / in the name, it's interpreted as a path or url.
- if "/" in m or "\\" in m:
+ if "/" in m or "\\" in m or m in (".", ".."):
return spack.mirror.Mirror(m)
# Otherwise, the named mirror is required to exist.
try:
return spack.mirror.require_mirror_name(m)
except ValueError as e:
- raise argparse.ArgumentTypeError(
- str(e) + ". Did you mean {}?".format(os.path.join(".", m))
- )
+ raise argparse.ArgumentTypeError(f"{e}. Did you mean {os.path.join('.', m)}?") from e
def mirror_url(url):
try:
return spack.mirror.Mirror.from_url(url)
except ValueError as e:
- raise argparse.ArgumentTypeError(str(e))
+ raise argparse.ArgumentTypeError(str(e)) from e
def mirror_directory(path):
try:
return spack.mirror.Mirror.from_local_path(path)
except ValueError as e:
- raise argparse.ArgumentTypeError(str(e))
+ raise argparse.ArgumentTypeError(str(e)) from e
def mirror_name(name):
try:
return spack.mirror.require_mirror_name(name)
except ValueError as e:
- raise argparse.ArgumentTypeError(str(e))
+ raise argparse.ArgumentTypeError(str(e)) from e
diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py
index 8caa272137..4254763773 100644
--- a/lib/spack/spack/mirror.py
+++ b/lib/spack/spack/mirror.py
@@ -89,9 +89,8 @@ class Mirror:
"""Create an anonymous mirror by URL. This method validates the URL."""
if not urllib.parse.urlparse(url).scheme in supported_url_schemes:
raise ValueError(
- '"{}" is not a valid mirror URL. Scheme must be once of {}.'.format(
- url, ", ".join(supported_url_schemes)
- )
+ f'"{url}" is not a valid mirror URL. '
+ f"Scheme must be one of {supported_url_schemes}."
)
return Mirror(url)
@@ -759,7 +758,7 @@ def require_mirror_name(mirror_name):
"""Find a mirror by name and raise if it does not exist"""
mirror = spack.mirror.MirrorCollection().get(mirror_name)
if not mirror:
- raise ValueError('no mirror named "{0}"'.format(mirror_name))
+ raise ValueError(f'no mirror named "{mirror_name}"')
return mirror
diff --git a/lib/spack/spack/test/mirror.py b/lib/spack/spack/test/mirror.py
index 10d375a7fb..b62d5a3e41 100644
--- a/lib/spack/spack/test/mirror.py
+++ b/lib/spack/spack/test/mirror.py
@@ -8,6 +8,7 @@ import os
import pytest
+from llnl.util.filesystem import working_dir
from llnl.util.symlink import resolve_link_target_relative_to_the_link
import spack.caches
@@ -19,6 +20,7 @@ import spack.stage
import spack.util.executable
import spack.util.spack_json as sjson
import spack.util.url as url_util
+from spack.cmd.common.arguments import mirror_name_or_url
from spack.spec import Spec
from spack.util.executable import which
from spack.util.spack_yaml import SpackYAMLError
@@ -357,3 +359,12 @@ def test_update_connection_params(direction):
assert m.get_access_token(direction) == "token"
assert m.get_profile(direction) == "profile"
assert m.get_endpoint_url(direction) == "https://example.com"
+
+
+def test_mirror_name_or_url_dir_parsing(tmp_path):
+ curdir = tmp_path / "mirror"
+ curdir.mkdir()
+
+ with working_dir(curdir):
+ assert mirror_name_or_url(".").fetch_url == curdir.as_uri()
+ assert mirror_name_or_url("..").fetch_url == tmp_path.as_uri()