spack.environment package

Submodules

spack.environment.environment module

class spack.environment.environment.Environment(path, init_file=None, with_view=None, keep_relative=False)[source]

Bases: object

property active

True if this environment is currently active.

add(user_spec, list_name='specs')[source]

Add a single user_spec (non-concretized) to the Environment

Returns

True if the spec was added, False if it was already

present and did not need to be added

Return type

(bool)

add_default_view_to_env(env_mod)[source]

Collect the environment modifications to activate an environment using the default view. Removes duplicate paths.

Parameters

env_mod (spack.util.environment.EnvironmentModifications) – the environment modifications object that is modified.

added_specs()[source]

Specs that are not yet installed.

Yields the user spec for non-concretized specs, and the concrete spec for already concretized but not yet installed specs.

all_hashes()[source]

Return hashes of all specs.

all_specs()[source]

Return all specs, even those a user spec would shadow.

change_existing_spec(change_spec, list_name='specs', match_spec=None, allow_changing_multiple_specs=False)[source]

Find the spec identified by match_spec and change it to change_spec.

Parameters
  • change_spec (spack.spec.Spec) – defines the spec properties that need to be changed. This will not change attributes of the matched spec unless they conflict with change_spec.

  • list_name (str) – identifies the spec list in the environment that should be modified

  • match_spec (spack.spec.Spec) – if set, this identifies the spec that should be changed. If not set, it is assumed we are looking for a spec with the same name as change_spec.

check_views()[source]

Checks if the environments default view can be activated.

clear(re_read=False)[source]

Clear the contents of the environment

Parameters

re_read (bool) – If True, do not clear new_specs nor new_installs values. These values cannot be read from yaml, and need to be maintained when re-reading an existing environment.

concretize(force=False, tests=False)[source]

Concretize user_specs in this environment.

Only concretizes specs that haven’t been concretized yet unless force is True.

This only modifies the environment in memory. write() will write out a lockfile containing concretized specs.

Parameters
  • force (bool) – re-concretize ALL specs, even those that were already concretized

  • tests (bool or list or set) – False to run no tests, True to test all packages, or a list of package names to run tests for some

Returns

List of specs that have been concretized. Each entry is a tuple of the user spec and the corresponding concretized spec.

concretize_and_add(user_spec, concrete_spec=None, tests=False)[source]

Concretize and add a single spec to the environment.

Concretize the provided user_spec and add it along with the concretized result to the environment. If the given user_spec was already present in the environment, this does not add a duplicate. The concretized spec will be added unless the user_spec was already present and an associated concrete spec was already present.

Parameters

concrete_spec – if provided, then it is assumed that it is the result of concretizing the provided user_spec

concretized_specs()[source]

Tuples of (user spec, concrete spec) for all concrete specs.

config_scopes()[source]

A list of all configuration scopes for this environment.

property config_stage_dir

Directory for any staged configuration file(s).

property default_view
destroy()[source]

Remove this environment from Spack entirely.

develop(spec, path, clone=False)[source]

Add dev-build info for package

Parameters
  • spec (spack.spec.Spec) – Set constraints on development specs. Must include a concrete version.

  • path (str) – Path to find code for developer builds. Relative paths will be resolved relative to the environment.

  • clone (bool) – Clone the package code to the path. If clone is False Spack will assume the code is already present at path.

Returns

True iff the environment was changed.

Return type

(bool)

env_file_config_scope()[source]

Get the configuration scope for the environment’s manifest file.

env_file_config_scope_name()[source]

Name of the config scope of this environment’s manifest file.

property env_subdir_path

Path to directory where the env stores repos, logs, views.

get_by_hash(dag_hash)[source]
included_config_scopes()[source]

List of included configuration scopes from the environment.

Scopes are listed in the YAML file in order from highest to lowest precedence, so configuration from earlier scope will take precedence over later ones.

This routine returns them in the order they should be pushed onto the internal scope stack (so, in reverse, from lowest to highest).

install_all(**install_args)[source]

Install all concretized specs in an environment.

Note: this does not regenerate the views for the environment; that needs to be done separately with a call to write().

Parameters

install_args (dict) – keyword install arguments

install_specs(specs=None, **install_args)[source]
property internal

Whether this environment is managed by Spack.

is_develop(spec)[source]

Returns true when the spec is built from local sources

property lock_path

Path to spack.lock file in this environment.

property log_path
property manifest_path

Path to spack.yaml file in this environment.

matching_spec(spec)[source]

Given a spec (likely not concretized), find a matching concretized spec in the environment.

The matching spec does not have to be installed in the environment, but must be concrete (specs added with spack add without an intervening spack concretize will not be matched).

If there is a single root spec that matches the provided spec or a single dependency spec that matches the provided spec, then the concretized instance of that spec will be returned.

If multiple root specs match the provided spec, or no root specs match and multiple dependency specs match, then this raises an error and reports all matching specs.

property name

Human-readable representation of the environment.

This is the path for directory environments, and just the name for named environments.

regenerate_views()[source]
remove(query_spec, list_name='specs', force=False)[source]

Remove specs from an environment that match a query_spec

removed_specs()[source]

Tuples of (user spec, concrete spec) for all specs that will be removed on nexg concretize.

property repo
property repos_path
rm_default_view_from_env(env_mod)[source]

Collect the environment modifications to deactivate an environment using the default view. Reverses the action of add_default_view_to_env.

Parameters

env_mod (spack.util.environment.EnvironmentModifications) – the environment modifications object that is modified.

roots()[source]

Specs explicitly requested by the user in this environment.

Yields both added and installed specs that have user specs in spack.yaml.

undevelop(spec)[source]

Remove develop info for abstract spec spec.

returns True on success, False if no entry existed.

uninstalled_specs()[source]

Return root specs that are not installed, or are installed, but are development specs themselves or have those among their dependencies.

update_default_view(viewpath)[source]
update_stale_references(from_list=None)[source]

Iterate over spec lists updating references.

property user_specs
property view_path_default
write(regenerate=True)[source]

Writes an in-memory environment to its location on disk.

Write out package files for each newly concretized spec. Also regenerate any views associated with the environment and run post-write hooks, if regenerate is True.

Parameters

regenerate (bool) – regenerate views and run post-write hooks as well as writing if True.

write_transaction()[source]

Get a write lock context manager for use in a with block.

exception spack.environment.environment.SpackEnvironmentError(message, long_message=None)[source]

Bases: SpackError

Superclass for all errors to do with Spack environments.

exception spack.environment.environment.SpackEnvironmentViewError(message, long_message=None)[source]

Bases: SpackEnvironmentError

Class for errors regarding view generation.

class spack.environment.environment.ViewDescriptor(base_path, root, projections={}, select=[], exclude=[], link='all', link_type='symlink')[source]

Bases: object

content_hash(specs)[source]
exclude_fn(spec)[source]
static from_dict(base_path, d)[source]
get_projection_for_spec(spec)[source]

Get projection for spec relative to view root

Getting the projection from the underlying root will get the temporary projection. This gives the permanent projection relative to the root symlink.

regenerate(concretized_root_specs)[source]
select_fn(spec)[source]
specs_for_view(concretized_root_specs)[source]

From the list of concretized user specs in the environment, flatten the dags, and filter selected, installed specs, remove duplicates on dag hash.

to_dict()[source]
view(new=None)[source]

Generate the FilesystemView object for this ViewDescriptor

By default, this method returns a FilesystemView object rooted at the current underlying root of this ViewDescriptor (self._current_root)

Raise if new is None and there is no current view

Parameters

new (str or None) – If a string, create a FilesystemView rooted at that path. Default None. This should only be used to regenerate the view, and cannot be used to access specs.

spack.environment.environment.activate(env, use_env_repo=False)[source]

Activate an environment.

To activate an environment, we add its configuration scope to the existing Spack configuration, and we set active to the current environment.

Parameters
  • env (Environment) – the environment to activate

  • use_env_repo (bool) – use the packages exactly as they appear in the environment’s repository

spack.environment.environment.active(name)[source]

True if the named environment is active.

spack.environment.environment.active_environment()[source]

Returns the active environment when there is any

spack.environment.environment.all_environment_names()[source]

List the names of environments that currently exist.

spack.environment.environment.all_environments()[source]

Generator for all named Environments.

spack.environment.environment.config_dict(yaml_data)[source]

Get the configuration scope section out of an spack.yaml

spack.environment.environment.create(name, init_file=None, with_view=None, keep_relative=False)[source]

Create a named environment in Spack.

spack.environment.environment.deactivate()[source]

Undo any configuration or repo settings modified by activate().

spack.environment.environment.deactivate_config_scope(env)[source]

Remove any scopes from env from the global config path.

spack.environment.environment.default_manifest_yaml()[source]

default spack.yaml file to put in new environments

spack.environment.environment.display_specs(concretized_specs)[source]

Displays the list of specs returned by Environment.concretize().

Parameters

concretized_specs (list) – list of specs returned by Environment.concretize()

spack.environment.environment.env_path = '/home/docs/checkouts/readthedocs.org/user_builds/spack/checkouts/latest/lib/spack/docs/_spack_root/var/spack/environments'

path where environments are stored in the spack tree

spack.environment.environment.env_subdir_name = '.spack-env'

Name of the directory where environments store repos, logs, views

spack.environment.environment.exists(name)[source]

Whether an environment with this name exists or not.

spack.environment.environment.installed_specs()[source]

Returns the specs of packages installed in the active environment or None if no packages are installed.

spack.environment.environment.is_env_dir(path)[source]

Whether a directory contains a spack environment.

spack.environment.environment.is_latest_format(manifest)[source]

Return False if the manifest file exists and is not in the latest schema format.

Parameters

manifest (str) – manifest file to be analyzed

spack.environment.environment.lockfile_format_version = 4

version of the lockfile format. Must increase monotonically.

spack.environment.environment.lockfile_name = 'spack.lock'

Name of the input yaml file for an environment

spack.environment.environment.make_repo_path(root)[source]

Make a RepoPath from the repo subdirectories in an environment.

spack.environment.environment.manifest_file(env_name_or_dir)[source]

Return the absolute path to a manifest file given the environment name or directory.

Parameters

env_name_or_dir (str) – either the name of a valid environment or a directory where a manifest file resides

Raises

AssertionError – if the environment is not found

spack.environment.environment.manifest_name = 'spack.yaml'

Name of the input yaml file for an environment

spack.environment.environment.no_active_environment()[source]

Deactivate the active environment for the duration of the context. Has no effect when there is no active environment.

spack.environment.environment.prepare_config_scope(env)[source]

Add env’s scope to the global configuration search path.

spack.environment.environment.read(name)[source]

Get an environment with the supplied name.

spack.environment.environment.root(name)[source]

Get the root directory for an environment by name.

spack.environment.environment.spack_env_var = 'SPACK_ENV'

environment variable used to indicate the active environment

spack.environment.environment.update_yaml(manifest, backup_file)[source]

Update a manifest file from an old format to the current one.

Parameters
  • manifest (str) – path to a manifest file

  • backup_file (str) – file where to copy the original manifest

Returns

True if the manifest was updated, False otherwise.

Raises

AssertionError – in case anything goes wrong during the update

spack.environment.environment.valid_env_name(name)[source]
spack.environment.environment.valid_environment_name_re = '^\\w[\\w-]*$'

regex for validating enviroment names

spack.environment.environment.validate_env_name(name)[source]
spack.environment.environment.yaml_equivalent(first, second)[source]

Returns whether two spack yaml items are equivalent, including overrides

spack.environment.shell module

spack.environment.shell.activate(env, use_env_repo=False, add_view=True)[source]

Activate an environment and append environment modifications

To activate an environment, we add its configuration scope to the existing Spack configuration, and we set active to the current environment.

Parameters
  • env (spack.environment.Environment) – the environment to activate

  • use_env_repo (bool) – use the packages exactly as they appear in the environment’s repository

  • add_view (bool) – generate commands to add view to path variables

Returns

Environment variables modifications to activate environment.

Return type

spack.util.environment.EnvironmentModifications

spack.environment.shell.activate_header(env, shell, prompt=None)[source]
spack.environment.shell.deactivate()[source]

Deactivate an environment and collect corresponding environment modifications.

Note: unloads the environment in its current state, not in the state it was

loaded in, meaning that specs that were removed from the spack environment after activation are not unloaded.

Returns

Environment variables modifications to activate environment.

Return type

spack.util.environment.EnvironmentModifications

spack.environment.shell.deactivate_header(shell)[source]

Module contents

This package implements Spack environments.

spack.lock format

