This commit is contained in:
Gregory Becker 2024-07-17 09:41:14 -07:00
parent aef5c35065
commit ba62db9add
34 changed files with 142 additions and 156 deletions

View File

@ -46,7 +46,7 @@ def root_path() -> str:
"""Root of all the bootstrap related folders""" """Root of all the bootstrap related folders"""
return spack.util.path.canonicalize_path( return spack.util.path.canonicalize_path(
spack.config.get("bootstrap:root", spack.paths.default_user_bootstrap_path), spack.config.get("bootstrap:root", spack.paths.default_user_bootstrap_path),
replacements=spack.paths.path_replacements() replacements=spack.paths.path_replacements(),
) )
@ -80,14 +80,16 @@ def spack_python_interpreter() -> Generator:
def _store_path() -> str: def _store_path() -> str:
bootstrap_root_path = root_path() bootstrap_root_path = root_path()
return spack.util.path.canonicalize_path(os.path.join(bootstrap_root_path, "store"), return spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) os.path.join(bootstrap_root_path, "store"), replacements=spack.paths.path_replacements()
)
def _config_path() -> str: def _config_path() -> str:
bootstrap_root_path = root_path() bootstrap_root_path = root_path()
return spack.util.path.canonicalize_path(os.path.join(bootstrap_root_path, "config"), return spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) os.path.join(bootstrap_root_path, "config"), replacements=spack.paths.path_replacements()
)
@contextlib.contextmanager @contextlib.contextmanager

View File

@ -93,8 +93,7 @@ def __init__(self, conf: ConfigDictionary) -> None:
self.conf = conf self.conf = conf
self.name = conf["name"] self.name = conf["name"]
self.metadata_dir = spack.util.path.canonicalize_path( self.metadata_dir = spack.util.path.canonicalize_path(
conf["metadata"], conf["metadata"], replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
# Promote (relative) paths to file urls # Promote (relative) paths to file urls
@ -589,8 +588,7 @@ def bootstrapping_sources(scope: Optional[str] = None):
for entry in source_configs: for entry in source_configs:
current = copy.copy(entry) current = copy.copy(entry)
metadata_dir = spack.util.path.canonicalize_path( metadata_dir = spack.util.path.canonicalize_path(
entry["metadata"], entry["metadata"], replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
metadata_yaml = os.path.join(metadata_dir, METADATA_YAML_FILENAME) metadata_yaml = os.path.join(metadata_dir, METADATA_YAML_FILENAME)
with open(metadata_yaml, encoding="utf-8") as stream: with open(metadata_yaml, encoding="utf-8") as stream:

View File

@ -26,8 +26,7 @@ def misc_cache_location():
providers and for which packages provide which tags. providers and for which packages provide which tags.
""" """
path = spack.config.get("config:misc_cache", spack.paths.default_misc_cache_path) path = spack.config.get("config:misc_cache", spack.paths.default_misc_cache_path)
return spack.util.path.canonicalize_path(path, return spack.util.path.canonicalize_path(path, replacements=spack.paths.path_replacements())
replacements=spack.paths.path_replacements())
def _misc_cache(): def _misc_cache():
@ -50,8 +49,7 @@ def fetch_cache_location():
path = spack.config.get("config:source_cache") path = spack.config.get("config:source_cache")
if not path: if not path:
path = spack.paths.default_fetch_cache_path path = spack.paths.default_fetch_cache_path
path = spack.util.path.canonicalize_path(path, path = spack.util.path.canonicalize_path(path, replacements=spack.paths.path_replacements())
replacements=spack.paths.path_replacements())
return path return path

View File

@ -192,8 +192,9 @@ def _root(args):
root = spack.config.get("bootstrap:root", default=None, scope=args.scope) root = spack.config.get("bootstrap:root", default=None, scope=args.scope)
if root: if root:
root = spack.util.path.canonicalize_path(root, root = spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) root, replacements=spack.paths.path_replacements()
)
print(root) print(root)
@ -337,8 +338,9 @@ def _add(args):
raise RuntimeError(msg.format(args.name)) raise RuntimeError(msg.format(args.name))
# Check that the metadata file exists # Check that the metadata file exists
metadata_dir = spack.util.path.canonicalize_path(args.metadata_dir, metadata_dir = spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) args.metadata_dir, replacements=spack.paths.path_replacements()
)
if not os.path.exists(metadata_dir) or not os.path.isdir(metadata_dir): if not os.path.exists(metadata_dir) or not os.path.isdir(metadata_dir):
raise RuntimeError('the directory "{0}" does not exist'.format(args.metadata_dir)) raise RuntimeError('the directory "{0}" does not exist'.format(args.metadata_dir))
@ -387,8 +389,9 @@ def _remove(args):
def _mirror(args): def _mirror(args):
mirror_dir = spack.util.path.canonicalize_path(os.path.join(args.root_dir, LOCAL_MIRROR_DIR), mirror_dir = spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) os.path.join(args.root_dir, LOCAL_MIRROR_DIR), replacements=spack.paths.path_replacements()
)
# TODO: Here we are adding gnuconfig manually, but this can be fixed # TODO: Here we are adding gnuconfig manually, but this can be fixed
# TODO: as soon as we have an option to add to a mirror all the possible # TODO: as soon as we have an option to add to a mirror all the possible
@ -438,19 +441,22 @@ def write_metadata(subdir, metadata):
if args.binary_packages: if args.binary_packages:
abs_directory, rel_directory = write_metadata(subdir="binaries", metadata=BINARY_METADATA) abs_directory, rel_directory = write_metadata(subdir="binaries", metadata=BINARY_METADATA)
shutil.copy( shutil.copy(
spack.util.path.canonicalize_path(CLINGO_JSON, spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()), CLINGO_JSON, replacements=spack.paths.path_replacements()
abs_directory ),
abs_directory,
) )
shutil.copy( shutil.copy(
spack.util.path.canonicalize_path(GNUPG_JSON, spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()), GNUPG_JSON, replacements=spack.paths.path_replacements()
abs_directory ),
abs_directory,
) )
shutil.copy( shutil.copy(
spack.util.path.canonicalize_path(PATCHELF_JSON, spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()), PATCHELF_JSON, replacements=spack.paths.path_replacements()
abs_directory ),
abs_directory,
) )
instructions += cmd.format("local-binaries", rel_directory) instructions += cmd.format("local-binaries", rel_directory)
print(instructions) print(instructions)

