summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-10-30 13:48:32 +0100
committerGitHub <noreply@github.com>2024-10-30 13:48:32 +0100
commit8892c878ce173022c0efb18b35f1b21afd7a072b (patch)
tree5c3ce8e13c3861b9de99603084d3a4b8da8da145 /lib
parentcbf4d3967a29db1e49129964a2f2fef4da7461a6 (diff)
downloadspack-8892c878ce173022c0efb18b35f1b21afd7a072b.tar.gz
spack-8892c878ce173022c0efb18b35f1b21afd7a072b.tar.bz2
spack-8892c878ce173022c0efb18b35f1b21afd7a072b.tar.xz
spack-8892c878ce173022c0efb18b35f1b21afd7a072b.zip
types: remove singleton union in globals (#47282)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/caches.py11
-rw-r--r--lib/spack/spack/config.py12
-rw-r--r--lib/spack/spack/repo.py13
-rw-r--r--lib/spack/spack/store.py7
4 files changed, 14 insertions, 29 deletions
diff --git a/lib/spack/spack/caches.py b/lib/spack/spack/caches.py
index 58594059a5..f2d4bfeec0 100644
--- a/lib/spack/spack/caches.py
+++ b/lib/spack/spack/caches.py
@@ -5,7 +5,6 @@
"""Caches used by Spack to store data"""
import os
-from typing import Union
import llnl.util.lang
from llnl.util.filesystem import mkdirp
@@ -32,12 +31,8 @@ def _misc_cache():
return spack.util.file_cache.FileCache(path)
-FileCacheType = Union[spack.util.file_cache.FileCache, llnl.util.lang.Singleton]
-
#: Spack's cache for small data
-MISC_CACHE: Union[spack.util.file_cache.FileCache, llnl.util.lang.Singleton] = (
- llnl.util.lang.Singleton(_misc_cache)
-)
+MISC_CACHE: spack.util.file_cache.FileCache = llnl.util.lang.Singleton(_misc_cache) # type: ignore
def fetch_cache_location():
@@ -74,6 +69,4 @@ class MirrorCache:
#: Spack's local cache for downloaded source archives
-FETCH_CACHE: Union[spack.fetch_strategy.FsCache, llnl.util.lang.Singleton] = (
- llnl.util.lang.Singleton(_fetch_cache)
-)
+FETCH_CACHE: spack.fetch_strategy.FsCache = llnl.util.lang.Singleton(_fetch_cache) # type: ignore
diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py
index 94f8e4ff04..afd8f30bac 100644
--- a/lib/spack/spack/config.py
+++ b/lib/spack/spack/config.py
@@ -714,7 +714,7 @@ class Configuration:
@contextlib.contextmanager
def override(
path_or_scope: Union[ConfigScope, str], value: Optional[Any] = None
-) -> Generator[Union[lang.Singleton, Configuration], None, None]:
+) -> Generator[Configuration, None, None]:
"""Simple way to override config settings within a context.
Arguments:
@@ -756,9 +756,7 @@ def override(
COMMAND_LINE_SCOPES: List[str] = []
-def _add_platform_scope(
- cfg: Union[Configuration, lang.Singleton], name: str, path: str, writable: bool = True
-) -> None:
+def _add_platform_scope(cfg: Configuration, name: str, path: str, writable: bool = True) -> None:
"""Add a platform-specific subdirectory for the current platform."""
platform = spack.platforms.host().name
scope = DirectoryConfigScope(
@@ -792,9 +790,7 @@ def config_paths_from_entry_points() -> List[Tuple[str, str]]:
return config_paths
-def _add_command_line_scopes(
- cfg: Union[Configuration, lang.Singleton], command_line_scopes: List[str]
-) -> None:
+def _add_command_line_scopes(cfg: Configuration, command_line_scopes: List[str]) -> None:
"""Add additional scopes from the --config-scope argument, either envs or dirs."""
import spack.environment.environment as env # circular import
@@ -875,7 +871,7 @@ def create() -> Configuration:
#: This is the singleton configuration instance for Spack.
-CONFIG: Union[Configuration, lang.Singleton] = lang.Singleton(create)
+CONFIG: Configuration = lang.Singleton(create) # type: ignore
def add_from_file(filename: str, scope: Optional[str] = None) -> None:
diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py
index 3f54b02299..f3872aed8d 100644
--- a/lib/spack/spack/repo.py
+++ b/lib/spack/spack/repo.py
@@ -41,6 +41,7 @@ import spack.patch
import spack.provider_index
import spack.spec
import spack.tag
+import spack.util.file_cache
import spack.util.git
import spack.util.naming as nm
import spack.util.path
@@ -589,7 +590,7 @@ class RepoIndex:
self,
package_checker: FastPackageChecker,
namespace: str,
- cache: "spack.caches.FileCacheType",
+ cache: spack.util.file_cache.FileCache,
):
self.checker = package_checker
self.packages_path = self.checker.packages_path
@@ -682,7 +683,7 @@ class RepoPath:
def __init__(
self,
*repos: Union[str, "Repo"],
- cache: Optional["spack.caches.FileCacheType"],
+ cache: Optional[spack.util.file_cache.FileCache],
overrides: Optional[Dict[str, Any]] = None,
) -> None:
self.repos: List[Repo] = []
@@ -964,7 +965,7 @@ class Repo:
self,
root: str,
*,
- cache: "spack.caches.FileCacheType",
+ cache: spack.util.file_cache.FileCache,
overrides: Optional[Dict[str, Any]] = None,
) -> None:
"""Instantiate a package repository from a filesystem path.
@@ -1439,9 +1440,7 @@ def _path(configuration=None):
return create(configuration=configuration)
-def create(
- configuration: Union["spack.config.Configuration", llnl.util.lang.Singleton]
-) -> RepoPath:
+def create(configuration: spack.config.Configuration) -> RepoPath:
"""Create a RepoPath from a configuration object.
Args:
@@ -1464,7 +1463,7 @@ def create(
#: Singleton repo path instance
-PATH: Union[RepoPath, llnl.util.lang.Singleton] = llnl.util.lang.Singleton(_path)
+PATH: RepoPath = llnl.util.lang.Singleton(_path) # type: ignore
# Add the finder to sys.meta_path
REPOS_FINDER = ReposFinder()
diff --git a/lib/spack/spack/store.py b/lib/spack/spack/store.py
index 5884f24149..abd7d92500 100644
--- a/lib/spack/spack/store.py
+++ b/lib/spack/spack/store.py
@@ -39,9 +39,6 @@ import spack.util.path
DEFAULT_INSTALL_TREE_ROOT = os.path.join(spack.paths.opt_path, "spack")
-ConfigurationType = Union["spack.config.Configuration", "llnl.util.lang.Singleton"]
-
-
def parse_install_tree(config_dict):
"""Parse config settings and return values relevant to the store object.
@@ -207,7 +204,7 @@ class Store:
)
-def create(configuration: ConfigurationType) -> Store:
+def create(configuration: spack.config.Configuration) -> Store:
"""Create a store from the configuration passed as input.
Args:
@@ -240,7 +237,7 @@ def _create_global() -> Store:
#: Singleton store instance
-STORE: Union[Store, llnl.util.lang.Singleton] = llnl.util.lang.Singleton(_create_global)
+STORE: Store = llnl.util.lang.Singleton(_create_global) # type: ignore
def reinitialize():