Spack environments have existed since Spack v0.12.0, and there have been 4 different spack.lock formats since then. The formats are documented here.

The high-level format of a Spack lockfile hasn’t changed much between versions, but the contents have. Lockfiles are JSON-formatted and their top-level sections are:

  1. _meta (object): this contains deatails about the file format, including:
    • file-type: always "spack-lockfile"

    • lockfile-version: an integer representing the lockfile format version

    • specfile-version: an integer representing the spec format version (since v0.17)

  2. roots (list): an ordered list of records representing the roots of the Spack

    environment. Each has two fields: * hash: a Spack spec hash uniquely identifying the concrete root spec * spec: a string representation of the abstract spec that was concretized

  1. concrete_specs: a dictionary containing the specs in the environment.

Compatibility

New versions of Spack can (so far) read all old lockfile formats – they are backward-compatible. Old versions cannot read new lockfile formats, and you’ll need to upgrade Spack to use them.

Lockfile version compatibility across Spack versions

Spack version

v1

v2

v3

v4

v0.12:0.14

v0.15:0.16

v0.17

v0.18:

Version 1

When lockfiles were first created, there was only one hash in Spack: the DAG hash. This DAG hash (we’ll call it the old DAG hash) did not include build dependencies – it only included transitive link and run dependencies.

The spec format at this time was keyed by name. Each spec started with a key for its name, whose value was a dictionary of other spec attributes. The lockfile put these name-keyed specs into dictionaries keyed by their DAG hash, and the spec records did not actually have a “hash” field in the lockfile – you have to associate the hash from the key with the spec record after the fact.

Dependencies in original lockfiles were keyed by "hash", i.e. the old DAG hash.

{
    "_meta": {
        "file-type": "spack-lockfile",
        "lockfile-version": 1
    },
    "roots": [
        {
            "hash": "<old_dag_hash 1>",
            "spec": "<abstract spec 1>"
        },
        {
            "hash": "<old_dag_hash 2>",
            "spec": "<abstract spec 2>"
        }
    ],
    "concrete_specs": {
        "<old_dag_hash 1>": {
            "... <spec dict attributes> ...": { },
            "dependencies": {
                "depname_1": {
                    "hash": "<old_dag_hash for depname_1>",
                    "type": ["build", "link"]
                },
                "depname_2": {
                    "hash": "<old_dag_hash for depname_3>",
                    "type": ["build", "link"]
                }
            },
            "hash": "<old_dag_hash 1>"
        },
        "<old_dag_hash 2>": {
            "... <spec dict attributes> ...": { },
            "dependencies": {
                "depname_3": {
                    "hash": "<old_dag_hash for depname_3>",
                    "type": ["build", "link"]
                },
                "depname_4": {
                    "hash": "<old_dag_hash for depname_4>",
                    "type": ["build", "link"]
                },
            },
            "hash": "<old_dag_hash 2>"
        },
    }
}

Version 2

Version 2 changes one thing: specs in the lockfile are now keyed by build_hash instead of the old dag_hash. Specs have a hash attribute with their real DAG hash, so you can’t go by the dictionary key anymore to identify a spec – you have to read it in and look at "hash". Dependencies are still keyed by old DAG hash.

Even though we key lockfiles by build_hash, specs in Spack were still deployed with the old, coarser DAG hash. This means that in v2 and v3 lockfiles (which are keyed by build hash), there may be multiple versions of the same spec with different build dependencies, which means they will have different build hashes but the same DAG hash. Spack would only have been able to actually install one of these.

{
    "_meta": {
        "file-type": "spack-lockfile",
        "lockfile-version": 2
    },
    "roots": [
        {
            "hash": "<build_hash 1>",
            "spec": "<abstract spec 1>"
        },
        {
            "hash": "<build_hash 2>",
            "spec": "<abstract spec 2>"
        }
    ],
    "concrete_specs": {
        "<build_hash 1>": {
            "... <spec dict attributes> ...": { },
            "dependencies": {
                "depname_1": {
                    "hash": "<old_dag_hash for depname_1>",
                    "type": ["build", "link"]
                },
                "depname_2": {
                    "hash": "<old_dag_hash for depname_3>",
                    "type": ["build", "link"]
                }
            },
            "hash": "<old_dag_hash 1>",
        },
        "<build_hash 2>": {
            "... <spec dict attributes> ...": { },
            "dependencies": {
                "depname_3": {
                    "hash": "<old_dag_hash for depname_3>",
                    "type": ["build", "link"]
                },
                "depname_4": {
                    "hash": "<old_dag_hash for depname_4>",
                    "type": ["build", "link"]
                }
            },
            "hash": "<old_dag_hash 2>"
        }
    }
}