View File

@ -276,4 +276,4 @@ def add_versions_to_package(pkg: PackageBase, version_lines: str):
tty.msg(f"Open {filename} to review the additions.") tty.msg(f"Open {filename} to review the additions.")
if sys.stdout.isatty(): if sys.stdout.isatty():
editor(filename, debug=spack.config.get('config:debug')) editor(filename, debug=spack.config.get("config:debug"))

View File

@ -135,8 +135,7 @@ def clean(parser, args):
if args.bootstrap: if args.bootstrap:
bootstrap_prefix = spack.util.path.canonicalize_path( bootstrap_prefix = spack.util.path.canonicalize_path(
spack.config.get("bootstrap:root"), spack.config.get("bootstrap:root"), replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
msg = 'Removing bootstrapped software and configuration in "{0}"' msg = 'Removing bootstrapped software and configuration in "{0}"'
tty.msg(msg.format(bootstrap_prefix)) tty.msg(msg.format(bootstrap_prefix))

View File

@ -180,7 +180,7 @@ def config_edit(args):
if args.print_file: if args.print_file:
print(config_file) print(config_file)
else: else:
editor(config_file, debug=spack.config.get('config:debug')) editor(config_file, debug=spack.config.get("config:debug"))
def config_list(args): def config_list(args):

View File

@ -987,4 +987,4 @@ def create(parser, args):
# Optionally open up the new package file in your $EDITOR # Optionally open up the new package file in your $EDITOR
if not args.skip_editor: if not args.skip_editor:
editor(pkg_path, debug=spack.config.get('config:debug')) editor(pkg_path, debug=spack.config.get("config:debug"))

View File

@ -57,8 +57,7 @@ def develop(parser, args):
for name, entry in env.dev_specs.items(): for name, entry in env.dev_specs.items():
path = entry.get("path", name) path = entry.get("path", name)
abspath = spack.util.path.canonicalize_path( abspath = spack.util.path.canonicalize_path(
path, default_wd=env.path, path, default_wd=env.path, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
if os.path.exists(abspath): if os.path.exists(abspath):
@ -90,8 +89,9 @@ def develop(parser, args):
# default path is relative path to spec.name # default path is relative path to spec.name
path = args.path or spec.name path = args.path or spec.name
abspath = spack.util.path.canonicalize_path(path, default_wd=env.path, abspath = spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) path, default_wd=env.path, replacements=spack.paths.path_replacements()
)
# clone default: only if the path doesn't exist # clone default: only if the path doesn't exist
clone = args.clone clone = args.clone

View File

@ -46,7 +46,7 @@ def edit_package(name, repo_path, namespace):
else: else:
raise spack.repo.UnknownPackageError(spec.name) raise spack.repo.UnknownPackageError(spec.name)
editor(path, debug=spack.config.get('config:debug')) editor(path, debug=spack.config.get("config:debug"))
def setup_parser(subparser): def setup_parser(subparser):

View File

@ -132,9 +132,7 @@ def gpg_create(args):
old_sec_keys = spack.gpg.signing_keys() old_sec_keys = spack.gpg.signing_keys()
# Create the new key # Create the new key
spack.gpg.create( spack.gpg.create(name=args.name, email=args.email, comment=args.comment, expires=args.expires)
name=args.name, email=args.email, comment=args.comment, expires=args.expires
)
if args.export or args.secret: if args.export or args.secret:
new_sec_keys = set(spack.gpg.signing_keys()) new_sec_keys = set(spack.gpg.signing_keys())
new_keys = new_sec_keys.difference(old_sec_keys) new_keys = new_sec_keys.difference(old_sec_keys)

View File

@ -84,8 +84,9 @@ def repo_add(args):
path = args.path path = args.path
# real_path is absolute and handles substitution. # real_path is absolute and handles substitution.
canon_path = spack.util.path.canonicalize_path(path, canon_path = spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) path, replacements=spack.paths.path_replacements()
)
# check if the path exists # check if the path exists
if not os.path.exists(canon_path): if not os.path.exists(canon_path):
@ -117,12 +118,12 @@ def repo_remove(args):
namespace_or_path = args.namespace_or_path namespace_or_path = args.namespace_or_path
# If the argument is a path, remove that repository from config. # If the argument is a path, remove that repository from config.
canon_path = spack.util.path.canonicalize_path(namespace_or_path, canon_path = spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) namespace_or_path, replacements=spack.paths.path_replacements()
)
for repo_path in repos: for repo_path in repos:
repo_canon_path = spack.util.path.canonicalize_path( repo_canon_path = spack.util.path.canonicalize_path(
repo_path, repo_path, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
if canon_path == repo_canon_path: if canon_path == repo_canon_path:
repos.remove(repo_path) repos.remove(repo_path)

View File

@ -92,8 +92,9 @@ def concretize_develop(self, spec):
if not dev_info: if not dev_info:
return False return False
path = spack.util.path.canonicalize_path(dev_info["path"], default_wd=env.path, path = spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) dev_info["path"], default_wd=env.path, replacements=spack.paths.path_replacements()
)
if "dev_path" in spec.variants: if "dev_path" in spec.variants:
assert spec.variants["dev_path"].value == path assert spec.variants["dev_path"].value == path

View File

@ -1452,9 +1452,7 @@ def _fetch_file(url):
raw = raw_github_gitlab_url(url) raw = raw_github_gitlab_url(url)
tty.debug("Reading config from url {0}".format(raw)) tty.debug("Reading config from url {0}".format(raw))
return web_util.fetch_url_text( return web_util.fetch_url_text(
raw, raw, dest_dir=dest_dir, fetch_method=CONFIG.get("config:url_fetch_method")
dest_dir=dest_dir,
fetch_method=CONFIG.get('config:url_fetch_method')
) )
if not url: if not url:

View File

@ -91,7 +91,7 @@ def env_root_path():
"""Override default root path if the user specified it""" """Override default root path if the user specified it"""
return spack.util.path.canonicalize_path( return spack.util.path.canonicalize_path(
spack.config.get("config:environments_root", default=default_env_path), spack.config.get("config:environments_root", default=default_env_path),
replacements=spack.paths.path_replacements() replacements=spack.paths.path_replacements(),
) )
@ -480,8 +480,7 @@ def __init__(
self.base = base_path self.base = base_path
self.raw_root = root self.raw_root = root
self.root = spack.util.path.canonicalize_path( self.root = spack.util.path.canonicalize_path(
root, default_wd=base_path, root, default_wd=base_path, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
self.projections = projections self.projections = projections
self.select = select self.select = select
@ -498,8 +497,7 @@ def exclude_fn(self, spec):
def update_root(self, new_path): def update_root(self, new_path):
self.raw_root = new_path self.raw_root = new_path
self.root = spack.util.path.canonicalize_path( self.root = spack.util.path.canonicalize_path(
new_path, default_wd=self.base, new_path, default_wd=self.base, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
def __eq__(self, other): def __eq__(self, other):
@ -992,8 +990,9 @@ def included_config_scopes(self):
missing = [] missing = []
for i, config_path in enumerate(reversed(includes)): for i, config_path in enumerate(reversed(includes)):
# allow paths to contain spack config/environment variables, etc. # allow paths to contain spack config/environment variables, etc.
config_path = substitute_path_variables(config_path, config_path = substitute_path_variables(
replacements=spack.paths.path_replacements()) config_path, replacements=spack.paths.path_replacements()
)
include_url = urllib.parse.urlparse(config_path) include_url = urllib.parse.urlparse(config_path)
@ -1305,8 +1304,7 @@ def develop(self, spec: Spec, path: str, clone: bool = False) -> bool:
# better if we can create the `source_path` directly into its final # better if we can create the `source_path` directly into its final
# destination. # destination.
abspath = spack.util.path.canonicalize_path( abspath = spack.util.path.canonicalize_path(
path, default_wd=self.path, path, default_wd=self.path, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
pkg_cls = spack.repo.PATH.get_pkg_class(spec.name) pkg_cls = spack.repo.PATH.get_pkg_class(spec.name)
# We construct a package class ourselves, rather than asking for # We construct a package class ourselves, rather than asking for

View File

@ -40,7 +40,7 @@ def set_up_license(pkg):
write_license_file(pkg, license_path) write_license_file(pkg, license_path)
# use spack.util.executable so the editor does not hang on return here # use spack.util.executable so the editor does not hang on return here
ed.editor(license_path, exec_fn=ed.executable, debug=spack.config.get('config:debug')) ed.editor(license_path, exec_fn=ed.executable, debug=spack.config.get("config:debug"))
else: else:
# Use already existing license file # Use already existing license file
tty.msg("Found already existing license %s" % license_path) tty.msg("Found already existing license %s" % license_path)

View File

@ -92,7 +92,7 @@ def get_test_stage_dir():
""" """
return spack.util.path.canonicalize_path( return spack.util.path.canonicalize_path(
spack.config.get("config:test_stage", spack.paths.default_test_path), spack.config.get("config:test_stage", spack.paths.default_test_path),
replacements=spack.paths.path_replacements() replacements=spack.paths.path_replacements(),
) )

View File

@ -491,7 +491,7 @@ def _process_binary_cache_tarball(
tty.msg(f"Extracting {package_id(pkg)} from binary cache") tty.msg(f"Extracting {package_id(pkg)} from binary cache")
padding = spack.config.get('config:install_tree:padded_length', None) padding = spack.config.get("config:install_tree:padded_length", None)
with timer.measure("install"), spack.util.path.filter_padding(padding=padding): with timer.measure("install"), spack.util.path.filter_padding(padding=padding):
binary_distribution.extract_tarball( binary_distribution.extract_tarball(
pkg.spec, download_result, unsigned=unsigned, force=False, timer=timer pkg.spec, download_result, unsigned=unsigned, force=False, timer=timer
@ -2493,7 +2493,7 @@ def build_process(pkg: "spack.package_base.PackageBase", install_args: dict) ->
installer = BuildProcessInstaller(pkg, install_args) installer = BuildProcessInstaller(pkg, install_args)
# don't print long padded paths in executable debug output. # don't print long padded paths in executable debug output.
padding = spack.config.get('config:install_tree:padded_length', None) padding = spack.config.get("config:install_tree:padded_length", None)
with spack.util.path.filter_padding(padding=padding): with spack.util.path.filter_padding(padding=padding):
return installer.run() return installer.run()

View File

@ -53,8 +53,9 @@ def _url_or_path_to_url(url_or_path: str) -> str:
# Otherwise we interpret it as path, and we should promote it to file:// URL. # Otherwise we interpret it as path, and we should promote it to file:// URL.
return url_util.path_to_file_url( return url_util.path_to_file_url(
spack.util.path.canonicalize_path(url_or_path, spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) url_or_path, replacements=spack.paths.path_replacements()
)
) )

View File

@ -225,8 +225,7 @@ def root_path(name, module_set_name):
roots = spack.config.merge_yaml(defaults, roots) roots = spack.config.merge_yaml(defaults, roots)
path = roots.get(name, os.path.join(spack.paths.share_path, name)) path = roots.get(name, os.path.join(spack.paths.share_path, name))
return spack.util.path.canonicalize_path(path, return spack.util.path.canonicalize_path(path, replacements=spack.paths.path_replacements())
replacements=spack.paths.path_replacements())
def generate_module_index(root, modules, overwrite=False): def generate_module_index(root, modules, overwrite=False):

View File

@ -180,8 +180,9 @@ def _package(maybe_abstract_spec):
spec_str = entry["spec"] spec_str = entry["spec"]
external_path = entry.get("prefix", None) external_path = entry.get("prefix", None)
if external_path: if external_path:
external_path = canonicalize_path(external_path, external_path = canonicalize_path(
replacements=spack.paths.path_replacements()) external_path, replacements=spack.paths.path_replacements()
)
external_modules = entry.get("modules", None) external_modules = entry.get("modules", None)
external_spec = spack.spec.Spec.from_detection( external_spec = spack.spec.Spec.from_detection(
spack.spec.Spec( spack.spec.Spec(

View File

@ -930,8 +930,7 @@ def __init__(self, root, cache=None):
# Root directory, containing _repo.yaml and package dirs # Root directory, containing _repo.yaml and package dirs
# Allow roots to by spack-relative by starting with '$spack' # Allow roots to by spack-relative by starting with '$spack'
self.root = spack.util.path.canonicalize_path( self.root = spack.util.path.canonicalize_path(
root, root, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
# check and raise BadRepoError on fail. # check and raise BadRepoError on fail.
@ -1331,8 +1330,7 @@ def create_repo(root, namespace=None, subdir=packages_dir_name):
If the namespace is not provided, use basename of root. If the namespace is not provided, use basename of root.
Return the canonicalized path and namespace of the created repository. Return the canonicalized path and namespace of the created repository.
""" """
root = spack.util.path.canonicalize_path(root, root = spack.util.path.canonicalize_path(root, replacements=spack.paths.path_replacements())
replacements=spack.paths.path_replacements())
if not namespace: if not namespace:
namespace = os.path.basename(root) namespace = os.path.basename(root)

View File

@ -2604,8 +2604,9 @@ def setup(
spack.spec.Spec(info["spec"]).constrained( spack.spec.Spec(info["spec"]).constrained(
"dev_path=%s" "dev_path=%s"
% spack.util.path.canonicalize_path( % spack.util.path.canonicalize_path(
info["path"], default_wd=env.path, info["path"],
replacements=spack.paths.path_replacements() default_wd=env.path,
replacements=spack.paths.path_replacements(),
) )
) )
for name, info in env.dev_specs.items() for name, info in env.dev_specs.items()
@ -3123,8 +3124,9 @@ def _develop_specs_from_env(spec, env):
if not dev_info: if not dev_info:
return return
path = spack.util.path.canonicalize_path(dev_info["path"], default_wd=env.path, path = spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()) dev_info["path"], default_wd=env.path, replacements=spack.paths.path_replacements()
)
if "dev_path" in spec.variants: if "dev_path" in spec.variants:
error_msg = ( error_msg = (

View File

@ -150,8 +150,7 @@ def _resolve_paths(candidates):
Adjustments involve removing extra $user from $tempdir if $tempdir includes Adjustments involve removing extra $user from $tempdir if $tempdir includes
$user and appending $user if it is not present in the path. $user and appending $user if it is not present in the path.
""" """
temp_path = sup.canonicalize_path("$tempdir", temp_path = sup.canonicalize_path("$tempdir", replacements=spack.paths.path_replacements())
replacements=spack.paths.path_replacements())
user = getpass.getuser() user = getpass.getuser()
tmp_has_usr = user in temp_path.split(os.path.sep) tmp_has_usr = user in temp_path.split(os.path.sep)
@ -163,8 +162,7 @@ def _resolve_paths(candidates):
path = path.replace("/$user", "", 1) path = path.replace("/$user", "", 1)
# Ensure the path is unique per user. # Ensure the path is unique per user.
can_path = sup.canonicalize_path(path, can_path = sup.canonicalize_path(path, replacements=spack.paths.path_replacements())
replacements=spack.paths.path_replacements())
# When multiple users share a stage root, we can avoid conflicts between # When multiple users share a stage root, we can avoid conflicts between
# them by adding a per-user subdirectory. # them by adding a per-user subdirectory.
# Avoid doing this on Windows to keep stage absolute path as short as possible. # Avoid doing this on Windows to keep stage absolute path as short as possible.
@ -201,11 +199,10 @@ def get_stage_root():
def _mirror_roots(): def _mirror_roots():
mirrors = spack.config.get("mirrors") mirrors = spack.config.get("mirrors")
return [ return [
sup.substitute_path_variables(root, sup.substitute_path_variables(root, replacements=spack.paths.path_replacements())
replacements=spack.paths.path_replacements())
if root.endswith(os.sep) if root.endswith(os.sep)
else sup.substitute_path_variables(root, else sup.substitute_path_variables(root, replacemnts=spack.paths.path_replacements())
replacemnts=spack.paths.path_replacements()) + os.sep + os.sep
for root in mirrors.values() for root in mirrors.values()
] ]

View File

@ -78,8 +78,7 @@ def parse_install_tree(config_dict):
tty.warn("Using deprecated format for configuring install_tree") tty.warn("Using deprecated format for configuring install_tree")
unpadded_root = install_tree unpadded_root = install_tree
unpadded_root = spack.util.path.canonicalize_path( unpadded_root = spack.util.path.canonicalize_path(
unpadded_root, unpadded_root, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
# construct projection from previous values for backwards compatibility # construct projection from previous values for backwards compatibility
all_projection = config_dict.get( all_projection = config_dict.get(
@ -90,8 +89,7 @@ def parse_install_tree(config_dict):
else: else:
unpadded_root = install_tree.get("root", DEFAULT_INSTALL_TREE_ROOT) unpadded_root = install_tree.get("root", DEFAULT_INSTALL_TREE_ROOT)
unpadded_root = spack.util.path.canonicalize_path( unpadded_root = spack.util.path.canonicalize_path(
unpadded_root, unpadded_root, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
padded_length = install_tree.get("padded_length", False) padded_length = install_tree.get("padded_length", False)
@ -273,8 +271,9 @@ def _construct_upstream_dbs_from_install_roots(
for install_root in reversed(install_roots): for install_root in reversed(install_roots):
upstream_dbs = list(accumulated_upstream_dbs) upstream_dbs = list(accumulated_upstream_dbs)
next_db = spack.database.Database( next_db = spack.database.Database(
spack.util.path.canonicalize_path(install_root, spack.util.path.canonicalize_path(
replacements=spack.paths.path_replacements()), install_root, replacements=spack.paths.path_replacements()
),
is_upstream=True, is_upstream=True,
upstream_dbs=upstream_dbs, upstream_dbs=upstream_dbs,
) )

View File

@ -78,8 +78,9 @@ def make_environment(dirs: Optional[Tuple[str, ...]] = None):
builtins = spack.config.get("config:template_dirs", ["$spack/share/spack/templates"]) builtins = spack.config.get("config:template_dirs", ["$spack/share/spack/templates"])
extensions = spack.extensions.get_template_dirs() extensions = spack.extensions.get_template_dirs()
r = spack.paths.path_replacements() r = spack.paths.path_replacements()
dirs = tuple(canonicalize_path(d, replacements=r) dirs = tuple(
for d in itertools.chain(builtins, extensions)) canonicalize_path(d, replacements=r) for d in itertools.chain(builtins, extensions)
)
# Loader for the templates # Loader for the templates
loader = jinja2.FileSystemLoader(dirs) loader = jinja2.FileSystemLoader(dirs)

View File

@ -83,8 +83,7 @@ def test_store_path_customization(config_value, expected, mutable_config):
# Check the store path # Check the store path
current = spack.bootstrap.config.store_path() current = spack.bootstrap.config.store_path()
assert current == spack.util.path.canonicalize_path( assert current == spack.util.path.canonicalize_path(
expected, expected, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )

View File

@ -108,8 +108,7 @@ def test_develop_canonicalize_path(self, monkeypatch, config):
with ev.read("test") as e: with ev.read("test") as e:
path = "../$user" path = "../$user"
abspath = spack.util.path.canonicalize_path( abspath = spack.util.path.canonicalize_path(
path, e.path, path, e.path, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
def check_path(stage, dest): def check_path(stage, dest):
@ -128,8 +127,7 @@ def test_develop_canonicalize_path_no_args(self, monkeypatch, config):
with ev.read("test") as e: with ev.read("test") as e:
path = "$user" path = "$user"
abspath = spack.util.path.canonicalize_path( abspath = spack.util.path.canonicalize_path(
path, e.path, path, e.path, replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
def check_path(stage, dest): def check_path(stage, dest):

View File

@ -904,8 +904,9 @@ def test_env_with_included_config_var_path(tmpdir, packages_file):
spack_yaml = env_path / ev.manifest_name spack_yaml = env_path / ev.manifest_name
spack_yaml.write_text(mpileaks_env_config(config_var_path)) spack_yaml.write_text(mpileaks_env_config(config_var_path))
config_real_path = substitute_path_variables(config_var_path, config_real_path = substitute_path_variables(
replacements=spack.paths.path_replacements()) config_var_path, replacements=spack.paths.path_replacements()
)
shutil.move(included_file, config_real_path) shutil.move(included_file, config_real_path)
assert os.path.exists(config_real_path) assert os.path.exists(config_real_path)

View File

@ -341,58 +341,48 @@ def test_substitute_config_variables(mock_low_high_config, monkeypatch):
r = spack.paths.path_replacements() r = spack.paths.path_replacements()
assert cross_plat_join( assert cross_plat_join(
os.sep + os.path.join("foo", "bar", "baz"), prefix os.sep + os.path.join("foo", "bar", "baz"), prefix
) == spack_path.canonicalize_path("/foo/bar/baz/$spack", ) == spack_path.canonicalize_path("/foo/bar/baz/$spack", replacements=r)
replacements=r)
assert cross_plat_join( assert cross_plat_join(
spack.paths.prefix, os.path.join("foo", "bar", "baz") spack.paths.prefix, os.path.join("foo", "bar", "baz")
) == spack_path.canonicalize_path("$spack/foo/bar/baz/", ) == spack_path.canonicalize_path("$spack/foo/bar/baz/", replacements=r)
replacements=r)
assert cross_plat_join( assert cross_plat_join(
os.sep + os.path.join("foo", "bar", "baz"), prefix, os.path.join("foo", "bar", "baz") os.sep + os.path.join("foo", "bar", "baz"), prefix, os.path.join("foo", "bar", "baz")
) == spack_path.canonicalize_path("/foo/bar/baz/$spack/foo/bar/baz/", ) == spack_path.canonicalize_path("/foo/bar/baz/$spack/foo/bar/baz/", replacements=r)
replacements=r)
assert cross_plat_join( assert cross_plat_join(
os.sep + os.path.join("foo", "bar", "baz"), prefix os.sep + os.path.join("foo", "bar", "baz"), prefix
) == spack_path.canonicalize_path("/foo/bar/baz/${spack}", ) == spack_path.canonicalize_path("/foo/bar/baz/${spack}", replacements=r)
replacements=r)
assert cross_plat_join( assert cross_plat_join(
spack.paths.prefix, os.path.join("foo", "bar", "baz") spack.paths.prefix, os.path.join("foo", "bar", "baz")
) == spack_path.canonicalize_path("${spack}/foo/bar/baz/", ) == spack_path.canonicalize_path("${spack}/foo/bar/baz/", replacements=r)
replacements=r)
assert cross_plat_join( assert cross_plat_join(
os.sep + os.path.join("foo", "bar", "baz"), prefix, os.path.join("foo", "bar", "baz") os.sep + os.path.join("foo", "bar", "baz"), prefix, os.path.join("foo", "bar", "baz")
) == spack_path.canonicalize_path("/foo/bar/baz/${spack}/foo/bar/baz/", ) == spack_path.canonicalize_path("/foo/bar/baz/${spack}/foo/bar/baz/", replacements=r)
replacements=r)
assert cross_plat_join( assert cross_plat_join(
os.sep + os.path.join("foo", "bar", "baz"), prefix, os.path.join("foo", "bar", "baz") os.sep + os.path.join("foo", "bar", "baz"), prefix, os.path.join("foo", "bar", "baz")
) != spack_path.canonicalize_path("/foo/bar/baz/${spack/foo/bar/baz/", ) != spack_path.canonicalize_path("/foo/bar/baz/${spack/foo/bar/baz/", replacements=r)
replacements=r)
# $env replacement is a no-op when no environment is active # $env replacement is a no-op when no environment is active
assert spack_path.canonicalize_path( assert spack_path.canonicalize_path(
os.sep + os.path.join("foo", "bar", "baz", "$env"), os.sep + os.path.join("foo", "bar", "baz", "$env"), replacements=r
replacements=r
) == os.sep + os.path.join("foo", "bar", "baz", "$env") ) == os.sep + os.path.join("foo", "bar", "baz", "$env")
# Fake an active environment and $env is replaced properly # Fake an active environment and $env is replaced properly
fake_env_path = os.sep + os.path.join("quux", "quuux") fake_env_path = os.sep + os.path.join("quux", "quuux")
monkeypatch.setattr(ev, "active_environment", lambda: MockEnv(fake_env_path)) monkeypatch.setattr(ev, "active_environment", lambda: MockEnv(fake_env_path))
assert spack_path.canonicalize_path("$env/foo/bar/baz", assert spack_path.canonicalize_path("$env/foo/bar/baz", replacements=r) == os.path.join(
replacements=r) == os.path.join(
fake_env_path, os.path.join("foo", "bar", "baz") fake_env_path, os.path.join("foo", "bar", "baz")
) )
# relative paths without source information are relative to cwd # relative paths without source information are relative to cwd
assert spack_path.canonicalize_path(os.path.join("foo", "bar", "baz"), assert spack_path.canonicalize_path(
replacements=r) == os.path.abspath( os.path.join("foo", "bar", "baz"), replacements=r
os.path.join("foo", "bar", "baz") ) == os.path.abspath(os.path.join("foo", "bar", "baz"))
)
# relative paths with source information are relative to the file # relative paths with source information are relative to the file
spack.config.set( spack.config.set(
@ -400,22 +390,19 @@ def test_substitute_config_variables(mock_low_high_config, monkeypatch):
) )
spack.config.CONFIG.clear_caches() spack.config.CONFIG.clear_caches()
path = spack.config.get("modules:default:roots:lmod") path = spack.config.get("modules:default:roots:lmod")
assert spack_path.canonicalize_path(path, assert spack_path.canonicalize_path(path, replacements=r) == os.path.normpath(
replacements=r) == os.path.normpath(
os.path.join(mock_low_high_config.scopes["low"].path, os.path.join("foo", "bar", "baz")) os.path.join(mock_low_high_config.scopes["low"].path, os.path.join("foo", "bar", "baz"))
) )
# test architecture information is in replacements # test architecture information is in replacements
assert spack_path.canonicalize_path( assert spack_path.canonicalize_path(
os.path.join("foo", "$platform", "bar"), os.path.join("foo", "$platform", "bar"), replacements=r
replacements=r
) == os.path.abspath(os.path.join("foo", "test", "bar")) ) == os.path.abspath(os.path.join("foo", "test", "bar"))
host_target = spack.platforms.host().target("default_target") host_target = spack.platforms.host().target("default_target")
host_target_family = str(host_target.microarchitecture.family) host_target_family = str(host_target.microarchitecture.family)
assert spack_path.canonicalize_path( assert spack_path.canonicalize_path(
os.path.join("foo", "$target_family", "bar"), os.path.join("foo", "$target_family", "bar"), replacements=r
replacements=r
) == os.path.abspath(os.path.join("foo", host_target_family, "bar")) ) == os.path.abspath(os.path.join("foo", host_target_family, "bar"))
@ -453,32 +440,32 @@ def test_substitute_user(mock_low_high_config):
"foo", "bar" "foo", "bar"
) + os.sep + user + os.sep + "baz" == spack_path.canonicalize_path( ) + os.sep + user + os.sep + "baz" == spack_path.canonicalize_path(
os.sep + os.path.join("foo", "bar", "$user", "baz"), os.sep + os.path.join("foo", "bar", "$user", "baz"),
replacements=spack.paths.path_replacements() replacements=spack.paths.path_replacements(),
) )
def test_substitute_user_cache(mock_low_high_config): def test_substitute_user_cache(mock_low_high_config):
user_cache_path = spack.paths.user_cache_path user_cache_path = spack.paths.user_cache_path
assert user_cache_path + os.sep + "baz" == spack_path.canonicalize_path( assert user_cache_path + os.sep + "baz" == spack_path.canonicalize_path(
os.path.join("$user_cache_path", "baz"), os.path.join("$user_cache_path", "baz"), replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
def test_substitute_tempdir(mock_low_high_config): def test_substitute_tempdir(mock_low_high_config):
tempdir = tempfile.gettempdir() tempdir = tempfile.gettempdir()
assert tempdir == spack_path.canonicalize_path("$tempdir", assert tempdir == spack_path.canonicalize_path(
replacements=spack.paths.path_replacements()) "$tempdir", replacements=spack.paths.path_replacements()
)
assert tempdir + os.sep + os.path.join("foo", "bar", "baz") == spack_path.canonicalize_path( assert tempdir + os.sep + os.path.join("foo", "bar", "baz") == spack_path.canonicalize_path(
os.path.join("$tempdir", "foo", "bar", "baz"), os.path.join("$tempdir", "foo", "bar", "baz"), replacements=spack.paths.path_replacements()
replacements=spack.paths.path_replacements()
) )
def test_substitute_date(mock_low_high_config): def test_substitute_date(mock_low_high_config):
test_path = os.path.join("hello", "world", "on", "$date") test_path = os.path.join("hello", "world", "on", "$date")
new_path = spack_path.canonicalize_path(test_path, new_path = spack_path.canonicalize_path(
replacements=spack.paths.path_replacements()) test_path, replacements=spack.paths.path_replacements()
)
assert "$date" in test_path assert "$date" in test_path
assert date.today().strftime("%Y-%m-%d") in new_path assert date.today().strftime("%Y-%m-%d") in new_path

View File

@ -734,8 +734,7 @@ def test_resolve_paths(self):
assert spack.stage._resolve_paths(paths) == paths assert spack.stage._resolve_paths(paths) == paths
tempdir = "$tempdir" tempdir = "$tempdir"
can_tempdir = canonicalize_path(tempdir, can_tempdir = canonicalize_path(tempdir, replacements=spack.paths.path_replacements())
replacements=spack.paths.path_replacements())
user = getpass.getuser() user = getpass.getuser()
temp_has_user = user in can_tempdir.split(os.sep) temp_has_user = user in can_tempdir.split(os.sep)
paths = [ paths = [

View File

@ -351,8 +351,7 @@ def _which(*args, **kwargs):
def test_url_fetch_text_without_url(tmpdir): def test_url_fetch_text_without_url(tmpdir):
with pytest.raises(web_util.WebError, match="URL is required"): with pytest.raises(web_util.WebError, match="URL is required"):
web_util.fetch_url_text(None, web_util.fetch_url_text(None, fetch_method=spack.config.get("config:url_fetch_method"))
fetch_method=spack.config.get('config:url_fetch_method'))
def test_url_fetch_text_curl_failures(tmpdir, monkeypatch): def test_url_fetch_text_curl_failures(tmpdir, monkeypatch):
@ -369,8 +368,9 @@ def _which(*args, **kwargs):
with spack.config.override("config:url_fetch_method", "curl"): with spack.config.override("config:url_fetch_method", "curl"):
with pytest.raises(web_util.WebError, match="Missing required curl"): with pytest.raises(web_util.WebError, match="Missing required curl"):
web_util.fetch_url_text("https://github.com/", web_util.fetch_url_text(
fetch_method=spack.config.get('config:url_fetch_method')) "https://github.com/", fetch_method=spack.config.get("config:url_fetch_method")
)
def test_url_check_curl_errors(): def test_url_check_curl_errors():
@ -398,8 +398,10 @@ def _which(*args, **kwargs):
with spack.config.override("config:url_fetch_method", "curl"): with spack.config.override("config:url_fetch_method", "curl"):
with pytest.raises(web_util.WebError, match="Missing required curl"): with pytest.raises(web_util.WebError, match="Missing required curl"):
web_util.url_exists("https://github.com/", web_util.url_exists(
fetch_method=spack.config.get('config:url_fetch_method', 'urllib')) "https://github.com/",
fetch_method=spack.config.get("config:url_fetch_method", "urllib"),
)
def test_url_fetch_text_urllib_bad_returncode(tmpdir, monkeypatch): def test_url_fetch_text_urllib_bad_returncode(tmpdir, monkeypatch):
@ -414,8 +416,9 @@ def _read_from_url(*args, **kwargs):
with spack.config.override("config:url_fetch_method", "urllib"): with spack.config.override("config:url_fetch_method", "urllib"):
with pytest.raises(web_util.WebError, match="failed with error code"): with pytest.raises(web_util.WebError, match="failed with error code"):
web_util.fetch_url_text("https://github.com/", web_util.fetch_url_text(
fetch_method=spack.config.get('config:url_fetch_method')) "https://github.com/", fetch_method=spack.config.get("config:url_fetch_method")
)
def test_url_fetch_text_urllib_web_error(tmpdir, monkeypatch): def test_url_fetch_text_urllib_web_error(tmpdir, monkeypatch):
@ -426,5 +429,6 @@ def _raise_web_error(*args, **kwargs):
with spack.config.override("config:url_fetch_method", "urllib"): with spack.config.override("config:url_fetch_method", "urllib"):
with pytest.raises(web_util.WebError, match="fetch failed to verify"): with pytest.raises(web_util.WebError, match="fetch failed to verify"):
web_util.fetch_url_text("https://github.com/", web_util.fetch_url_text(
fetch_method=spack.config.get('config:url_fetch_method')) "https://github.com/", fetch_method=spack.config.get("config:url_fetch_method")
)

View File

@ -79,7 +79,7 @@ def test_output_filtering(self, capfd, install_mockery, mutable_config):
# test filtering when padding is enabled # test filtering when padding is enabled
with spack.config.override("config:install_tree", {"padded_length": 256}): with spack.config.override("config:install_tree", {"padded_length": 256}):
# tty.msg with filtering on the first argument # tty.msg with filtering on the first argument
padding = spack.config.get('config:install_tree:padded_length', None) padding = spack.config.get("config:install_tree:padded_length", None)
with sup.filter_padding(padding=padding): with sup.filter_padding(padding=padding):
tty.msg("here is a long path: %s/with/a/suffix" % long_path) tty.msg("here is a long path: %s/with/a/suffix" % long_path)
out, err = capfd.readouterr() out, err = capfd.readouterr()

View File

@ -60,8 +60,9 @@ def executable(exe: str, args: List[str]) -> int:
return cmd.returncode return cmd.returncode
def editor(*args: str, exec_fn: Callable[[str, List[str]], int] = os.execv, def editor(
debug: bool = False) -> bool: *args: str, exec_fn: Callable[[str, List[str]], int] = os.execv, debug: bool = False
) -> bool:
"""Invoke the user's editor. """Invoke the user's editor.
This will try to execute the following, in order: This will try to execute the following, in order: