spack.detection package
- spack.detection.by_path(packages_to_search: Iterable[str], *, path_hints: List[str] | None = None, max_workers: int | None = None) Dict[str, List[Spec]] [source]
Return the list of packages that have been detected on the system, keyed by unqualified package name.
- Parameters:
packages_to_search – list of packages to be detected. Each package can be either unqualified of fully qualified
path_hints – initial list of paths to be searched
max_workers – maximum number of workers to search for packages in parallel
- spack.detection.detection_tests(pkg_name: str, repository: RepoPath) List[Runner] [source]
Returns a list of test runners for a given package.
Currently, detection tests are specified in a YAML file, called
detection_test.yaml
, alongside thepackage.py
file.This function reads that file to create a bunch of
Runner
objects.- Parameters:
pkg_name – name of the package to test
repository – repository where the package lives
- spack.detection.executable_prefix(executable_dir: str) str [source]
Given a directory where an executable is found, guess the prefix (i.e. the “root” directory of that installation) and return it.
- Parameters:
executable_dir – directory where an executable is found
- spack.detection.executables_in_path(path_hints: List[str]) Dict[str, str] [source]
Get the paths of all executables available from the current PATH.
For convenience, this is constructed as a dictionary where the keys are the executable paths and the values are the names of the executables (i.e. the basename of the executable path).
There may be multiple paths with the same basename. In this case it is assumed there are two different instances of the executable.
- Parameters:
path_hints – list of paths to be searched. If None the list will be constructed based on the PATH environment variable.
- spack.detection.set_virtuals_nonbuildable(virtuals: Set[str], scope: str | None = None) List[str] [source]
Update packages:virtual:buildable:False for the provided virtual packages, if the property is not set by the user. Returns the list of virtual packages that have been updated.
- spack.detection.update_configuration(detected_packages: Dict[str, List[Spec]], scope: str | None = None, buildable: bool = True) List[Spec] [source]
Add the packages passed as arguments to packages.yaml
- Parameters:
detected_packages – list of specs to be added
scope – configuration scope where to add the detected packages
buildable – whether the detected packages are buildable or not
Submodules
spack.detection.common module
Define a common data structure to represent external packages and a function to update packages.yaml given a list of detected packages.
Ideally, each detection method should be placed in a specific subpackage and implement at least a function that returns a list of specs.
The update in packages.yaml can then be done using the function provided here.
The module also contains other functions that might be useful across different detection mechanisms.
- class spack.detection.common.WindowsCompilerExternalPaths[source]
Bases:
object
- static find_windows_compiler_bundled_packages() List[str] [source]
Return all MSVC compiler bundled packages
- static find_windows_compiler_cmake_paths() List[str] [source]
Semi hard-coded search path for cmake bundled with MSVC
- class spack.detection.common.WindowsKitExternalPaths[source]
Bases:
object
- static find_windows_driver_development_kit_paths() List[str] [source]
Provides a list of all installation paths for the WDK by version and architecture
- static find_windows_kit_bin_paths(kit_base: str | None | list = None) List[str] [source]
Returns Windows kit bin directory per version
- spack.detection.common.compute_windows_program_path_for_package(pkg: PackageBase) List[str] [source]
Given a package, attempts to compute its Windows program files location, and returns the list of best guesses.
- Parameters:
pkg – package for which Program Files location is to be computed
- spack.detection.common.compute_windows_user_path_for_package(pkg: PackageBase) List[str] [source]
Given a package attempt to compute its user scoped install location, return list of potential locations based on common heuristics. For more info on Windows user specific installs see: https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=netframework-4.8
- spack.detection.common.executable_prefix(executable_dir: str) str [source]
Given a directory where an executable is found, guess the prefix (i.e. the “root” directory of that installation) and return it.
- Parameters:
executable_dir – directory where an executable is found
- spack.detection.common.find_win32_additional_install_paths() List[str] [source]
Not all programs on Windows live on the PATH Return a list of other potential install locations.
- spack.detection.common.is_executable(file_path: str) bool [source]
Return True if the path passed as argument is that of an executable
- spack.detection.common.library_prefix(library_dir: str) str [source]
Given a directory where a library is found, guess the prefix (i.e. the “root” directory of that installation) and return it.
- Parameters:
library_dir – directory where a library is found
- spack.detection.common.path_to_dict(search_paths: List[str]) Dict[str, str] [source]
Return dictionary[fullpath]: basename from list of paths
- spack.detection.common.set_virtuals_nonbuildable(virtuals: Set[str], scope: str | None = None) List[str] [source]
Update packages:virtual:buildable:False for the provided virtual packages, if the property is not set by the user. Returns the list of virtual packages that have been updated.
- spack.detection.common.update_configuration(detected_packages: Dict[str, List[Spec]], scope: str | None = None, buildable: bool = True) List[Spec] [source]
Add the packages passed as arguments to packages.yaml
- Parameters:
detected_packages – list of specs to be added
scope – configuration scope where to add the detected packages
buildable – whether the detected packages are buildable or not
spack.detection.path module
Detection of software installed in the system, based on paths inspections and running executables.
- spack.detection.path.DETECTION_TIMEOUT = 60
Timeout used for package detection (seconds)
- class spack.detection.path.ExecutablesFinder[source]
Bases:
Finder
- candidate_files(*, patterns: List[str], paths: List[str]) List[str] [source]
Returns a list of candidate files found on the system.
- Parameters:
patterns – search patterns to be used for matching files
paths – paths where to search for files
- class spack.detection.path.Finder[source]
Bases:
object
Inspects the file-system looking for packages. Guesses places where to look using PATH.
- candidate_files(*, patterns: List[str], paths: List[str]) List[str] [source]
Returns a list of candidate files found on the system.
- Parameters:
patterns – search patterns to be used for matching files
paths – paths where to search for files
- detect_specs(*, pkg: Type[PackageBase], paths: Iterable[str]) List[Spec] [source]
Given a list of files matching the search patterns, returns a list of detected specs.
- Parameters:
pkg – package being detected
paths – files matching the package search patterns
- find(*, pkg_name: str, repository, initial_guess: List[str] | None = None) List[Spec] [source]
For a given package, returns a list of detected specs.
- Parameters:
pkg_name – package being detected
repository – repository to retrieve the package
initial_guess – initial list of paths to search from the caller if None, default paths are searched. If this is an empty list, nothing will be searched.
- class spack.detection.path.LibrariesFinder[source]
Bases:
Finder
Finds libraries on the system, searching by LD_LIBRARY_PATH, LIBRARY_PATH, DYLD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATH, and standard system library paths
- candidate_files(*, patterns: List[str], paths: List[str]) List[str] [source]
Returns a list of candidate files found on the system.
- Parameters:
patterns – search patterns to be used for matching files
paths – paths where to search for files
- spack.detection.path.accept_elf(path, host_compat)[source]
Accept an ELF file if the header matches the given compat triplet. In case it’s not an ELF (e.g. static library, or some arbitrary file, fall back to is_readable_file).
- spack.detection.path.by_path(packages_to_search: Iterable[str], *, path_hints: List[str] | None = None, max_workers: int | None = None) Dict[str, List[Spec]] [source]
Return the list of packages that have been detected on the system, keyed by unqualified package name.
- Parameters:
packages_to_search – list of packages to be detected. Each package can be either unqualified of fully qualified
path_hints – initial list of paths to be searched
max_workers – maximum number of workers to search for packages in parallel
- spack.detection.path.common_windows_package_paths(pkg_cls=None) List[str] [source]
Get the paths for common package installation location on Windows that are outside the PATH Returns [] on unix
- spack.detection.path.dedupe_paths(paths: List[str]) List[str] [source]
Deduplicate paths based on inode and device number. In case the list contains first a symlink and then the directory it points to, the symlink is replaced with the directory path. This ensures that we pick for example
/usr/bin
over/bin
if the latter is a symlink to the former.
- spack.detection.path.executables_in_path(path_hints: List[str]) Dict[str, str] [source]
Get the paths of all executables available from the current PATH.
For convenience, this is constructed as a dictionary where the keys are the executable paths and the values are the names of the executables (i.e. the basename of the executable path).
There may be multiple paths with the same basename. In this case it is assumed there are two different instances of the executable.
- Parameters:
path_hints – list of paths to be searched. If None the list will be constructed based on the PATH environment variable.
- spack.detection.path.libraries_in_ld_and_system_library_path(path_hints: List[str] | None = None) Dict[str, str] [source]
Get the paths of all libraries available from
path_hints
or the following defaults:Environment variables (Linux:
LD_LIBRARY_PATH
, Darwin:DYLD_LIBRARY_PATH
, andDYLD_FALLBACK_LIBRARY_PATH
)Dynamic linker default paths (glibc: ld.so.conf, musl: ld-musl-<arch>.path)
Default system library paths.
For convenience, this is constructed as a dictionary where the keys are the library paths and the values are the names of the libraries (i.e. the basename of the library path).
There may be multiple paths with the same basename. In this case it is assumed there are two different instances of the library.
- Parameters:
path_hints (list) – list of paths to be searched. If None the list will be constructed based on the set of LD_LIBRARY_PATH, LIBRARY_PATH, DYLD_LIBRARY_PATH, and DYLD_FALLBACK_LIBRARY_PATH environment variables as well as the standard system library paths.
path_hints – list of paths to be searched. If
None
, the default system paths are used.
- spack.detection.path.libraries_in_windows_paths(path_hints: List[str] | None = None) Dict[str, str] [source]
Get the paths of all libraries available from the system PATH paths.
For more details, see libraries_in_ld_and_system_library_path regarding return type and contents.
- Parameters:
path_hints – list of paths to be searched. If None the list will be constructed based on the set of PATH environment variables as well as the standard system library paths.
spack.detection.test module
Create and run mock e2e tests for package detection.
- class spack.detection.test.DetectionTest(pkg_name: str, layout: List[MockExecutables], results: List[ExpectedTestResult])[source]
Bases:
NamedTuple
Data structure to construct detection tests by PATH inspection.
Packages may have a YAML file containing the description of one or more detection tests to be performed. Each test creates a few mock executable scripts in a temporary folder, and checks that detection by PATH gives the expected results.
- layout: List[MockExecutables]
Alias for field number 1
- results: List[ExpectedTestResult]
Alias for field number 2
- class spack.detection.test.ExpectedTestResult(spec: str, extra_attributes: Dict[str, str])[source]
Bases:
NamedTuple
Data structure to model assertions on detection tests
- class spack.detection.test.MockExecutables(executables: List[str], script: str)[source]
Bases:
NamedTuple
Mock executables to be used in detection tests
- class spack.detection.test.Runner(*, test: DetectionTest, repository: RepoPath)[source]
Bases:
object
Runs an external detection test
- spack.detection.test.detection_tests(pkg_name: str, repository: RepoPath) List[Runner] [source]
Returns a list of test runners for a given package.
Currently, detection tests are specified in a YAML file, called
detection_test.yaml
, alongside thepackage.py
file.This function reads that file to create a bunch of
Runner
objects.- Parameters:
pkg_name – name of the package to test
repository – repository where the package lives
- spack.detection.test.read_detection_tests(pkg_name: str, repository: RepoPath) Dict[str, Any] [source]
Returns the normalized content of the detection_tests.yaml associated with the package passed in input.
The content is merged with that of any package that is transitively included using the “includes” attribute.
- Parameters:
pkg_name – name of the package to test
repository – repository in which to search for packages