Add type hints to spack.installer (#38872)
This commit is contained in:
		@@ -36,6 +36,8 @@
 | 
				
			|||||||
    _use_uuid = False
 | 
					    _use_uuid = False
 | 
				
			||||||
    pass
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from typing import Optional, Tuple
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import llnl.util.filesystem as fs
 | 
					import llnl.util.filesystem as fs
 | 
				
			||||||
import llnl.util.lang as lang
 | 
					import llnl.util.lang as lang
 | 
				
			||||||
import llnl.util.tty as tty
 | 
					import llnl.util.tty as tty
 | 
				
			||||||
@@ -178,9 +180,9 @@ class InstallRecord:
 | 
				
			|||||||
    dependents left.
 | 
					    dependents left.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Args:
 | 
					    Args:
 | 
				
			||||||
        spec (spack.spec.Spec): spec tracked by the install record
 | 
					        spec: spec tracked by the install record
 | 
				
			||||||
        path (str): path where the spec has been installed
 | 
					        path: path where the spec has been installed
 | 
				
			||||||
        installed (bool): whether or not the spec is currently installed
 | 
					        installed: whether or not the spec is currently installed
 | 
				
			||||||
        ref_count (int): number of specs that depend on this one
 | 
					        ref_count (int): number of specs that depend on this one
 | 
				
			||||||
        explicit (bool or None): whether or not this spec was explicitly
 | 
					        explicit (bool or None): whether or not this spec was explicitly
 | 
				
			||||||
            installed, or pulled-in as a dependency of something else
 | 
					            installed, or pulled-in as a dependency of something else
 | 
				
			||||||
@@ -189,14 +191,14 @@ class InstallRecord:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def __init__(
 | 
					    def __init__(
 | 
				
			||||||
        self,
 | 
					        self,
 | 
				
			||||||
        spec,
 | 
					        spec: "spack.spec.Spec",
 | 
				
			||||||
        path,
 | 
					        path: str,
 | 
				
			||||||
        installed,
 | 
					        installed: bool,
 | 
				
			||||||
        ref_count=0,
 | 
					        ref_count: int = 0,
 | 
				
			||||||
        explicit=False,
 | 
					        explicit: bool = False,
 | 
				
			||||||
        installation_time=None,
 | 
					        installation_time: Optional[float] = None,
 | 
				
			||||||
        deprecated_for=None,
 | 
					        deprecated_for: Optional["spack.spec.Spec"] = None,
 | 
				
			||||||
        in_buildcache=False,
 | 
					        in_buildcache: bool = False,
 | 
				
			||||||
        origin=None,
 | 
					        origin=None,
 | 
				
			||||||
    ):
 | 
					    ):
 | 
				
			||||||
        self.spec = spec
 | 
					        self.spec = spec
 | 
				
			||||||
@@ -407,7 +409,7 @@ def __init__(
 | 
				
			|||||||
            self.lock = lk.Lock(
 | 
					            self.lock = lk.Lock(
 | 
				
			||||||
                self._lock_path, default_timeout=self.db_lock_timeout, desc="database"
 | 
					                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
 | 
					        # 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
 | 
					        # 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:
 | 
					            if hash_key in db._data:
 | 
				
			||||||
                return db
 | 
					                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.
 | 
					        """Get a spec for hash, and whether it's installed upstream.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Return:
 | 
					        Return:
 | 
				
			||||||
 
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -639,7 +639,7 @@ class PackageBase(WindowsRPath, PackageViewMixin, metaclass=PackageMeta):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def __init__(self, spec):
 | 
					    def __init__(self, spec):
 | 
				
			||||||
        # this determines how the package should be built.
 | 
					        # this determines how the package should be built.
 | 
				
			||||||
        self.spec = spec
 | 
					        self.spec: "spack.spec.Spec" = spec
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Allow custom staging paths for packages
 | 
					        # Allow custom staging paths for packages
 | 
				
			||||||
        self.path = None
 | 
					        self.path = None
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,10 +25,7 @@
 | 
				
			|||||||
global_timer_name = "_global"
 | 
					global_timer_name = "_global"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class NullTimer:
 | 
					class BaseTimer:
 | 
				
			||||||
    """Timer interface that does nothing, useful in for "tell
 | 
					 | 
				
			||||||
    don't ask" style code when timers are optional."""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def start(self, name=global_timer_name):
 | 
					    def start(self, name=global_timer_name):
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -53,11 +50,14 @@ def write_tty(self, out=sys.stdout):
 | 
				
			|||||||
        pass
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#: instance of a do-nothing timer
 | 
					class NullTimer(BaseTimer):
 | 
				
			||||||
NULL_TIMER = NullTimer()
 | 
					    """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"""
 | 
					    """Simple interval timer"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, now=time.time):
 | 
					    def __init__(self, now=time.time):
 | 
				
			||||||
@@ -153,3 +153,7 @@ def write_tty(self, out=sys.stdout):
 | 
				
			|||||||
        # Write to out
 | 
					        # Write to out
 | 
				
			||||||
        for name, duration in formatted:
 | 
					        for name, duration in formatted:
 | 
				
			||||||
            out.write(f"    {name:10s} {pretty_seconds(duration):>10s}\n")
 | 
					            out.write(f"    {name:10s} {pretty_seconds(duration):>10s}\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#: instance of a do-nothing timer
 | 
				
			||||||
 | 
					NULL_TIMER = NullTimer()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user