Remove dead code (#43114)
* Remove dead code in spack * Remove dead code in llnl
This commit is contained in:
parent
d6421a69eb
commit
1e47ccb83a
@ -42,11 +42,6 @@ def convert_to_posix_path(path: str) -> str:
|
|||||||
return format_os_path(path, mode=Path.unix)
|
return format_os_path(path, mode=Path.unix)
|
||||||
|
|
||||||
|
|
||||||
def convert_to_windows_path(path: str) -> str:
|
|
||||||
"""Converts the input path to Windows style."""
|
|
||||||
return format_os_path(path, mode=Path.windows)
|
|
||||||
|
|
||||||
|
|
||||||
def convert_to_platform_path(path: str) -> str:
|
def convert_to_platform_path(path: str) -> str:
|
||||||
"""Converts the input path to the current platform's native style."""
|
"""Converts the input path to the current platform's native style."""
|
||||||
return format_os_path(path, mode=Path.platform_path)
|
return format_os_path(path, mode=Path.platform_path)
|
||||||
|
@ -237,16 +237,6 @@ def _get_mime_type():
|
|||||||
return file_command("-b", "-h", "--mime-type")
|
return file_command("-b", "-h", "--mime-type")
|
||||||
|
|
||||||
|
|
||||||
@memoized
|
|
||||||
def _get_mime_type_compressed():
|
|
||||||
"""Same as _get_mime_type but attempts to check for
|
|
||||||
compression first
|
|
||||||
"""
|
|
||||||
mime_uncompressed = _get_mime_type()
|
|
||||||
mime_uncompressed.add_default_arg("-Z")
|
|
||||||
return mime_uncompressed
|
|
||||||
|
|
||||||
|
|
||||||
def mime_type(filename):
|
def mime_type(filename):
|
||||||
"""Returns the mime type and subtype of a file.
|
"""Returns the mime type and subtype of a file.
|
||||||
|
|
||||||
@ -262,21 +252,6 @@ def mime_type(filename):
|
|||||||
return type, subtype
|
return type, subtype
|
||||||
|
|
||||||
|
|
||||||
def compressed_mime_type(filename):
|
|
||||||
"""Same as mime_type but checks for type that has been compressed
|
|
||||||
|
|
||||||
Args:
|
|
||||||
filename (str): file to be analyzed
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Tuple containing the MIME type and subtype
|
|
||||||
"""
|
|
||||||
output = _get_mime_type_compressed()(filename, output=str, error=str).strip()
|
|
||||||
tty.debug("==> " + output)
|
|
||||||
type, _, subtype = output.partition("/")
|
|
||||||
return type, subtype
|
|
||||||
|
|
||||||
|
|
||||||
#: This generates the library filenames that may appear on any OS.
|
#: This generates the library filenames that may appear on any OS.
|
||||||
library_extensions = ["a", "la", "so", "tbd", "dylib"]
|
library_extensions = ["a", "la", "so", "tbd", "dylib"]
|
||||||
|
|
||||||
@ -308,13 +283,6 @@ def paths_containing_libs(paths, library_names):
|
|||||||
return rpaths_to_include
|
return rpaths_to_include
|
||||||
|
|
||||||
|
|
||||||
@system_path_filter
|
|
||||||
def same_path(path1, path2):
|
|
||||||
norm1 = os.path.abspath(path1).rstrip(os.path.sep)
|
|
||||||
norm2 = os.path.abspath(path2).rstrip(os.path.sep)
|
|
||||||
return norm1 == norm2
|
|
||||||
|
|
||||||
|
|
||||||
def filter_file(
|
def filter_file(
|
||||||
regex: str,
|
regex: str,
|
||||||
repl: Union[str, Callable[[Match], str]],
|
repl: Union[str, Callable[[Match], str]],
|
||||||
@ -909,17 +877,6 @@ def is_exe(path):
|
|||||||
return os.path.isfile(path) and os.access(path, os.X_OK)
|
return os.path.isfile(path) and os.access(path, os.X_OK)
|
||||||
|
|
||||||
|
|
||||||
@system_path_filter
|
|
||||||
def get_filetype(path_name):
|
|
||||||
"""
|
|
||||||
Return the output of file path_name as a string to identify file type.
|
|
||||||
"""
|
|
||||||
file = Executable("file")
|
|
||||||
file.add_default_env("LC_ALL", "C")
|
|
||||||
output = file("-b", "-h", "%s" % path_name, output=str, error=str)
|
|
||||||
return output.strip()
|
|
||||||
|
|
||||||
|
|
||||||
def has_shebang(path):
|
def has_shebang(path):
|
||||||
"""Returns whether a path has a shebang line. Returns False if the file cannot be opened."""
|
"""Returns whether a path has a shebang line. Returns False if the file cannot be opened."""
|
||||||
try:
|
try:
|
||||||
@ -1169,20 +1126,6 @@ def write_tmp_and_move(filename):
|
|||||||
shutil.move(tmp, filename)
|
shutil.move(tmp, filename)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
@system_path_filter
|
|
||||||
def open_if_filename(str_or_file, mode="r"):
|
|
||||||
"""Takes either a path or a file object, and opens it if it is a path.
|
|
||||||
|
|
||||||
If it's a file object, just yields the file object.
|
|
||||||
"""
|
|
||||||
if isinstance(str_or_file, str):
|
|
||||||
with open(str_or_file, mode) as f:
|
|
||||||
yield f
|
|
||||||
else:
|
|
||||||
yield str_or_file
|
|
||||||
|
|
||||||
|
|
||||||
@system_path_filter
|
@system_path_filter
|
||||||
def touch(path):
|
def touch(path):
|
||||||
"""Creates an empty file at the specified path."""
|
"""Creates an empty file at the specified path."""
|
||||||
@ -1295,19 +1238,6 @@ def temp_cwd():
|
|||||||
shutil.rmtree(tmp_dir, **kwargs)
|
shutil.rmtree(tmp_dir, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
@system_path_filter
|
|
||||||
def temp_rename(orig_path, temp_path):
|
|
||||||
same_path = os.path.realpath(orig_path) == os.path.realpath(temp_path)
|
|
||||||
if not same_path:
|
|
||||||
shutil.move(orig_path, temp_path)
|
|
||||||
try:
|
|
||||||
yield
|
|
||||||
finally:
|
|
||||||
if not same_path:
|
|
||||||
shutil.move(temp_path, orig_path)
|
|
||||||
|
|
||||||
|
|
||||||
@system_path_filter
|
@system_path_filter
|
||||||
def can_access(file_name):
|
def can_access(file_name):
|
||||||
"""True if we have read/write access to the file."""
|
"""True if we have read/write access to the file."""
|
||||||
|
@ -98,36 +98,6 @@ def caller_locals():
|
|||||||
del stack
|
del stack
|
||||||
|
|
||||||
|
|
||||||
def get_calling_module_name():
|
|
||||||
"""Make sure that the caller is a class definition, and return the
|
|
||||||
enclosing module's name.
|
|
||||||
"""
|
|
||||||
# Passing zero here skips line context for speed.
|
|
||||||
stack = inspect.stack(0)
|
|
||||||
try:
|
|
||||||
# Make sure locals contain __module__
|
|
||||||
caller_locals = stack[2][0].f_locals
|
|
||||||
finally:
|
|
||||||
del stack
|
|
||||||
|
|
||||||
if "__module__" not in caller_locals:
|
|
||||||
raise RuntimeError(
|
|
||||||
"Must invoke get_calling_module_name() " "from inside a class definition!"
|
|
||||||
)
|
|
||||||
|
|
||||||
module_name = caller_locals["__module__"]
|
|
||||||
base_name = module_name.split(".")[-1]
|
|
||||||
return base_name
|
|
||||||
|
|
||||||
|
|
||||||
def attr_required(obj, attr_name):
|
|
||||||
"""Ensure that a class has a required attribute."""
|
|
||||||
if not hasattr(obj, attr_name):
|
|
||||||
raise RequiredAttributeError(
|
|
||||||
"No required attribute '%s' in class '%s'" % (attr_name, obj.__class__.__name__)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def attr_setdefault(obj, name, value):
|
def attr_setdefault(obj, name, value):
|
||||||
"""Like dict.setdefault, but for objects."""
|
"""Like dict.setdefault, but for objects."""
|
||||||
if not hasattr(obj, name):
|
if not hasattr(obj, name):
|
||||||
@ -513,42 +483,6 @@ def copy(self):
|
|||||||
return clone
|
return clone
|
||||||
|
|
||||||
|
|
||||||
def in_function(function_name):
|
|
||||||
"""True if the caller was called from some function with
|
|
||||||
the supplied Name, False otherwise."""
|
|
||||||
stack = inspect.stack()
|
|
||||||
try:
|
|
||||||
for elt in stack[2:]:
|
|
||||||
if elt[3] == function_name:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
finally:
|
|
||||||
del stack
|
|
||||||
|
|
||||||
|
|
||||||
def check_kwargs(kwargs, fun):
|
|
||||||
"""Helper for making functions with kwargs. Checks whether the kwargs
|
|
||||||
are empty after all of them have been popped off. If they're
|
|
||||||
not, raises an error describing which kwargs are invalid.
|
|
||||||
|
|
||||||
Example::
|
|
||||||
|
|
||||||
def foo(self, **kwargs):
|
|
||||||
x = kwargs.pop('x', None)
|
|
||||||
y = kwargs.pop('y', None)
|
|
||||||
z = kwargs.pop('z', None)
|
|
||||||
check_kwargs(kwargs, self.foo)
|
|
||||||
|
|
||||||
# This raises a TypeError:
|
|
||||||
foo(w='bad kwarg')
|
|
||||||
"""
|
|
||||||
if kwargs:
|
|
||||||
raise TypeError(
|
|
||||||
"'%s' is an invalid keyword argument for function %s()."
|
|
||||||
% (next(iter(kwargs)), fun.__name__)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def match_predicate(*args):
|
def match_predicate(*args):
|
||||||
"""Utility function for making string matching predicates.
|
"""Utility function for making string matching predicates.
|
||||||
|
|
||||||
@ -764,11 +698,6 @@ def pretty_seconds(seconds):
|
|||||||
return pretty_seconds_formatter(seconds)(seconds)
|
return pretty_seconds_formatter(seconds)(seconds)
|
||||||
|
|
||||||
|
|
||||||
class RequiredAttributeError(ValueError):
|
|
||||||
def __init__(self, message):
|
|
||||||
super().__init__(message)
|
|
||||||
|
|
||||||
|
|
||||||
class ObjectWrapper:
|
class ObjectWrapper:
|
||||||
"""Base class that wraps an object. Derived classes can add new behavior
|
"""Base class that wraps an object. Derived classes can add new behavior
|
||||||
while staying undercover.
|
while staying undercover.
|
||||||
@ -935,25 +864,6 @@ def uniq(sequence):
|
|||||||
return uniq_list
|
return uniq_list
|
||||||
|
|
||||||
|
|
||||||
def star(func):
|
|
||||||
"""Unpacks arguments for use with Multiprocessing mapping functions"""
|
|
||||||
|
|
||||||
def _wrapper(args):
|
|
||||||
return func(*args)
|
|
||||||
|
|
||||||
return _wrapper
|
|
||||||
|
|
||||||
|
|
||||||
class Devnull:
|
|
||||||
"""Null stream with less overhead than ``os.devnull``.
|
|
||||||
|
|
||||||
See https://stackoverflow.com/a/2929954.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def write(self, *_):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def elide_list(line_list, max_num=10):
|
def elide_list(line_list, max_num=10):
|
||||||
"""Takes a long list and limits it to a smaller number of elements,
|
"""Takes a long list and limits it to a smaller number of elements,
|
||||||
replacing intervening elements with '...'. For example::
|
replacing intervening elements with '...'. For example::
|
||||||
|
@ -815,10 +815,6 @@ def __init__(self, path):
|
|||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
class LockLimitError(LockError):
|
|
||||||
"""Raised when exceed maximum attempts to acquire a lock."""
|
|
||||||
|
|
||||||
|
|
||||||
class LockTimeoutError(LockError):
|
class LockTimeoutError(LockError):
|
||||||
"""Raised when an attempt to acquire a lock times out."""
|
"""Raised when an attempt to acquire a lock times out."""
|
||||||
|
|
||||||
|
@ -44,10 +44,6 @@ def is_debug(level=1):
|
|||||||
return _debug >= level
|
return _debug >= level
|
||||||
|
|
||||||
|
|
||||||
def is_stacktrace():
|
|
||||||
return _stacktrace
|
|
||||||
|
|
||||||
|
|
||||||
def set_debug(level=0):
|
def set_debug(level=0):
|
||||||
global _debug
|
global _debug
|
||||||
assert level >= 0, "Debug level must be a positive value"
|
assert level >= 0, "Debug level must be a positive value"
|
||||||
@ -252,37 +248,6 @@ def die(message, *args, **kwargs) -> NoReturn:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def get_number(prompt, **kwargs):
|
|
||||||
default = kwargs.get("default", None)
|
|
||||||
abort = kwargs.get("abort", None)
|
|
||||||
|
|
||||||
if default is not None and abort is not None:
|
|
||||||
prompt += " (default is %s, %s to abort) " % (default, abort)
|
|
||||||
elif default is not None:
|
|
||||||
prompt += " (default is %s) " % default
|
|
||||||
elif abort is not None:
|
|
||||||
prompt += " (%s to abort) " % abort
|
|
||||||
|
|
||||||
number = None
|
|
||||||
while number is None:
|
|
||||||
msg(prompt, newline=False)
|
|
||||||
ans = input()
|
|
||||||
if ans == str(abort):
|
|
||||||
return None
|
|
||||||
|
|
||||||
if ans:
|
|
||||||
try:
|
|
||||||
number = int(ans)
|
|
||||||
if number < 1:
|
|
||||||
msg("Please enter a valid number.")
|
|
||||||
number = None
|
|
||||||
except ValueError:
|
|
||||||
msg("Please enter a valid number.")
|
|
||||||
elif default is not None:
|
|
||||||
number = default
|
|
||||||
return number
|
|
||||||
|
|
||||||
|
|
||||||
def get_yes_or_no(prompt, **kwargs):
|
def get_yes_or_no(prompt, **kwargs):
|
||||||
default_value = kwargs.get("default", None)
|
default_value = kwargs.get("default", None)
|
||||||
|
|
||||||
|
@ -625,18 +625,6 @@ def __init__(self, *args):
|
|||||||
else:
|
else:
|
||||||
raise TypeError("__init__ takes 1 or 2 arguments. (%d given)" % nargs)
|
raise TypeError("__init__ takes 1 or 2 arguments. (%d given)" % nargs)
|
||||||
|
|
||||||
def _add_versions(self, version_list):
|
|
||||||
# If it already has a non-trivial version list, this is an error
|
|
||||||
if self.versions and self.versions != vn.any_version:
|
|
||||||
# Note: This may be impossible to reach by the current parser
|
|
||||||
# Keeping it in case the implementation changes.
|
|
||||||
raise MultipleVersionError(
|
|
||||||
"A spec cannot contain multiple version signifiers. Use a version list instead."
|
|
||||||
)
|
|
||||||
self.versions = vn.VersionList()
|
|
||||||
for version in version_list:
|
|
||||||
self.versions.add(version)
|
|
||||||
|
|
||||||
def _autospec(self, compiler_spec_like):
|
def _autospec(self, compiler_spec_like):
|
||||||
if isinstance(compiler_spec_like, CompilerSpec):
|
if isinstance(compiler_spec_like, CompilerSpec):
|
||||||
return compiler_spec_like
|
return compiler_spec_like
|
||||||
@ -1544,20 +1532,6 @@ def _dependencies_dict(self, depflag: dt.DepFlag = dt.ALL):
|
|||||||
result[key] = list(group)
|
result[key] = list(group)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
#
|
|
||||||
# Private routines here are called by the parser when building a spec.
|
|
||||||
#
|
|
||||||
def _add_versions(self, version_list):
|
|
||||||
"""Called by the parser to add an allowable version."""
|
|
||||||
# If it already has a non-trivial version list, this is an error
|
|
||||||
if self.versions and self.versions != vn.any_version:
|
|
||||||
raise MultipleVersionError(
|
|
||||||
"A spec cannot contain multiple version signifiers." " Use a version list instead."
|
|
||||||
)
|
|
||||||
self.versions = vn.VersionList()
|
|
||||||
for version in version_list:
|
|
||||||
self.versions.add(version)
|
|
||||||
|
|
||||||
def _add_flag(self, name, value, propagate):
|
def _add_flag(self, name, value, propagate):
|
||||||
"""Called by the parser to add a known flag.
|
"""Called by the parser to add a known flag.
|
||||||
Known flags currently include "arch"
|
Known flags currently include "arch"
|
||||||
@ -1626,14 +1600,6 @@ def _set_architecture(self, **kwargs):
|
|||||||
else:
|
else:
|
||||||
setattr(self.architecture, new_attr, new_value)
|
setattr(self.architecture, new_attr, new_value)
|
||||||
|
|
||||||
def _set_compiler(self, compiler):
|
|
||||||
"""Called by the parser to set the compiler."""
|
|
||||||
if self.compiler:
|
|
||||||
raise DuplicateCompilerSpecError(
|
|
||||||
"Spec for '%s' cannot have two compilers." % self.name
|
|
||||||
)
|
|
||||||
self.compiler = compiler
|
|
||||||
|
|
||||||
def _add_dependency(self, spec: "Spec", *, depflag: dt.DepFlag, virtuals: Tuple[str, ...]):
|
def _add_dependency(self, spec: "Spec", *, depflag: dt.DepFlag, virtuals: Tuple[str, ...]):
|
||||||
"""Called by the parser to add another spec as a dependency."""
|
"""Called by the parser to add another spec as a dependency."""
|
||||||
if spec.name not in self._dependencies or not spec.name:
|
if spec.name not in self._dependencies or not spec.name:
|
||||||
|
Loading…
Reference in New Issue
Block a user