Add type hints to spack.installer (#38872)

This commit is contained in:
Harmen Stoppels 2023-07-13 12:41:19 +02:00 committed by GitHub
parent b67f1f395b
commit 161b30a32f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 679 additions and 632 deletions

View file

@ -36,6 +36,8 @@
_use_uuid = False
pass
from typing import Optional, Tuple
import llnl.util.filesystem as fs
import llnl.util.lang as lang
import llnl.util.tty as tty
@ -178,9 +180,9 @@ class InstallRecord:
dependents left.
Args:
spec (spack.spec.Spec): spec tracked by the install record
path (str): path where the spec has been installed
installed (bool): whether or not the spec is currently installed
spec: spec tracked by the install record
path: path where the spec has been installed
installed: whether or not the spec is currently installed
ref_count (int): number of specs that depend on this one
explicit (bool or None): whether or not this spec was explicitly
installed, or pulled-in as a dependency of something else
@ -189,14 +191,14 @@ class InstallRecord:
def __init__(
self,
spec,
path,
installed,
ref_count=0,
explicit=False,
installation_time=None,
deprecated_for=None,
in_buildcache=False,
spec: "spack.spec.Spec",
path: str,
installed: bool,
ref_count: int = 0,
explicit: bool = False,
installation_time: Optional[float] = None,
deprecated_for: Optional["spack.spec.Spec"] = None,
in_buildcache: bool = False,
origin=None,
):
self.spec = spec
@ -407,7 +409,7 @@ def __init__(
self.lock = lk.Lock(
self._lock_path, default_timeout=self.db_lock_timeout, desc="database"
)
self._data = {}
self._data: Dict[str, InstallRecord] = {}
# For every installed spec we keep track of its install prefix, so that
# we can answer the simple query whether a given path is already taken
@ -710,7 +712,9 @@ def db_for_spec_hash(self, hash_key):
if hash_key in db._data:
return db
def query_by_spec_hash(self, hash_key, data=None):
def query_by_spec_hash(
self, hash_key: str, data: Optional[Dict[str, InstallRecord]] = None
) -> Tuple[bool, Optional[InstallRecord]]:
"""Get a spec for hash, and whether it's installed upstream.
Return:

File diff suppressed because it is too large Load diff

View file

@ -639,7 +639,7 @@ class PackageBase(WindowsRPath, PackageViewMixin, metaclass=PackageMeta):
def __init__(self, spec):
# this determines how the package should be built.
self.spec = spec
self.spec: "spack.spec.Spec" = spec
# Allow custom staging paths for packages
self.path = None

View file

@ -25,10 +25,7 @@
global_timer_name = "_global"
class NullTimer:
"""Timer interface that does nothing, useful in for "tell
don't ask" style code when timers are optional."""
class BaseTimer:
def start(self, name=global_timer_name):
pass
@ -53,11 +50,14 @@ def write_tty(self, out=sys.stdout):
pass
#: instance of a do-nothing timer
NULL_TIMER = NullTimer()
class NullTimer(BaseTimer):
"""Timer interface that does nothing, useful in for "tell
don't ask" style code when timers are optional."""
pass
class Timer:
class Timer(BaseTimer):
"""Simple interval timer"""
def __init__(self, now=time.time):
@ -153,3 +153,7 @@ def write_tty(self, out=sys.stdout):
# Write to out
for name, duration in formatted:
out.write(f" {name:10s} {pretty_seconds(duration):>10s}\n")
#: instance of a do-nothing timer
NULL_TIMER = NullTimer()