compilers: avoid redundant fs operations and cache (#46031)
This commit is contained in:
parent
2de712b35f
commit
02f329a8af
@ -16,7 +16,7 @@
|
|||||||
from typing import Any, Callable, Iterable, List, Tuple
|
from typing import Any, Callable, Iterable, List, Tuple
|
||||||
|
|
||||||
# Ignore emacs backups when listing modules
|
# Ignore emacs backups when listing modules
|
||||||
ignore_modules = [r"^\.#", "~$"]
|
ignore_modules = r"^\.#|~$"
|
||||||
|
|
||||||
|
|
||||||
def index_by(objects, *funcs):
|
def index_by(objects, *funcs):
|
||||||
@ -164,19 +164,22 @@ def list_modules(directory, **kwargs):
|
|||||||
order."""
|
order."""
|
||||||
list_directories = kwargs.setdefault("directories", True)
|
list_directories = kwargs.setdefault("directories", True)
|
||||||
|
|
||||||
for name in os.listdir(directory):
|
ignore = re.compile(ignore_modules)
|
||||||
if name == "__init__.py":
|
|
||||||
continue
|
|
||||||
|
|
||||||
path = os.path.join(directory, name)
|
with os.scandir(directory) as it:
|
||||||
if list_directories and os.path.isdir(path):
|
for entry in it:
|
||||||
init_py = os.path.join(path, "__init__.py")
|
if entry.name == "__init__.py" or entry.name == "__pycache__":
|
||||||
if os.path.isfile(init_py):
|
continue
|
||||||
yield name
|
|
||||||
|
|
||||||
elif name.endswith(".py"):
|
if (
|
||||||
if not any(re.search(pattern, name) for pattern in ignore_modules):
|
list_directories
|
||||||
yield re.sub(".py$", "", name)
|
and entry.is_dir()
|
||||||
|
and os.path.isfile(os.path.join(entry.path, "__init__.py"))
|
||||||
|
):
|
||||||
|
yield entry.name
|
||||||
|
|
||||||
|
elif entry.name.endswith(".py") and entry.is_file() and not ignore.search(entry.name):
|
||||||
|
yield entry.name[:-3] # strip .py
|
||||||
|
|
||||||
|
|
||||||
def decorator_with_or_without_args(decorator):
|
def decorator_with_or_without_args(decorator):
|
||||||
|
@ -394,8 +394,9 @@ def replace_apple_clang(name):
|
|||||||
return [replace_apple_clang(name) for name in all_compiler_module_names()]
|
return [replace_apple_clang(name) for name in all_compiler_module_names()]
|
||||||
|
|
||||||
|
|
||||||
|
@llnl.util.lang.memoized
|
||||||
def all_compiler_module_names() -> List[str]:
|
def all_compiler_module_names() -> List[str]:
|
||||||
return [name for name in llnl.util.lang.list_modules(spack.paths.compilers_path)]
|
return list(llnl.util.lang.list_modules(spack.paths.compilers_path))
|
||||||
|
|
||||||
|
|
||||||
@_auto_compiler_spec
|
@_auto_compiler_spec
|
||||||
|
Loading…
Reference in New Issue
Block a user