imports: automate missing imports (#46410)

This commit is contained in:
Harmen Stoppels 2024-09-17 07:45:59 +02:00 committed by GitHub
parent 930e711771
commit 673565aefe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
136 changed files with 383 additions and 170 deletions

View File

@ -51,7 +51,9 @@ def _search_duplicate_compilers(error_cls):
import llnl.util.lang
import spack.builder
import spack.config
import spack.fetch_strategy
import spack.patch
import spack.repo
import spack.spec

View File

@ -14,6 +14,7 @@
import spack.compilers
import spack.config
import spack.environment
import spack.modules
import spack.paths
import spack.platforms
import spack.repo

View File

@ -14,7 +14,9 @@
from llnl.util import tty
import spack.environment
import spack.spec
import spack.tengine
import spack.util.path
from ._common import _root_spec
from .config import root_path, spec_for_current_python, store_path

View File

@ -53,6 +53,7 @@
from llnl.util.tty.color import cescape, colorize
from llnl.util.tty.log import MultiProcessFd
import spack.build_systems._checks
import spack.build_systems.cmake
import spack.build_systems.meson
import spack.build_systems.python
@ -62,6 +63,7 @@
import spack.deptypes as dt
import spack.error
import spack.main
import spack.multimethod
import spack.package_base
import spack.paths
import spack.platforms
@ -73,9 +75,8 @@
import spack.util.executable
from spack import traverse
from spack.context import Context
from spack.error import NoHeadersError, NoLibrariesError
from spack.error import InstallError, NoHeadersError, NoLibrariesError
from spack.install_test import spack_install_test_log
from spack.installer import InstallError
from spack.util.cpus import determine_number_of_jobs
from spack.util.environment import (
SYSTEM_DIR_CASE_ENTRY,
@ -1135,7 +1136,7 @@ def _setup_pkg_and_run(
return_value = function(pkg, kwargs)
write_pipe.send(return_value)
except StopPhase as e:
except spack.error.StopPhase as e:
# Do not create a full ChildError from this, it's not an error
# it's a control statement.
write_pipe.send(e)
@ -1296,7 +1297,7 @@ def exitcode_msg(p):
p.join()
# If returns a StopPhase, raise it
if isinstance(child_result, StopPhase):
if isinstance(child_result, spack.error.StopPhase):
# do not print
raise child_result
@ -1505,17 +1506,6 @@ def _make_child_error(msg, module, name, traceback, log, log_type, context):
return ChildError(msg, module, name, traceback, log, log_type, context)
class StopPhase(spack.error.SpackError):
"""Pickle-able exception to control stopped builds."""
def __reduce__(self):
return _make_stop_phase, (self.message, self.long_message)
def _make_stop_phase(msg, long_msg):
return StopPhase(msg, long_msg)
def write_log_summary(out, log_type, log, last=None):
errors, warnings = parse_log_events(log)
nerr = len(errors)

View File

@ -8,7 +8,7 @@
import llnl.util.lang
import spack.builder
import spack.installer
import spack.error
import spack.relocate
import spack.spec
import spack.store
@ -34,7 +34,7 @@ def check_paths(path_list, filetype, predicate):
if not predicate(abs_path):
msg = "Install failed for {0}. No such {1} in prefix: {2}"
msg = msg.format(pkg.name, filetype, path)
raise spack.installer.InstallError(msg)
raise spack.error.InstallError(msg)
check_paths(pkg.sanity_check_is_file, "file", os.path.isfile)
check_paths(pkg.sanity_check_is_dir, "directory", os.path.isdir)
@ -42,7 +42,7 @@ def check_paths(path_list, filetype, predicate):
ignore_file = llnl.util.lang.match_predicate(spack.store.STORE.layout.hidden_file_regexes)
if all(map(ignore_file, os.listdir(pkg.prefix))):
msg = "Install failed for {0}. Nothing was installed!"
raise spack.installer.InstallError(msg.format(pkg.name))
raise spack.error.InstallError(msg.format(pkg.name))
def apply_macos_rpath_fixups(builder: spack.builder.Builder):

View File

@ -13,6 +13,7 @@
import spack.build_environment
import spack.builder
import spack.error
import spack.package_base
from spack.directives import build_system, conflicts, depends_on
from spack.multimethod import when
@ -248,7 +249,7 @@ def runs_ok(script_abs_path):
# An external gnuconfig may not not have a prefix.
if gnuconfig_dir is None:
raise spack.build_environment.InstallError(
raise spack.error.InstallError(
"Spack could not find substitutes for GNU config files because no "
"prefix is available for the `gnuconfig` package. Make sure you set a "
"prefix path instead of modules for external `gnuconfig`."
@ -268,7 +269,7 @@ def runs_ok(script_abs_path):
msg += (
" or the `gnuconfig` package prefix is misconfigured as" " an external package"
)
raise spack.build_environment.InstallError(msg)
raise spack.error.InstallError(msg)
# Filter working substitutes
candidates = [f for f in candidates if runs_ok(f)]
@ -293,9 +294,7 @@ def runs_ok(script_abs_path):
and set the prefix to the directory containing the `config.guess` and
`config.sub` files.
"""
raise spack.build_environment.InstallError(
msg.format(", ".join(to_be_found), self.name)
)
raise spack.error.InstallError(msg.format(", ".join(to_be_found), self.name))
# Copy the good files over the bad ones
for abs_path in to_be_patched:

View File

@ -15,6 +15,7 @@
import spack.build_environment
import spack.builder
import spack.deptypes as dt
import spack.error
import spack.package_base
from spack.directives import build_system, conflicts, depends_on, variant
from spack.multimethod import when
@ -344,7 +345,7 @@ def std_args(pkg, generator=None):
msg = "Invalid CMake generator: '{0}'\n".format(generator)
msg += "CMakePackage currently supports the following "
msg += "primary generators: '{0}'".format("', '".join(valid_primary_generators))
raise spack.package_base.InstallError(msg)
raise spack.error.InstallError(msg)
try:
build_type = pkg.spec.variants["build_type"].value

View File

@ -14,6 +14,7 @@
import spack.compiler
import spack.package_base
import spack.util.executable
# Local "type" for type hints
Path = Union[str, pathlib.Path]

View File

@ -22,9 +22,10 @@
install,
)
import spack.builder
import spack.error
from spack.build_environment import dso_suffix
from spack.package_base import InstallError
from spack.error import InstallError
from spack.util.environment import EnvironmentModifications
from spack.util.executable import Executable
from spack.util.prefix import Prefix

View File

@ -15,7 +15,7 @@
import spack.util.path
from spack.build_environment import dso_suffix
from spack.directives import conflicts, license, redistribute, variant
from spack.package_base import InstallError
from spack.error import InstallError
from spack.util.environment import EnvironmentModifications
from spack.util.executable import Executable

View File

@ -24,6 +24,8 @@
import spack.detection
import spack.multimethod
import spack.package_base
import spack.platforms
import spack.repo
import spack.spec
import spack.store
from spack.directives import build_system, depends_on, extends

View File

@ -10,7 +10,7 @@
from llnl.util import lang
import spack.build_environment
import spack.error
import spack.multimethod
#: Builder classes, as registered by the "builder" decorator
@ -461,15 +461,13 @@ def _on_phase_start(self, instance):
# If a phase has a matching stop_before_phase attribute,
# stop the installation process raising a StopPhase
if getattr(instance, "stop_before_phase", None) == self.name:
raise spack.build_environment.StopPhase(
"Stopping before '{0}' phase".format(self.name)
)
raise spack.error.StopPhase("Stopping before '{0}' phase".format(self.name))
def _on_phase_exit(self, instance):
# If a phase has a matching last_phase attribute,
# stop the installation process raising a StopPhase
if getattr(instance, "last_phase", None) == self.name:
raise spack.build_environment.StopPhase("Stopping at '{0}' phase".format(self.name))
raise spack.error.StopPhase("Stopping at '{0}' phase".format(self.name))
def copy(self):
return copy.deepcopy(self)

View File

@ -31,6 +31,7 @@
import spack
import spack.binary_distribution as bindist
import spack.concretize
import spack.config as cfg
import spack.environment as ev
import spack.main

View File

@ -17,7 +17,7 @@
from llnl.util.tty.colify import colify
from llnl.util.tty.color import colorize
import spack.config
import spack.config # breaks a cycle.
import spack.environment as ev
import spack.error
import spack.extensions

View File

@ -11,6 +11,7 @@
import llnl.util.tty.color as color
import spack.platforms
import spack.spec
description = "print architecture information about this machine"
section = "system"

View File

@ -20,6 +20,7 @@
import spack.spec
import spack.stage
import spack.util.path
import spack.util.spack_yaml
from spack.cmd.common import arguments
description = "manage bootstrap configuration"

View File

@ -4,6 +4,7 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import spack.cmd
import spack.spec
from spack.cmd.common import arguments
description = "change an existing spec in an environment"

View File

@ -11,6 +11,7 @@
import llnl.util.tty as tty
import spack.caches
import spack.cmd
import spack.config
import spack.stage
import spack.store

View File

@ -17,6 +17,7 @@
from llnl.util.tty.colify import colify
import spack.cmd
import spack.config
import spack.main
import spack.paths
import spack.platforms

View File

@ -9,6 +9,7 @@
import llnl.util.tty as tty
import spack.cmd
import spack.spec
display_args = {"long": True, "show_flags": False, "variants": False, "indent": 4}

View File

@ -13,7 +13,9 @@
import spack.config
import spack.environment as ev
import spack.error
import spack.schema.env
import spack.spec
import spack.store
import spack.util.spack_yaml as syaml
from spack.cmd.common import arguments
@ -254,7 +256,7 @@ def config_remove(args):
existing.pop(value, None)
else:
# This should be impossible to reach
raise spack.config.ConfigError("Config has nested non-dict values")
raise spack.error.ConfigError("Config has nested non-dict values")
spack.config.set(path, existing, scope)
@ -338,7 +340,7 @@ def _config_change(config_path, match_spec_str=None):
if not changed:
existing_requirements = spack.config.get(key_path)
if isinstance(existing_requirements, str):
raise spack.config.ConfigError(
raise spack.error.ConfigError(
"'config change' needs to append a requirement,"
" but existing require: config is not a list"
)

View File

@ -16,6 +16,8 @@
import spack
import spack.paths
import spack.platforms
import spack.spec
import spack.store
import spack.util.git
from spack.util.executable import which

View File

@ -8,7 +8,9 @@
import llnl.util.tty as tty
import spack.build_environment
import spack.cmd
import spack.cmd.common.arguments
import spack.config
import spack.repo
from spack.cmd.common import arguments

View File

@ -25,6 +25,7 @@
import spack.config
import spack.environment as ev
import spack.environment.depfile as depfile
import spack.environment.environment
import spack.environment.shell
import spack.tengine
from spack.cmd.common import arguments

View File

@ -18,6 +18,7 @@
import spack.cray_manifest as cray_manifest
import spack.detection
import spack.error
import spack.package_base
import spack.repo
import spack.spec
from spack.cmd.common import arguments

View File

@ -11,8 +11,10 @@
import llnl.util.tty.color as color
import spack.cmd as cmd
import spack.config
import spack.environment as ev
import spack.repo
import spack.spec
import spack.store
from spack.cmd.common import arguments
from spack.database import InstallStatuses

View File

@ -16,6 +16,7 @@
import spack.install_test
import spack.repo
import spack.spec
import spack.variant
import spack.version
from spack.cmd.common import arguments
from spack.package_base import preferred_version

View File

@ -13,7 +13,6 @@
from llnl.string import plural
from llnl.util import lang, tty
import spack.build_environment
import spack.cmd
import spack.config
import spack.environment as ev
@ -22,7 +21,7 @@
import spack.spec
import spack.store
from spack.cmd.common import arguments
from spack.error import SpackError
from spack.error import InstallError, SpackError
from spack.installer import PackageInstaller
description = "build and install packages"
@ -285,7 +284,7 @@ def require_user_confirmation_for_overwrite(concrete_specs, args):
tty.die("Reinstallation aborted.")
def _dump_log_on_error(e: spack.build_environment.InstallError):
def _dump_log_on_error(e: InstallError):
e.print_context()
assert e.pkg, "Expected InstallError to include the associated package"
if not os.path.exists(e.pkg.log_path):
@ -350,7 +349,7 @@ def reporter_factory(specs):
install_with_active_env(env, args, install_kwargs, reporter_factory)
else:
install_without_active_env(args, install_kwargs, reporter_factory)
except spack.build_environment.InstallError as e:
except InstallError as e:
if args.show_log_on_error:
_dump_log_on_error(e)
raise

View File

@ -6,6 +6,7 @@
import sys
import spack.cmd
import spack.cmd.common
import spack.environment as ev
import spack.store
import spack.user_environment as uenv

View File

@ -15,6 +15,7 @@
import spack.cmd
import spack.config
import spack.error
import spack.modules
import spack.modules.common
import spack.repo
@ -124,13 +125,13 @@ def check_module_set_name(name):
names = [k for k in modules if k != "prefix_inspections"]
if not names:
raise spack.config.ConfigError(
raise spack.error.ConfigError(
f"Module set configuration is missing. Cannot use module set '{name}'"
)
pretty_names = "', '".join(names)
raise spack.config.ConfigError(
raise spack.error.ConfigError(
f"Cannot use invalid module set '{name}'.",
f"Valid module set names are: '{pretty_names}'.",
)

View File

@ -78,8 +78,8 @@ def python(parser, args, unknown_args):
# Run user choice of interpreter
if args.python_interpreter == "ipython":
return spack.cmd.python.ipython_interpreter(args)
return spack.cmd.python.python_interpreter(args)
return ipython_interpreter(args)
return python_interpreter(args)
def ipython_interpreter(args):

View File

@ -12,10 +12,12 @@
import spack
import spack.cmd
import spack.cmd.common.arguments
import spack.config
import spack.environment
import spack.hash_types as ht
import spack.solver.asp as asp
import spack.spec
from spack.cmd.common import arguments
description = "concretize a specs using an ASP solver"

View File

@ -14,6 +14,7 @@
import spack.hash_types as ht
import spack.spec
import spack.store
import spack.traverse
from spack.cmd.common import arguments
description = "show what would be installed, given a spec"

View File

@ -9,6 +9,7 @@
import llnl.util.tty as tty
import llnl.util.tty.colify as colify
import spack.environment
import spack.repo
import spack.tag

View File

@ -15,10 +15,12 @@
from llnl.util.tty import colify
import spack.cmd
import spack.config
import spack.environment as ev
import spack.install_test
import spack.repo
import spack.report
import spack.store
from spack.cmd.common import arguments
description = "run spack's tests for an install"

View File

@ -10,6 +10,7 @@
from llnl.util.filesystem import working_dir
import spack
import spack.cmd
import spack.config
import spack.paths
import spack.util.git

View File

@ -6,6 +6,7 @@
import llnl.util.tty as tty
import spack.cmd
import spack.config
from spack.cmd.common import arguments
description = "remove specs from an environment"

View File

@ -10,6 +10,8 @@
import re
import sys
import spack.extensions
try:
import pytest
except ImportError:

View File

@ -7,7 +7,9 @@
import sys
import spack.cmd
import spack.cmd.common
import spack.error
import spack.store
import spack.user_environment as uenv
from spack.cmd.common import arguments

View File

@ -6,6 +6,7 @@
import llnl.util.tty as tty
import spack.cmd
import spack.environment as ev
import spack.store
import spack.verify

View File

@ -39,6 +39,7 @@
from llnl.util import filesystem, lang, tty
import spack.error
import spack.paths
import spack.platforms
import spack.schema
@ -48,17 +49,21 @@
import spack.schema.compilers
import spack.schema.concretizer
import spack.schema.config
import spack.schema.definitions
import spack.schema.develop
import spack.schema.env
import spack.schema.mirrors
import spack.schema.modules
import spack.schema.packages
import spack.schema.repos
import spack.schema.upstreams
import spack.schema.view
import spack.spec
# Hacked yaml for configuration files preserves line numbers.
import spack.util.spack_yaml as syaml
import spack.util.web as web_util
from spack.error import SpackError
from spack.error import SpecSyntaxError
from spack.util.cpus import cpus_available
#: Dict from section names -> schema for that section
@ -165,7 +170,7 @@ def get_section(self, section: str) -> Optional[YamlConfigDict]:
def _write_section(self, section: str) -> None:
if not self.writable:
raise ConfigError(f"Cannot write to immutable scope {self}")
raise spack.error.ConfigError(f"Cannot write to immutable scope {self}")
filename = self.get_section_filename(section)
data = self.get_section(section)
@ -277,7 +282,7 @@ def get_section(self, section: str) -> Optional[YamlConfigDict]:
def _write_section(self, section: str) -> None:
if not self.writable:
raise ConfigError(f"Cannot write to immutable scope {self}")
raise spack.error.ConfigError(f"Cannot write to immutable scope {self}")
data_to_write: Optional[YamlConfigDict] = self._raw_data
# If there is no existing data, this section SingleFileScope has never
@ -705,7 +710,7 @@ def print_section(self, section: str, blame: bool = False, *, scope=None) -> Non
data[section] = self.get_config(section, scope=scope)
syaml.dump_config(data, stream=sys.stdout, default_flow_style=False, blame=blame)
except (syaml.SpackYAMLError, OSError) as e:
raise ConfigError(f"cannot read '{section}' configuration") from e
raise spack.error.ConfigError(f"cannot read '{section}' configuration") from e
@contextlib.contextmanager
@ -807,7 +812,7 @@ def _add_command_line_scopes(
_add_platform_scope(cfg, name, path, writable=False)
continue
else:
raise ConfigError(f"Invalid configuration scope: {path}")
raise spack.error.ConfigError(f"Invalid configuration scope: {path}")
for scope in manifest.env_config_scopes:
scope.name = f"{name}:{scope.name}"
@ -1019,7 +1024,7 @@ def change_or_add(
if found:
update_fn(section)
spack.config.set(section_name, section, scope=scope)
CONFIG.set(section_name, section, scope=scope)
return
# If no scope meets the criteria specified by ``find_fn``,
@ -1032,14 +1037,14 @@ def change_or_add(
break
if found:
spack.config.set(section_name, section, scope=scope)
CONFIG.set(section_name, section, scope=scope)
return
# If no scopes define any config for the named section, then
# modify the highest-priority scope.
scope, section = configs_by_section[0]
update_fn(section)
spack.config.set(section_name, section, scope=scope)
CONFIG.set(section_name, section, scope=scope)
def update_all(section_name: str, change_fn: Callable[[str], bool]) -> None:
@ -1051,7 +1056,7 @@ def update_all(section_name: str, change_fn: Callable[[str], bool]) -> None:
for scope, section in configs_by_section:
modified = change_fn(section)
if modified:
spack.config.set(section_name, section, scope=scope)
CONFIG.set(section_name, section, scope=scope)
def _validate_section_name(section: str) -> None:
@ -1225,7 +1230,7 @@ def get_valid_type(path):
return types[schema_type]()
else:
return type(None)
raise ConfigError(f"Cannot determine valid type for path '{path}'.")
raise spack.error.ConfigError(f"Cannot determine valid type for path '{path}'.")
def remove_yaml(dest, source):
@ -1268,7 +1273,7 @@ def they_are(t):
unmerge = sk in dest
old_dest_value = dest.pop(sk, None)
if unmerge and not spack.config._override(sk):
if unmerge and not _override(sk):
dest[sk] = remove_yaml(old_dest_value, sv)
return dest
@ -1718,27 +1723,23 @@ def parse_spec_from_yaml_string(string: str) -> "spack.spec.Spec":
try:
spec = spack.spec.Spec(string)
return spec
except spack.parser.SpecSyntaxError as e:
mark = spack.config.get_mark_from_yaml_data(string)
except SpecSyntaxError as e:
mark = get_mark_from_yaml_data(string)
if mark:
msg = f"{mark.name}:{mark.line + 1}: {str(e)}"
raise spack.parser.SpecSyntaxError(msg) from e
raise SpecSyntaxError(msg) from e
raise e
class ConfigError(SpackError):
"""Superclass for all Spack config related errors."""
class ConfigSectionError(ConfigError):
class ConfigSectionError(spack.error.ConfigError):
"""Error for referring to a bad config section name in a configuration."""
class ConfigFileError(ConfigError):
class ConfigFileError(spack.error.ConfigError):
"""Issue reading or accessing a configuration file."""
class ConfigFormatError(ConfigError):
class ConfigFormatError(spack.error.ConfigError):
"""Raised when a configuration format does not match its schema."""
def __init__(

View File

@ -25,8 +25,10 @@
import llnl.util.tty
import spack.config
import spack.error
import spack.operating_systems.windows_os as winOs
import spack.spec
import spack.util.environment
import spack.util.spack_yaml
import spack.util.windows_registry

View File

@ -18,6 +18,7 @@
import llnl.util.lang
import llnl.util.tty
import spack.spec
import spack.util.elf as elf_utils
import spack.util.environment
import spack.util.environment as environment

View File

@ -16,7 +16,9 @@
import spack.config
import spack.hash_types as ht
import spack.projections
import spack.spec
import spack.store
import spack.util.spack_json as sjson
from spack.error import SpackError

View File

@ -30,13 +30,16 @@
import spack.concretize
import spack.config
import spack.deptypes as dt
import spack.environment
import spack.error
import spack.filesystem_view as fsv
import spack.hash_types as ht
import spack.paths
import spack.repo
import spack.schema.env
import spack.schema.merged
import spack.spec
import spack.spec_list
import spack.store
import spack.user_environment as uenv
import spack.util.cpus

View File

@ -144,3 +144,48 @@ class PatchDirectiveError(SpackError):
class PatchLookupError(NoSuchPatchError):
"""Raised when a patch file cannot be located from sha256."""
class SpecSyntaxError(Exception):
"""Base class for Spec syntax errors"""
class PackageError(SpackError):
"""Raised when something is wrong with a package definition."""
def __init__(self, message, long_msg=None):
super().__init__(message, long_msg)
class NoURLError(PackageError):
"""Raised when someone tries to build a URL for a package with no URLs."""
def __init__(self, cls):
super().__init__("Package %s has no version with a URL." % cls.__name__)
class InstallError(SpackError):
"""Raised when something goes wrong during install or uninstall.
The error can be annotated with a ``pkg`` attribute to allow the
caller to get the package for which the exception was raised.
"""
def __init__(self, message, long_msg=None, pkg=None):
super().__init__(message, long_msg)
self.pkg = pkg
class ConfigError(SpackError):
"""Superclass for all Spack config related errors."""
class StopPhase(SpackError):
"""Pickle-able exception to control stopped builds."""
def __reduce__(self):
return _make_stop_phase, (self.message, self.long_message)
def _make_stop_phase(msg, long_msg):
return StopPhase(msg, long_msg)

View File

@ -17,6 +17,7 @@
import llnl.util.lang
import spack.cmd
import spack.config
import spack.error
import spack.util.path

View File

@ -1541,7 +1541,7 @@ def _extrapolate(pkg, version):
"""Create a fetcher from an extrapolated URL for this version."""
try:
return URLFetchStrategy(url=pkg.url_for_version(version), fetch_options=pkg.fetch_options)
except spack.package_base.NoURLError:
except spack.error.NoURLError:
raise ExtrapolationError(
f"Can't extrapolate a URL for version {version} because "
f"package {pkg.name} defines no URLs"

View File

@ -46,6 +46,7 @@
import spack.repo
import spack.spec
import spack.tengine
import spack.traverse
def find(seq, predicate):

View File

@ -33,7 +33,7 @@
import spack.util.executable
import spack.util.path
import spack.util.spack_json as sjson
from spack.installer import InstallError
from spack.error import InstallError
from spack.spec import Spec
from spack.util.prefix import Prefix
@ -119,7 +119,7 @@ def cache_extra_test_sources(pkg: Pb, srcs: ListOrStringType):
location(s) under the install testing directory.
Raises:
spack.installer.InstallError: if any of the source paths are absolute
spack.error.InstallError: if any of the source paths are absolute
or do not exist
under the build stage
"""

View File

@ -889,7 +889,7 @@ def __init__(
# ensure priority queue invariants when tasks are "removed" from the
# queue.
if status == STATUS_REMOVED:
raise InstallError(
raise spack.error.InstallError(
f"Cannot create a build task for {self.pkg_id} with status '{status}'", pkg=pkg
)
@ -1160,7 +1160,7 @@ def _check_deps_status(self, request: BuildRequest) -> None:
if spack.store.STORE.failure_tracker.has_failed(dep):
action = "'spack install' the dependency"
msg = f"{dep_id} is marked as an install failure: {action}"
raise InstallError(err.format(request.pkg_id, msg), pkg=dep_pkg)
raise spack.error.InstallError(err.format(request.pkg_id, msg), pkg=dep_pkg)
# Attempt to get a read lock to ensure another process does not
# uninstall the dependency while the requested spec is being
@ -1168,7 +1168,7 @@ def _check_deps_status(self, request: BuildRequest) -> None:
ltype, lock = self._ensure_locked("read", dep_pkg)
if lock is None:
msg = f"{dep_id} is write locked by another process"
raise InstallError(err.format(request.pkg_id, msg), pkg=request.pkg)
raise spack.error.InstallError(err.format(request.pkg_id, msg), pkg=request.pkg)
# Flag external and upstream packages as being installed
if dep_pkg.spec.external or dep_pkg.spec.installed_upstream:
@ -1220,7 +1220,7 @@ def _prepare_for_install(self, task: BuildTask) -> None:
if not installed_in_db:
# Ensure there is no other installed spec with the same prefix dir
if spack.store.STORE.db.is_occupied_install_prefix(task.pkg.spec.prefix):
raise InstallError(
raise spack.error.InstallError(
f"Install prefix collision for {task.pkg_id}",
long_msg=f"Prefix directory {task.pkg.spec.prefix} already "
"used by another installed spec.",
@ -1488,7 +1488,9 @@ def _install_task(self, task: BuildTask, install_status: InstallStatus) -> None:
self._update_installed(task)
return
elif cache_only:
raise InstallError("No binary found when cache-only was specified", pkg=pkg)
raise spack.error.InstallError(
"No binary found when cache-only was specified", pkg=pkg
)
else:
tty.msg(f"No binary for {pkg_id} found: installing from source")
@ -1515,7 +1517,7 @@ def _install_task(self, task: BuildTask, install_status: InstallStatus) -> None:
# the database, so that we don't need to re-read from file.
spack.store.STORE.db.add(pkg.spec, explicit=explicit)
except spack.build_environment.StopPhase as e:
except spack.error.StopPhase as e:
# A StopPhase exception means that do_install was asked to
# stop early from clients, and is not an error at this point
pid = f"{self.pid}: " if tty.show_pid() else ""
@ -1848,7 +1850,7 @@ def install(self) -> None:
tty.warn(f"{pkg_id} does NOT actually have any uninstalled deps left")
dep_str = "dependencies" if task.priority > 1 else "dependency"
raise InstallError(
raise spack.error.InstallError(
f"Cannot proceed with {pkg_id}: {task.priority} uninstalled "
f"{dep_str}: {','.join(task.uninstalled_deps)}",
pkg=pkg,
@ -1870,7 +1872,7 @@ def install(self) -> None:
self._update_failed(task)
if self.fail_fast:
raise InstallError(fail_fast_err, pkg=pkg)
raise spack.error.InstallError(fail_fast_err, pkg=pkg)
continue
@ -1999,7 +2001,7 @@ def install(self) -> None:
)
# Terminate if requested to do so on the first failure.
if self.fail_fast:
raise InstallError(f"{fail_fast_err}: {str(exc)}", pkg=pkg)
raise spack.error.InstallError(f"{fail_fast_err}: {str(exc)}", pkg=pkg)
# Terminate when a single build request has failed, or summarize errors later.
if task.is_build_request:
@ -2051,7 +2053,7 @@ def install(self) -> None:
f"missing package ({ids[0]}) from {', '.join(ids)}"
)
raise InstallError(
raise spack.error.InstallError(
"Installation request failed. Refer to reported errors for failing package(s).",
pkg=pkg,
)
@ -2317,33 +2319,21 @@ def install(self):
raise e.inner_exception
class InstallError(spack.error.SpackError):
"""Raised when something goes wrong during install or uninstall.
The error can be annotated with a ``pkg`` attribute to allow the
caller to get the package for which the exception was raised.
"""
def __init__(self, message, long_msg=None, pkg=None):
super().__init__(message, long_msg)
self.pkg = pkg
class BadInstallPhase(InstallError):
class BadInstallPhase(spack.error.InstallError):
"""Raised for an install phase option is not allowed for a package."""
def __init__(self, pkg_name, phase):
super().__init__(f"'{phase}' is not a valid phase for package {pkg_name}")
class ExternalPackageError(InstallError):
class ExternalPackageError(spack.error.InstallError):
"""Raised by install() when a package is only for external use."""
class InstallLockError(InstallError):
class InstallLockError(spack.error.InstallError):
"""Raised during install when something goes wrong with package locking."""
class UpstreamPackageError(InstallError):
class UpstreamPackageError(spack.error.InstallError):
"""Raised during install when something goes wrong with an upstream
package."""

View File

@ -9,6 +9,8 @@
after the system path is set up.
"""
import argparse
# import spack.modules.common
import inspect
import io
import operator
@ -36,6 +38,7 @@
import spack.cmd
import spack.config
import spack.environment as ev
import spack.error
import spack.modules
import spack.paths
import spack.platforms
@ -44,6 +47,7 @@
import spack.store
import spack.util.debug
import spack.util.environment
import spack.util.lock
from spack.error import SpackError
#: names of profile statistics
@ -763,6 +767,8 @@ def print_setup_info(*info):
This is in ``main.py`` to make it fast; the setup scripts need to
invoke spack in login scripts, and it needs to be quick.
"""
import spack.modules.common
shell = "csh" if "csh" in info else "sh"
def shell_set(var, value):

View File

@ -29,6 +29,7 @@
import spack.config
import spack.error
import spack.fetch_strategy
import spack.mirror
import spack.oci.image
import spack.repo
import spack.spec

View File

@ -46,6 +46,7 @@
import spack.deptypes as dt
import spack.environment
import spack.error
import spack.modules
import spack.paths
import spack.projections as proj
import spack.repo

View File

@ -11,6 +11,8 @@
from os import chdir, environ, getcwd, makedirs, mkdir, remove, removedirs
from shutil import move, rmtree
from spack.error import InstallError
# Emulate some shell commands for convenience
env = environ
cd = chdir
@ -84,12 +86,7 @@
install_test_root,
test_part,
)
from spack.installer import (
ExternalPackageError,
InstallError,
InstallLockError,
UpstreamPackageError,
)
from spack.installer import ExternalPackageError, InstallLockError, UpstreamPackageError
from spack.mixins import filter_compiler_wrappers
from spack.multimethod import default_args, when
from spack.package_base import (

View File

@ -33,6 +33,8 @@
from llnl.util.lang import classproperty, memoized
from llnl.util.link_tree import LinkTree
import spack.build_environment
import spack.builder
import spack.compilers
import spack.config
import spack.dependency
@ -50,8 +52,10 @@
import spack.store
import spack.url
import spack.util.environment
import spack.util.executable
import spack.util.path
import spack.util.web
from spack.error import InstallError, NoURLError, PackageError
from spack.filesystem_view import YamlFilesystemView
from spack.install_test import (
PackageTest,
@ -61,7 +65,7 @@
cache_extra_test_sources,
install_test_root,
)
from spack.installer import InstallError, PackageInstaller
from spack.installer import PackageInstaller
from spack.solver.version_order import concretization_version_order
from spack.stage import DevelopStage, ResourceStage, Stage, StageComposite, compute_stage_name
from spack.util.executable import ProcessError, which
@ -2581,20 +2585,6 @@ def __init__(self, spec, dependents):
self.dependents = dependents
class PackageError(spack.error.SpackError):
"""Raised when something is wrong with a package definition."""
def __init__(self, message, long_msg=None):
super().__init__(message, long_msg)
class NoURLError(PackageError):
"""Raised when someone tries to build a URL for a package with no URLs."""
def __init__(self, cls):
super().__init__("Package %s has no version with a URL." % cls.__name__)
class InvalidPackageOpError(PackageError):
"""Raised when someone tries perform an invalid operation on a package."""

View File

@ -9,7 +9,7 @@
import spack.error
import spack.repo
import spack.spec
from spack.config import ConfigError
from spack.error import ConfigError
from spack.version import Version
_lesser_spec_types = {"compiler": spack.spec.CompilerSpec, "version": Version}

View File

@ -70,6 +70,7 @@
import spack.error
import spack.spec
import spack.version
from spack.error import SpecSyntaxError
IS_WINDOWS = sys.platform == "win32"
#: Valid name for specs and variants. Here we are not using
@ -600,10 +601,6 @@ def parse_one_or_raise(
return result
class SpecSyntaxError(Exception):
"""Base class for Spec syntax errors"""
class SpecTokenizationError(SpecSyntaxError):
"""Syntax error in a spec string"""

View File

@ -6,6 +6,7 @@
import itertools
import os
import re
import sys
from collections import OrderedDict
from typing import List, Optional
@ -17,7 +18,7 @@
from llnl.util.lang import memoized
from llnl.util.symlink import readlink, symlink
import spack.platforms
import spack.error
import spack.store
import spack.util.elf as elf
import spack.util.executable as executable
@ -25,8 +26,6 @@
from .relocate_text import BinaryFilePrefixReplacer, TextFilePrefixReplacer
is_macos = str(spack.platforms.real_host()) == "darwin"
class InstallRootStringError(spack.error.SpackError):
def __init__(self, file_path, root_path):
@ -49,7 +48,7 @@ def _patchelf() -> Optional[executable.Executable]:
"""Return the full path to the patchelf binary, if available, else None."""
import spack.bootstrap
if is_macos:
if sys.platform == "darwin":
return None
with spack.bootstrap.ensure_bootstrap_configuration():
@ -416,7 +415,7 @@ def relocate_macho_binaries(
# normalized paths
rel_to_orig = macho_make_paths_normal(orig_path_name, rpaths, deps, idpath)
# replace the relativized paths with normalized paths
if is_macos:
if sys.platform == "darwin":
modify_macho_object(path_name, rpaths, deps, idpath, rel_to_orig)
else:
modify_object_macholib(path_name, rel_to_orig)
@ -427,7 +426,7 @@ def relocate_macho_binaries(
rpaths, deps, idpath, old_layout_root, prefix_to_prefix
)
# replace the old paths with new paths
if is_macos:
if sys.platform == "darwin":
modify_macho_object(path_name, rpaths, deps, idpath, paths_to_paths)
else:
modify_object_macholib(path_name, paths_to_paths)
@ -438,7 +437,7 @@ def relocate_macho_binaries(
path_name, new_layout_root, rpaths, deps, idpath
)
# replace the new paths with relativized paths in the new prefix
if is_macos:
if sys.platform == "darwin":
modify_macho_object(path_name, rpaths, deps, idpath, paths_to_paths)
else:
modify_object_macholib(path_name, paths_to_paths)
@ -450,7 +449,7 @@ def relocate_macho_binaries(
rpaths, deps, idpath, old_layout_root, prefix_to_prefix
)
# replace the old paths with new paths
if is_macos:
if sys.platform == "darwin":
modify_macho_object(path_name, rpaths, deps, idpath, paths_to_paths)
else:
modify_object_macholib(path_name, paths_to_paths)
@ -572,7 +571,7 @@ def make_macho_binaries_relative(cur_path_names, orig_path_names, old_layout_roo
"""
Replace old RPATHs with paths relative to old_dir in binary files
"""
if not is_macos:
if not sys.platform == "darwin":
return
for cur_path, orig_path in zip(cur_path_names, orig_path_names):

View File

@ -39,6 +39,7 @@
import spack.error
import spack.patch
import spack.provider_index
import spack.repo
import spack.spec
import spack.tag
import spack.util.git
@ -1522,8 +1523,10 @@ def add_package(self, name, dependencies=None):
Both "dep_type" and "condition" can default to ``None`` in which case
``spack.dependency.default_deptype`` and ``spack.spec.Spec()`` are used.
"""
import spack.tengine # avoid circular import
dependencies = dependencies or []
context = {"cls_name": spack.util.naming.mod_to_class(name), "dependencies": dependencies}
context = {"cls_name": nm.mod_to_class(name), "dependencies": dependencies}
template = spack.tengine.make_environment().get_template("mock-repository/package.pyt")
text = template.render(context)
package_py = self.recipe_filename(name)

View File

@ -22,6 +22,8 @@
import spack
import spack.paths
import spack.platforms
import spack.spec
import spack.tengine
import spack.util.git
from spack.error import SpackError
from spack.util.crypto import checksum

View File

@ -14,6 +14,7 @@
import spack.binary_distribution as bindist
import spack.error
import spack.hooks
import spack.platforms
import spack.relocate as relocate
import spack.store

View File

@ -8,6 +8,8 @@
import llnl.util.lang
from spack.error import SpecSyntaxError
class DeprecationMessage(typing.NamedTuple):
message: str
@ -31,7 +33,7 @@ def _validate_spec(validator, is_spec, instance, schema):
for spec_str in instance:
try:
spack.parser.parse(spec_str)
except spack.parser.SpecSyntaxError as e:
except SpecSyntaxError as e:
yield jsonschema.ValidationError(str(e))
def _deprecated_properties(validator, deprecated, instance, schema):

View File

@ -11,6 +11,7 @@
from llnl.util.lang import union_dicts
import spack.config
import spack.schema.projections
#: Properties for inclusion in other schemas

View File

@ -11,6 +11,7 @@
from typing import Any, Dict
import spack.schema
import spack.schema.projections
projections_scheme = spack.schema.projections.properties["projections"]

View File

@ -27,7 +27,9 @@
import spack
import spack.binary_distribution
import spack.bootstrap.core
import spack.compilers
import spack.concretize
import spack.config
import spack.config as sc
import spack.deptypes as dt
@ -2166,7 +2168,7 @@ def define_package_versions_and_validate_preferences(
matches = [x for x in self.possible_versions[pkg_name] if x.satisfies(v)]
matches.sort(reverse=True)
if not matches:
raise spack.config.ConfigError(
raise spack.error.ConfigError(
f"Preference for version {v} does not match any known "
f"version of {pkg_name} (in its package.py or any external)"
)
@ -2796,7 +2798,7 @@ def validate_and_define_versions_from_requirements(
# not throw an error, which is just so that users know they need to change
# their config, instead of getting a hard to decipher concretization error.
if not any(x for x in self.possible_versions[name] if x.satisfies(versions)):
raise spack.config.ConfigError(
raise spack.error.ConfigError(
f"Version requirement {versions} on {pkg_name} for {name} "
f"cannot match any known version from package.py or externals"
)

View File

@ -2016,6 +2016,7 @@ def process_hash_bit_prefix(self, bits):
def _lookup_hash(self):
"""Lookup just one spec with an abstract hash, returning a spec from the the environment,
store, or finally, binary caches."""
import spack.binary_distribution
import spack.environment
active_env = spack.environment.active_environment()

View File

@ -33,6 +33,7 @@
import spack.error
import spack.paths
import spack.spec
import spack.store
import spack.util.path
#: default installation root, relative to the Spack install path

View File

@ -8,11 +8,14 @@
from collections.abc import Mapping
import spack.error
import spack.repo
import spack.util.spack_json as sjson
def _get_installed_package_names():
"""Returns names of packages installed in the active environment."""
import spack.environment
specs = spack.environment.installed_specs()
return [spec.name for spec in specs]

View File

@ -11,6 +11,7 @@
import spack.compiler
import spack.compilers
import spack.spec
import spack.util.executable
import spack.util.spack_yaml as syaml

View File

@ -27,11 +27,15 @@
import spack.binary_distribution as bindist
import spack.caches
import spack.compilers
import spack.config
import spack.fetch_strategy
import spack.hooks.sbang as sbang
import spack.main
import spack.mirror
import spack.paths
import spack.spec
import spack.stage
import spack.store
import spack.util.gpg
import spack.util.spack_yaml as syaml

View File

@ -9,6 +9,7 @@
import spack.bootstrap.config
import spack.bootstrap.core
import spack.compilers
import spack.config
import spack.environment
import spack.store
import spack.util.path

View File

@ -16,6 +16,7 @@
import spack.config
import spack.deptypes as dt
import spack.package_base
import spack.paths
import spack.spec
import spack.util.spack_yaml as syaml
from spack.build_environment import UseMode, _static_to_shared_library, dso_suffix

View File

@ -16,7 +16,10 @@
import spack.build_systems.autotools
import spack.build_systems.cmake
import spack.environment
import spack.error
import spack.paths
import spack.platforms
import spack.platforms.test
from spack.build_environment import ChildError, setup_package
from spack.spec import Spec
from spack.util.executable import which
@ -265,7 +268,7 @@ def test_cmake_std_args(self, default_mock_concretization):
def test_cmake_bad_generator(self, default_mock_concretization):
s = default_mock_concretization("cmake-client")
with pytest.raises(spack.package_base.InstallError):
with pytest.raises(spack.error.InstallError):
spack.build_systems.cmake.CMakeBuilder.std_args(
s.package, generator="Yellow Sticky Notes"
)

View File

@ -8,7 +8,10 @@
from llnl.util.filesystem import touch
import spack.builder
import spack.paths
import spack.repo
import spack.spec
@pytest.fixture()

View File

@ -5,6 +5,7 @@
import pytest
import spack.error
import spack.installer as inst
import spack.repo
import spack.spec
@ -25,7 +26,7 @@ def test_build_task_errors(install_mockery):
inst.BuildTask(spec.package, None, False, 0, 0, 0, set())
request = inst.BuildRequest(spec.package, {})
with pytest.raises(inst.InstallError, match="Cannot create a build task"):
with pytest.raises(spack.error.InstallError, match="Cannot create a build task"):
inst.BuildTask(spec.package, request, False, 0, 0, inst.STATUS_REMOVED, set())

View File

@ -13,6 +13,7 @@
import spack.environment as ev
import spack.error
import spack.paths as spack_paths
import spack.spec
import spack.util.git

View File

@ -15,6 +15,7 @@
import spack.environment as ev
import spack.main
import spack.mirror
import spack.spec
_bootstrap = spack.main.SpackCommand("bootstrap")

View File

@ -8,8 +8,8 @@
import pytest
import spack.cmd.checksum
import spack.error
import spack.package_base
import spack.parser
import spack.repo
import spack.spec
import spack.stage
@ -304,7 +304,7 @@ def test_checksum_deprecated_version(mock_packages, can_fetch_versions):
def test_checksum_url(mock_packages, config):
pkg_cls = spack.repo.PATH.get_pkg_class("zlib")
with pytest.raises(spack.parser.SpecSyntaxError):
with pytest.raises(spack.error.SpecSyntaxError):
spack_checksum(f"{pkg_cls.url}")

View File

@ -14,6 +14,7 @@
import spack.environment as ev
import spack.main
import spack.package_base
import spack.spec
import spack.stage
import spack.store

View File

@ -10,6 +10,7 @@
import pytest
import spack.cmd
import spack.cmd.commands
import spack.main
import spack.paths
from spack.cmd.commands import _dest_to_fish_complete, _positional_to_subroutine

View File

@ -10,6 +10,7 @@
import spack.cmd.compiler
import spack.compilers
import spack.config
import spack.main
import spack.spec
import spack.util.pattern

View File

@ -9,6 +9,7 @@
import pytest
import spack.cmd.create
import spack.url
from spack.main import SpackCommand
from spack.url import UndetectableNameError
from spack.util.executable import which

View File

@ -11,6 +11,7 @@
import spack
import spack.platforms
import spack.spec
from spack.main import SpackCommand
from spack.util.executable import which

View File

@ -5,6 +5,7 @@
import pytest
import spack.spec
import spack.store
from spack.database import InstallStatuses
from spack.main import SpackCommand

View File

@ -11,6 +11,7 @@
import spack.environment as ev
import spack.error
import spack.repo
import spack.spec
import spack.store
from spack.main import SpackCommand

View File

@ -11,7 +11,11 @@
import spack.config
import spack.environment as ev
import spack.package_base
import spack.spec
import spack.stage
import spack.util.git
import spack.util.path
from spack.main import SpackCommand
add = SpackCommand("add")

View File

@ -7,6 +7,8 @@
import spack.cmd.diff
import spack.main
import spack.repo
import spack.spec
import spack.util.spack_json as sjson
from spack.test.conftest import create_test_repo

View File

@ -24,11 +24,17 @@
import spack.environment.environment
import spack.environment.shell
import spack.error
import spack.main
import spack.modules
import spack.modules.tcl
import spack.package_base
import spack.paths
import spack.repo
import spack.solver.asp
import spack.spec
import spack.stage
import spack.store
import spack.util.environment
import spack.util.spack_json as sjson
import spack.util.spack_yaml
from spack.cmd.env import _env_create
@ -1160,7 +1166,7 @@ def test_config_change_new(mutable_mock_env_path, tmp_path, mock_packages, mutab
)
with ev.Environment(tmp_path):
assert spack.spec.Spec("mpich").concretized().satisfies("@3.0.3")
with pytest.raises(spack.config.ConfigError, match="not a list"):
with pytest.raises(spack.error.ConfigError, match="not a list"):
config("change", "packages:mpich:require:~debug")
@ -1188,7 +1194,7 @@ def test_env_with_included_config_missing_file(tmpdir, mutable_empty_config):
with spack_yaml.open("w") as f:
f.write("spack:\n include:\n - {0}\n".format(missing_file.strpath))
with pytest.raises(spack.config.ConfigError, match="missing include path"):
with pytest.raises(spack.error.ConfigError, match="missing include path"):
ev.Environment(tmpdir.strpath)

View File

@ -12,6 +12,8 @@
import spack
import spack.cmd.external
import spack.config
import spack.cray_manifest
import spack.detection
import spack.detection.path
import spack.repo

View File

@ -14,6 +14,7 @@
import spack.cmd as cmd
import spack.cmd.find
import spack.environment as ev
import spack.store
import spack.user_environment as uenv
from spack.main import SpackCommand
from spack.spec import Spec

View File

@ -17,16 +17,18 @@
import llnl.util.filesystem as fs
import llnl.util.tty as tty
import spack.build_environment
import spack.cmd.common.arguments
import spack.cmd.install
import spack.config
import spack.environment as ev
import spack.error
import spack.hash_types as ht
import spack.installer
import spack.package_base
import spack.store
from spack.error import SpackError
from spack.error import SpackError, SpecSyntaxError
from spack.main import SpackCommand
from spack.parser import SpecSyntaxError
from spack.spec import Spec
install = SpackCommand("install")
@ -420,7 +422,7 @@ def test_junit_output_with_failures(tmpdir, exc_typename, msg):
@pytest.mark.parametrize(
"exc_typename,expected_exc,msg",
[
("RuntimeError", spack.installer.InstallError, "something weird happened"),
("RuntimeError", spack.error.InstallError, "something weird happened"),
("KeyboardInterrupt", KeyboardInterrupt, "Ctrl-C strikes again"),
],
)
@ -704,7 +706,7 @@ def test_install_only_package(tmpdir, mock_fetch, install_mockery, capfd):
with capfd.disabled():
try:
install("--only", "package", "dependent-install")
except spack.installer.InstallError as e:
except spack.error.InstallError as e:
msg = str(e)
assert "Cannot proceed with dependent-install" in msg

View File

@ -11,6 +11,8 @@
from llnl.util.filesystem import mkdirp, working_dir
import spack
import spack.cmd
import spack.fetch_strategy
from spack.version import ver

View File

@ -7,6 +7,7 @@
import sys
from textwrap import dedent
import spack.paths
import spack.repo
from spack.main import SpackCommand

View File

@ -11,6 +11,7 @@
import spack.environment as ev
import spack.paths
import spack.spec
import spack.stage
from spack.main import SpackCommand, SpackCommandError

View File

@ -13,6 +13,9 @@
import pytest
import spack
import spack.cmd.logs
import spack.main
import spack.spec
from spack.main import SpackCommand
logs = SpackCommand("logs")

View File

@ -10,8 +10,11 @@
import spack.cmd.mirror
import spack.config
import spack.environment as ev
import spack.error
import spack.mirror
import spack.spec
import spack.util.url as url_util
import spack.version
from spack.main import SpackCommand, SpackCommandError
mirror = SpackCommand("mirror")

View File

@ -11,6 +11,8 @@
import spack.config
import spack.main
import spack.modules
import spack.modules.lmod
import spack.repo
import spack.spec
import spack.store

View File

@ -12,6 +12,7 @@
import spack.cmd.pkg
import spack.main
import spack.paths
import spack.repo
import spack.util.file_cache

View File

@ -9,7 +9,6 @@
import spack.environment as ev
import spack.error
import spack.parser
import spack.spec
import spack.store
from spack.main import SpackCommand, SpackCommandError
@ -142,7 +141,7 @@ def test_spec_returncode():
def test_spec_parse_error():
with pytest.raises(spack.parser.SpecSyntaxError) as e:
with pytest.raises(spack.error.SpecSyntaxError) as e:
spec("1.15:")
# make sure the error is formatted properly

Some files were not shown because too many files have changed in this diff Show More