Version 3

Version 3 doesn’t change the top-level lockfile format, but this was when we changed the specfile format. Specs in concrete_specs are now keyed by the build hash, with no inner dictionary keyed by their package name. The package name is in a name field inside each spec dictionary. The dependencies field in the specs is a list instead of a dictionary, and each element of the list is a record with the name, dependency types, and hash of the dependency. Instead of a key called hash, dependencies are keyed by build_hash. Each spec still has a hash attribute.

Version 3 adds the specfile_version field to _meta and uses the new JSON spec format.

{
    "_meta": {
        "file-type": "spack-lockfile",
        "lockfile-version": 3,
        "specfile-version": 2
    },
    "roots": [
        {
            "hash": "<build_hash 1>",
            "spec": "<abstract spec 1>"
        },
        {
            "hash": "<build_hash 2>",
            "spec": "<abstract spec 2>"
        },
    ],
    "concrete_specs": {
        "<build_hash 1>": {
            "... <spec dict attributes> ...": { },
            "dependencies": [
                {
                    "name": "depname_1",
                    "build_hash": "<build_hash for depname_1>",
                    "type": ["build", "link"]
                },
                {
                    "name": "depname_2",
                    "build_hash": "<build_hash for depname_2>",
                    "type": ["build", "link"]
                },
            ],
            "hash": "<old_dag_hash 1>",
        },
        "<build_hash 2>": {
            "... <spec dict attributes> ...": { },
            "dependencies": [
                {
                    "name": "depname_3",
                    "build_hash": "<build_hash for depname_3>",
                    "type": ["build", "link"]
                },
                {
                    "name": "depname_4",
                    "build_hash": "<build_hash for depname_4>",
                    "type": ["build", "link"]
                },
            ],
            "hash": "<old_dag_hash 2>"
        }
    }
}

Version 4

Version 4 removes build hashes and is keyed by the new DAG hash (hash). The hash now includes build dependencies and a canonical hash of the package.py file. Dependencies are keyed by hash (DAG hash) as well. There are no more build_hash fields in the specs, and there are no more issues with lockfiles being able to store multiple specs with the same DAG hash (because the DAG hash is now finer-grained).

{
    "_meta": {
        "file-type": "spack-lockfile",
        "lockfile-version": 3,
        "specfile-version": 2
    },
    "roots": [
        {
            "hash": "<dag_hash 1>",
            "spec": "<abstract spec 1>"
        },
        {
            "hash": "<dag_hash 2>",
            "spec": "<abstract spec 2>"
        }
    ],
    "concrete_specs": {
        "<dag_hash 1>": {
            "... <spec dict attributes> ...": { },
            "dependencies": [
                {
                    "name": "depname_1",
                    "hash": "<dag_hash for depname_1>",
                    "type": ["build", "link"]
                },
                {
                    "name": "depname_2",
                    "hash": "<dag_hash for depname_2>",
                    "type": ["build", "link"]
                }
            ],
            "hash": "<dag_hash 1>",
        },
        "<daghash 2>": {
            "... <spec dict attributes> ...": { },
            "dependencies": [
                {
                    "name": "depname_3",
                    "hash": "<dag_hash for depname_3>",
                    "type": ["build", "link"]
                },
                {
                    "name": "depname_4",
                    "hash": "<dag_hash for depname_4>",
                    "type": ["build", "link"]
                }
            ],
            "hash": "<dag_hash 2>"
        }
    }
}
class spack.environment.Environment(path, init_file=None, with_view=None, keep_relative=False)[source]

Bases: object

property active

True if this environment is currently active.

add(user_spec, list_name='specs')[source]

Add a single user_spec (non-concretized) to the Environment

Returns

True if the spec was added, False if it was already

present and did not need to be added

Return type

(bool)

add_default_view_to_env(env_mod)[source]

Collect the environment modifications to activate an environment using the default view. Removes duplicate paths.

Parameters

env_mod (spack.util.environment.EnvironmentModifications) – the environment modifications object that is modified.

added_specs()[source]

Specs that are not yet installed.

Yields the user spec for non-concretized specs, and the concrete spec for already concretized but not yet installed specs.

all_hashes()[source]

Return hashes of all specs.

all_specs()[source]

Return all specs, even those a user spec would shadow.

change_existing_spec(change_spec, list_name='specs', match_spec=None, allow_changing_multiple_specs=False)[source]

Find the spec identified by match_spec and change it to change_spec.

Parameters
  • change_spec (spack.spec.Spec) – defines the spec properties that need to be changed. This will not change attributes of the matched spec unless they conflict with change_spec.

  • list_name (str) – identifies the spec list in the environment that should be modified

  • match_spec (spack.spec.Spec) – if set, this identifies the spec that should be changed. If not set, it is assumed we are looking for a spec with the same name as change_spec.

check_views()[source]

Checks if the environments default view can be activated.

clear(re_read=False)[source]

Clear the contents of the environment

Parameters

re_read (bool) – If True, do not clear new_specs nor new_installs values. These values cannot be read from yaml, and need to be maintained when re-reading an existing environment.

concretize(force=False, tests=False)[source]

Concretize user_specs in this environment.

Only concretizes specs that haven’t been concretized yet unless force is True.

This only modifies the environment in memory. write() will write out a lockfile containing concretized specs.

Parameters
  • force (bool) – re-concretize ALL specs, even those that were already concretized

  • tests (bool or list or set) – False to run no tests, True to test all packages, or a list of package names to run tests for some

Returns

List of specs that have been concretized. Each entry is a tuple of the user spec and the corresponding concretized spec.

concretize_and_add(user_spec, concrete_spec=None, tests=False)[source]

Concretize and add a single spec to the environment.

Concretize the provided user_spec and add it along with the concretized result to the environment. If the given user_spec was already present in the environment, this does not add a duplicate. The concretized spec will be added unless the user_spec was already present and an associated concrete spec was already present.

Parameters

concrete_spec – if provided, then it is assumed that it is the result of concretizing the provided user_spec

concretized_specs()[source]

Tuples of (user spec, concrete spec) for all concrete specs.

config_scopes()[source]

A list of all configuration scopes for this environment.

property config_stage_dir

Directory for any staged configuration file(s).

property default_view
destroy()[source]

Remove this environment from Spack entirely.

develop(spec, path, clone=False)[source]

Add dev-build info for package

Parameters
  • spec (spack.spec.Spec) – Set constraints on development specs. Must include a concrete version.

  • path (str) – Path to find code for developer builds. Relative paths will be resolved relative to the environment.

  • clone (bool) – Clone the package code to the path. If clone is False Spack will assume the code is already present at path.

Returns

True iff the environment was changed.

Return type

(bool)

env_file_config_scope()[source]

Get the configuration scope for the environment’s manifest file.

env_file_config_scope_name()[source]

Name of the config scope of this environment’s manifest file.

property env_subdir_path

Path to directory where the env stores repos, logs, views.

get_by_hash(dag_hash)[source]
included_config_scopes()[source]

List of included configuration scopes from the environment.

Scopes are listed in the YAML file in order from highest to lowest precedence, so configuration from earlier scope will take precedence over later ones.

This routine returns them in the order they should be pushed onto the internal scope stack (so, in reverse, from lowest to highest).

install_all(**install_args)[source]

Install all concretized specs in an environment.

Note: this does not regenerate the views for the environment; that needs to be done separately with a call to write().

Parameters

install_args (dict) – keyword install arguments

install_specs(specs=None, **install_args)[source]
property internal

Whether this environment is managed by Spack.

is_develop(spec)[source]

Returns true when the spec is built from local sources

property lock_path

Path to spack.lock file in this environment.

property log_path
property manifest_path

Path to spack.yaml file in this environment.

matching_spec(spec)[source]

Given a spec (likely not concretized), find a matching concretized spec in the environment.

The matching spec does not have to be installed in the environment, but must be concrete (specs added with spack add without an intervening spack concretize will not be matched).

If there is a single root spec that matches the provided spec or a single dependency spec that matches the provided spec, then the concretized instance of that spec will be returned.

If multiple root specs match the provided spec, or no root specs match and multiple dependency specs match, then this raises an error and reports all matching specs.

property name

Human-readable representation of the environment.

This is the path for directory environments, and just the name for named environments.

regenerate_views()[source]
remove(query_spec, list_name='specs', force=False)[source]

Remove specs from an environment that match a query_spec

removed_specs()[source]

Tuples of (user spec, concrete spec) for all specs that will be removed on nexg concretize.

property repo
property repos_path
rm_default_view_from_env(env_mod)[source]

Collect the environment modifications to deactivate an environment using the default view. Reverses the action of add_default_view_to_env.

Parameters

env_mod (spack.util.environment.EnvironmentModifications) – the environment modifications object that is modified.

roots()[source]

Specs explicitly requested by the user in this environment.

Yields both added and installed specs that have user specs in spack.yaml.

undevelop(spec)[source]

Remove develop info for abstract spec spec.

returns True on success, False if no entry existed.

uninstalled_specs()[source]

Return root specs that are not installed, or are installed, but are development specs themselves or have those among their dependencies.

update_default_view(viewpath)[source]
update_stale_references(from_list=None)[source]

Iterate over spec lists updating references.

property user_specs
property view_path_default
write(regenerate=True)[source]

Writes an in-memory environment to its location on disk.

Write out package files for each newly concretized spec. Also regenerate any views associated with the environment and run post-write hooks, if regenerate is True.

Parameters

regenerate (bool) – regenerate views and run post-write hooks as well as writing if True.

write_transaction()[source]

Get a write lock context manager for use in a with block.

exception spack.environment.SpackEnvironmentError(message, long_message=None)[source]

Bases: SpackError

Superclass for all errors to do with Spack environments.

exception spack.environment.SpackEnvironmentViewError(message, long_message=None)[source]

Bases: SpackEnvironmentError

Class for errors regarding view generation.

spack.environment.activate(env, use_env_repo=False)[source]

Activate an environment.

To activate an environment, we add its configuration scope to the existing Spack configuration, and we set active to the current environment.

Parameters
  • env (Environment) – the environment to activate

  • use_env_repo (bool) – use the packages exactly as they appear in the environment’s repository

spack.environment.active(name)[source]

True if the named environment is active.

spack.environment.active_environment()[source]

Returns the active environment when there is any

spack.environment.all_environment_names()[source]

List the names of environments that currently exist.

spack.environment.all_environments()[source]

Generator for all named Environments.

spack.environment.config_dict(yaml_data)[source]

Get the configuration scope section out of an spack.yaml

spack.environment.create(name, init_file=None, with_view=None, keep_relative=False)[source]

Create a named environment in Spack.

spack.environment.deactivate()[source]

Undo any configuration or repo settings modified by activate().

spack.environment.default_manifest_yaml()[source]

default spack.yaml file to put in new environments

spack.environment.display_specs(concretized_specs)[source]

Displays the list of specs returned by Environment.concretize().

Parameters

concretized_specs (list) – list of specs returned by Environment.concretize()

spack.environment.exists(name)[source]

Whether an environment with this name exists or not.

spack.environment.installed_specs()[source]

Returns the specs of packages installed in the active environment or None if no packages are installed.

spack.environment.is_env_dir(path)[source]

Whether a directory contains a spack environment.

spack.environment.is_latest_format(manifest)[source]

Return False if the manifest file exists and is not in the latest schema format.

Parameters

manifest (str) – manifest file to be analyzed

spack.environment.manifest_file(env_name_or_dir)[source]

Return the absolute path to a manifest file given the environment name or directory.

Parameters

env_name_or_dir (str) – either the name of a valid environment or a directory where a manifest file resides

Raises

AssertionError – if the environment is not found

spack.environment.no_active_environment()[source]

Deactivate the active environment for the duration of the context. Has no effect when there is no active environment.

spack.environment.read(name)[source]

Get an environment with the supplied name.

spack.environment.root(name)[source]

Get the root directory for an environment by name.

spack.environment.update_yaml(manifest, backup_file)[source]

Update a manifest file from an old format to the current one.

Parameters
  • manifest (str) – path to a manifest file

  • backup_file (str) – file where to copy the original manifest

Returns

True if the manifest was updated, False otherwise.

Raises

AssertionError – in case anything goes wrong during the update