types: remove singleton union in globals (#47282)

This commit is contained in:
Harmen Stoppels 2024-10-30 13:48:32 +01:00 committed by GitHub
parent cbf4d3967a
commit 8892c878ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 29 deletions

View File

@ -5,7 +5,6 @@
"""Caches used by Spack to store data""" """Caches used by Spack to store data"""
import os import os
from typing import Union
import llnl.util.lang import llnl.util.lang
from llnl.util.filesystem import mkdirp from llnl.util.filesystem import mkdirp
@ -32,12 +31,8 @@ def _misc_cache():
return spack.util.file_cache.FileCache(path) return spack.util.file_cache.FileCache(path)
FileCacheType = Union[spack.util.file_cache.FileCache, llnl.util.lang.Singleton]
#: Spack's cache for small data #: Spack's cache for small data
MISC_CACHE: Union[spack.util.file_cache.FileCache, llnl.util.lang.Singleton] = ( MISC_CACHE: spack.util.file_cache.FileCache = llnl.util.lang.Singleton(_misc_cache) # type: ignore
llnl.util.lang.Singleton(_misc_cache)
)
def fetch_cache_location(): def fetch_cache_location():
@ -74,6 +69,4 @@ def store(self, fetcher, relative_dest):
#: Spack's local cache for downloaded source archives #: Spack's local cache for downloaded source archives
FETCH_CACHE: Union[spack.fetch_strategy.FsCache, llnl.util.lang.Singleton] = ( FETCH_CACHE: spack.fetch_strategy.FsCache = llnl.util.lang.Singleton(_fetch_cache) # type: ignore
llnl.util.lang.Singleton(_fetch_cache)
)

View File

@ -714,7 +714,7 @@ def print_section(self, section: str, blame: bool = False, *, scope=None) -> Non
@contextlib.contextmanager @contextlib.contextmanager
def override( def override(
path_or_scope: Union[ConfigScope, str], value: Optional[Any] = None 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. """Simple way to override config settings within a context.
Arguments: Arguments:
@ -756,9 +756,7 @@ def override(
COMMAND_LINE_SCOPES: List[str] = [] COMMAND_LINE_SCOPES: List[str] = []
def _add_platform_scope( def _add_platform_scope(cfg: Configuration, name: str, path: str, writable: bool = True) -> None:
cfg: Union[Configuration, lang.Singleton], name: str, path: str, writable: bool = True
) -> None:
"""Add a platform-specific subdirectory for the current platform.""" """Add a platform-specific subdirectory for the current platform."""
platform = spack.platforms.host().name platform = spack.platforms.host().name
scope = DirectoryConfigScope( scope = DirectoryConfigScope(
@ -792,9 +790,7 @@ def config_paths_from_entry_points() -> List[Tuple[str, str]]:
return config_paths return config_paths
def _add_command_line_scopes( def _add_command_line_scopes(cfg: Configuration, command_line_scopes: List[str]) -> None:
cfg: Union[Configuration, lang.Singleton], command_line_scopes: List[str]
) -> None:
"""Add additional scopes from the --config-scope argument, either envs or dirs.""" """Add additional scopes from the --config-scope argument, either envs or dirs."""
import spack.environment.environment as env # circular import import spack.environment.environment as env # circular import
@ -875,7 +871,7 @@ def create() -> Configuration:
#: This is the singleton configuration instance for Spack. #: 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: def add_from_file(filename: str, scope: Optional[str] = None) -> None:

View File

@ -41,6 +41,7 @@
import spack.provider_index import spack.provider_index
import spack.spec import spack.spec
import spack.tag import spack.tag
import spack.util.file_cache
import spack.util.git import spack.util.git
import spack.util.naming as nm import spack.util.naming as nm
import spack.util.path import spack.util.path
@ -589,7 +590,7 @@ def __init__(
self, self,
package_checker: FastPackageChecker, package_checker: FastPackageChecker,
namespace: str, namespace: str,
cache: "spack.caches.FileCacheType", cache: spack.util.file_cache.FileCache,
): ):
self.checker = package_checker self.checker = package_checker
self.packages_path = self.checker.packages_path self.packages_path = self.checker.packages_path
@ -682,7 +683,7 @@ class RepoPath:
def __init__( def __init__(
self, self,
*repos: Union[str, "Repo"], *repos: Union[str, "Repo"],
cache: Optional["spack.caches.FileCacheType"], cache: Optional[spack.util.file_cache.FileCache],
overrides: Optional[Dict[str, Any]] = None, overrides: Optional[Dict[str, Any]] = None,
) -> None: ) -> None:
self.repos: List[Repo] = [] self.repos: List[Repo] = []
@ -964,7 +965,7 @@ def __init__(
self, self,
root: str, root: str,
*, *,
cache: "spack.caches.FileCacheType", cache: spack.util.file_cache.FileCache,
overrides: Optional[Dict[str, Any]] = None, overrides: Optional[Dict[str, Any]] = None,
) -> None: ) -> None:
"""Instantiate a package repository from a filesystem path. """Instantiate a package repository from a filesystem path.
@ -1439,9 +1440,7 @@ def _path(configuration=None):
return create(configuration=configuration) return create(configuration=configuration)
def create( def create(configuration: spack.config.Configuration) -> RepoPath:
configuration: Union["spack.config.Configuration", llnl.util.lang.Singleton]
) -> RepoPath:
"""Create a RepoPath from a configuration object. """Create a RepoPath from a configuration object.
Args: Args:
@ -1464,7 +1463,7 @@ def create(
#: Singleton repo path instance #: 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 # Add the finder to sys.meta_path
REPOS_FINDER = ReposFinder() REPOS_FINDER = ReposFinder()

View File

@ -39,9 +39,6 @@
DEFAULT_INSTALL_TREE_ROOT = os.path.join(spack.paths.opt_path, "spack") 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): def parse_install_tree(config_dict):
"""Parse config settings and return values relevant to the store object. """Parse config settings and return values relevant to the store object.
@ -207,7 +204,7 @@ def __reduce__(self):
) )
def create(configuration: ConfigurationType) -> Store: def create(configuration: spack.config.Configuration) -> Store:
"""Create a store from the configuration passed as input. """Create a store from the configuration passed as input.
Args: Args:
@ -240,7 +237,7 @@ def _create_global() -> Store:
#: Singleton store instance #: 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(): def reinitialize():