spack.detection package

class spack.detection.DetectedPackage(spec: Spec, prefix: str)[source]

Bases: NamedTuple

Information on a package that has been detected.

prefix: str

Prefix of the spec

static restore(spec_str: str, prefix: str, extra_attributes: Dict[str, str] | None) DetectedPackage[source]
spec: Spec

Spec that was detected

spack.detection.by_path(packages_to_search: List[str], *, path_hints: List[str] | None = None, max_workers: int | None = None) Dict[str, List[DetectedPackage]][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 the package.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.update_configuration(detected_packages: Dict[str, List[DetectedPackage]], scope: str | None = None, buildable: bool = True) List[Spec][source]

Add the packages passed as arguments to packages.yaml

Parameters:
  • detected_packages – list of DetectedPackage objects 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 DetectedPackage objects. 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.DetectedPackage(spec: Spec, prefix: str)[source]

Bases: NamedTuple

Information on a package that has been detected.

prefix: str

Prefix of the spec

static restore(spec_str: str, prefix: str, extra_attributes: Dict[str, str] | None) DetectedPackage[source]
spec: Spec

Spec that was detected

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

static find_windows_compiler_ninja_paths() List[str][source]

Semi hard-coded search heuristic for locating ninja bundled with MSVC

static find_windows_compiler_root_paths() List[str][source]

Helper for Windows compiler installation root discovery

At the moment simply returns location of VS install paths from VSWhere But should be extended to include more information as relevant

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

static find_windows_kit_lib_paths(kit_base: str | None | list = None) List[str][source]

Returns Windows kit lib directory per version

static find_windows_kit_reg_installed_roots_paths() List[str][source]
static find_windows_kit_reg_sdk_paths() List[str][source]
static find_windows_kit_roots() List[str][source]

Return Windows kit root, typically %programfiles%Windows Kits10|11

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])[source]

Return dictionary[fullpath]: basename from list of paths

spack.detection.common.update_configuration(detected_packages: Dict[str, List[DetectedPackage]], scope: str | None = None, buildable: bool = True) List[Spec][source]

Add the packages passed as arguments to packages.yaml

Parameters:
  • detected_packages – list of DetectedPackage objects 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

default_path_hints() List[str][source]
prefix_from_path(*, path: str) str[source]

Given a path where a file was found, returns the corresponding prefix.

Parameters:

path – path of a detected file

search_patterns(*, pkg: PackageBase) List[str][source]

Returns the list of patterns used to match candidate files.

Parameters:

pkg – package being detected

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

default_path_hints() List[str][source]
detect_specs(*, pkg: PackageBase, paths: List[str]) List[DetectedPackage][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, initial_guess: List[str] | None = None) List[DetectedPackage][source]

For a given package, returns a list of detected specs.

Parameters:
  • pkg_name – package being detected

  • 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.

prefix_from_path(*, path: str) str[source]

Given a path where a file was found, returns the corresponding prefix.

Parameters:

path – path of a detected file

search_patterns(*, pkg: PackageBase) List[str][source]

Returns the list of patterns used to match candidate files.

Parameters:

pkg – package being detected

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

prefix_from_path(*, path: str) str[source]

Given a path where a file was found, returns the corresponding prefix.

Parameters:

path – path of a detected file

search_patterns(*, pkg: PackageBase) List[str][source]

Returns the list of patterns used to match candidate files.

Parameters:

pkg – package being detected

spack.detection.path.accept_elf(path, host_compat)[source]

Accept an ELF file if the header matches the given compat triplet, obtained with get_elf_compat(). 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: List[str], *, path_hints: List[str] | None = None, max_workers: int | None = None) Dict[str, List[DetectedPackage]][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.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.file_identifier(path)[source]
spack.detection.path.get_elf_compat(path)[source]

For ELF files, get a triplet (EI_CLASS, EI_DATA, e_machine) and see if it is host-compatible.

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, and DYLD_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

pkg_name: str

Alias for field number 0

results: List[ExpectedTestResult]

Alias for field number 2

class spack.detection.test.ExpectedTestResult(spec: str)[source]

Bases: NamedTuple

Data structure to model assertions on detection tests

spec: str

Spec to be detected

class spack.detection.test.MockExecutables(executables: List[str], script: str)[source]

Bases: NamedTuple

Mock executables to be used in detection tests

executables: List[str]

Relative paths for mock executables to be created

script: str

Shell script for the mock executable

class spack.detection.test.Runner(*, test: DetectionTest, repository: RepoPath)[source]

Bases: object

Runs an external detection test

execute() List[Spec][source]

Executes a test and returns the specs that have been detected.

This function sets-up a test in a temporary directory, according to the prescriptions in the test layout, then performs a detection by executables and returns the specs that have been detected.

property expected_specs: List[Spec]
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 the package.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