summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2024-03-11 08:47:55 +0100
committerGitHub <noreply@github.com>2024-03-11 00:47:55 -0700
commit1e47ccb83a3e0b394560f39538cde6563edbaca3 (patch)
treeb721a8e12991c1194313d394920aa6738dd08f39
parentd6421a69ebf9ea2172f1fa9ff5339a1a7317cf3c (diff)
downloadspack-1e47ccb83a3e0b394560f39538cde6563edbaca3.tar.gz
spack-1e47ccb83a3e0b394560f39538cde6563edbaca3.tar.bz2
spack-1e47ccb83a3e0b394560f39538cde6563edbaca3.tar.xz
spack-1e47ccb83a3e0b394560f39538cde6563edbaca3.zip
Remove dead code (#43114)
* Remove dead code in spack * Remove dead code in llnl
-rw-r--r--lib/spack/llnl/path.py5
-rw-r--r--lib/spack/llnl/util/filesystem.py70
-rw-r--r--lib/spack/llnl/util/lang.py90
-rw-r--r--lib/spack/llnl/util/lock.py4
-rw-r--r--lib/spack/llnl/util/tty/__init__.py35
-rw-r--r--lib/spack/spack/spec.py34
6 files changed, 0 insertions, 238 deletions
diff --git a/lib/spack/llnl/path.py b/lib/spack/llnl/path.py
index 18f9b6e9a2..9ef90eec4c 100644
--- a/lib/spack/llnl/path.py
+++ b/lib/spack/llnl/path.py
@@ -42,11 +42,6 @@ def convert_to_posix_path(path: str) -> str:
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:
"""Converts the input path to the current platform's native style."""
return format_os_path(path, mode=Path.platform_path)
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index a9cfc10091..390d1f651e 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -237,16 +237,6 @@ def _get_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):
"""Returns the mime type and subtype of a file.
@@ -262,21 +252,6 @@ def mime_type(filename):
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.
library_extensions = ["a", "la", "so", "tbd", "dylib"]
@@ -308,13 +283,6 @@ def paths_containing_libs(paths, library_names):
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(
regex: 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)
-@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):
"""Returns whether a path has a shebang line. Returns False if the file cannot be opened."""
try:
@@ -1169,20 +1126,6 @@ def write_tmp_and_move(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
def touch(path):
"""Creates an empty file at the specified path."""
@@ -1295,19 +1238,6 @@ def temp_cwd():
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
def can_access(file_name):
"""True if we have read/write access to the file."""
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py
index c59ecf2758..c3e67f205d 100644
--- a/lib/spack/llnl/util/lang.py
+++ b/lib/spack/llnl/util/lang.py
@@ -98,36 +98,6 @@ def caller_locals():
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):
"""Like dict.setdefault, but for objects."""
if not hasattr(obj, name):
@@ -513,42 +483,6 @@ class HashableMap(collections.abc.MutableMapping):
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):
"""Utility function for making string matching predicates.
@@ -764,11 +698,6 @@ def pretty_seconds(seconds):
return pretty_seconds_formatter(seconds)(seconds)
-class RequiredAttributeError(ValueError):
- def __init__(self, message):
- super().__init__(message)
-
-
class ObjectWrapper:
"""Base class that wraps an object. Derived classes can add new behavior
while staying undercover.
@@ -935,25 +864,6 @@ def uniq(sequence):
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):
"""Takes a long list and limits it to a smaller number of elements,
replacing intervening elements with '...'. For example::
diff --git a/lib/spack/llnl/util/lock.py b/lib/spack/llnl/util/lock.py
index 08c90b21ce..3df408cb31 100644
--- a/lib/spack/llnl/util/lock.py
+++ b/lib/spack/llnl/util/lock.py
@@ -815,10 +815,6 @@ class LockDowngradeError(LockError):
super().__init__(msg)
-class LockLimitError(LockError):
- """Raised when exceed maximum attempts to acquire a lock."""
-
-
class LockTimeoutError(LockError):
"""Raised when an attempt to acquire a lock times out."""
diff --git a/lib/spack/llnl/util/tty/__init__.py b/lib/spack/llnl/util/tty/__init__.py
index 7a322a6e48..3f3ba1d462 100644
--- a/lib/spack/llnl/util/tty/__init__.py
+++ b/lib/spack/llnl/util/tty/__init__.py
@@ -44,10 +44,6 @@ def is_debug(level=1):
return _debug >= level
-def is_stacktrace():
- return _stacktrace
-
-
def set_debug(level=0):
global _debug
assert level >= 0, "Debug level must be a positive value"
@@ -252,37 +248,6 @@ def die(message, *args, **kwargs) -> NoReturn:
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):
default_value = kwargs.get("default", None)
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index d54921bf67..53d2dc6b05 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -625,18 +625,6 @@ class CompilerSpec:
else:
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):
if isinstance(compiler_spec_like, CompilerSpec):
return compiler_spec_like
@@ -1544,20 +1532,6 @@ class Spec:
result[key] = list(group)
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):
"""Called by the parser to add a known flag.
Known flags currently include "arch"
@@ -1626,14 +1600,6 @@ class Spec:
else:
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, ...]):
"""Called by the parser to add another spec as a dependency."""
if spec.name not in self._dependencies or not spec.name: