Deprecate env: as top level environment key (#37424)

This commit is contained in:
Massimiliano Culpo 2023-05-04 13:08:29 +02:00 committed by GitHub
parent e5dcaebd43
commit cf5daff6f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 61 deletions

View File

@ -357,7 +357,14 @@ def ensure_env_root_path_exists():
def config_dict(yaml_data): def config_dict(yaml_data):
"""Get the configuration scope section out of an spack.yaml""" """Get the configuration scope section out of an spack.yaml"""
# TODO (env:): Remove env: as a possible top level keyword in v0.21
key = spack.config.first_existing(yaml_data, spack.schema.env.keys) key = spack.config.first_existing(yaml_data, spack.schema.env.keys)
if key == "env":
msg = (
"using 'env:' as a top-level attribute of a Spack environment is deprecated and "
"will be removed in Spack v0.21. Please use 'spack:' instead."
)
warnings.warn(msg)
return yaml_data[key] return yaml_data[key]

View File

@ -193,7 +193,7 @@ def test_dev_build_env(tmpdir, mock_packages, install_mockery, mutable_mock_env_
with open("spack.yaml", "w") as f: with open("spack.yaml", "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- dev-build-test-install@0.0.0 - dev-build-test-install@0.0.0
@ -233,7 +233,7 @@ def test_dev_build_env_version_mismatch(
with open("spack.yaml", "w") as f: with open("spack.yaml", "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- dev-build-test-install@0.0.0 - dev-build-test-install@0.0.0
@ -286,7 +286,7 @@ def test_dev_build_multiple(
with open("spack.yaml", "w") as f: with open("spack.yaml", "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- dev-build-test-dependent@0.0.0 - dev-build-test-dependent@0.0.0
@ -339,7 +339,7 @@ def test_dev_build_env_dependency(
with open("spack.yaml", "w") as f: with open("spack.yaml", "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- dependent-of-dev-build@0.0.0 - dependent-of-dev-build@0.0.0
@ -397,7 +397,7 @@ def reset_string():
with open("spack.yaml", "w") as f: with open("spack.yaml", "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- %s@0.0.0 - %s@0.0.0

View File

@ -342,7 +342,7 @@ def test_env_install_two_specs_same_dep(install_mockery, mock_fetch, tmpdir, cap
with open(str(path), "w") as f: with open(str(path), "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- a - a
- depb - depb
@ -522,7 +522,7 @@ def test_user_removed_spec(environment_from_manifest):
"""Ensure a user can remove from any position in the spack.yaml file.""" """Ensure a user can remove from any position in the spack.yaml file."""
before = environment_from_manifest( before = environment_from_manifest(
"""\ """\
env: spack:
specs: specs:
- mpileaks - mpileaks
- hypre - hypre
@ -536,7 +536,7 @@ def test_user_removed_spec(environment_from_manifest):
with open(before.manifest_path, "w") as f: with open(before.manifest_path, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- mpileaks - mpileaks
- libelf - libelf
@ -557,7 +557,7 @@ def test_init_from_lockfile(environment_from_manifest):
"""Test that an environment can be instantiated from a lockfile.""" """Test that an environment can be instantiated from a lockfile."""
e1 = environment_from_manifest( e1 = environment_from_manifest(
""" """
env: spack:
specs: specs:
- mpileaks - mpileaks
- hypre - hypre
@ -584,7 +584,7 @@ def test_init_from_yaml(environment_from_manifest):
"""Test that an environment can be instantiated from a lockfile.""" """Test that an environment can be instantiated from a lockfile."""
e1 = environment_from_manifest( e1 = environment_from_manifest(
""" """
env: spack:
specs: specs:
- mpileaks - mpileaks
- hypre - hypre
@ -615,7 +615,7 @@ def test_env_view_external_prefix(tmp_path, mutable_database, mock_packages):
manifest_file = manifest_dir / ev.manifest_name manifest_file = manifest_dir / ev.manifest_name
manifest_file.write_text( manifest_file.write_text(
""" """
env: spack:
specs: specs:
- a - a
view: true view: true
@ -663,7 +663,7 @@ def test_init_with_file_and_remove(tmpdir):
with open(str(path), "w") as f: with open(str(path), "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- mpileaks - mpileaks
""" """
@ -686,7 +686,7 @@ def test_init_with_file_and_remove(tmpdir):
def test_env_with_config(environment_from_manifest): def test_env_with_config(environment_from_manifest):
e = environment_from_manifest( e = environment_from_manifest(
""" """
env: spack:
specs: specs:
- mpileaks - mpileaks
packages: packages:
@ -723,7 +723,7 @@ def test_with_config_bad_include(environment_from_manifest):
def test_env_with_include_config_files_same_basename(environment_from_manifest): def test_env_with_include_config_files_same_basename(environment_from_manifest):
e = environment_from_manifest( e = environment_from_manifest(
""" """
env: spack:
include: include:
- ./path/to/included-config.yaml - ./path/to/included-config.yaml
- ./second/path/to/include-config.yaml - ./second/path/to/include-config.yaml
@ -781,7 +781,7 @@ def mpileaks_env_config(include_path):
"""Return the contents of an environment that includes the provided """Return the contents of an environment that includes the provided
path and lists mpileaks as the sole spec.""" path and lists mpileaks as the sole spec."""
return """\ return """\
env: spack:
include: include:
- {0} - {0}
specs: specs:
@ -798,7 +798,7 @@ def test_env_with_included_config_file(environment_from_manifest, packages_file)
include_filename = "included-config.yaml" include_filename = "included-config.yaml"
e = environment_from_manifest( e = environment_from_manifest(
f"""\ f"""\
env: spack:
include: include:
- {os.path.join(".", include_filename)} - {os.path.join(".", include_filename)}
specs: specs:
@ -892,7 +892,7 @@ def test_env_with_included_config_var_path(environment_from_manifest, packages_f
def test_env_config_precedence(environment_from_manifest): def test_env_config_precedence(environment_from_manifest):
e = environment_from_manifest( e = environment_from_manifest(
""" """
env: spack:
packages: packages:
libelf: libelf:
version: [0.8.12] version: [0.8.12]
@ -926,7 +926,7 @@ def test_env_config_precedence(environment_from_manifest):
def test_included_config_precedence(environment_from_manifest): def test_included_config_precedence(environment_from_manifest):
e = environment_from_manifest( e = environment_from_manifest(
""" """
env: spack:
include: include:
- ./high-config.yaml # this one should take precedence - ./high-config.yaml # this one should take precedence
- ./low-config.yaml - ./low-config.yaml
@ -968,7 +968,7 @@ def test_bad_env_yaml_format(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
spacks: spacks:
- mpileaks - mpileaks
""" """
@ -1268,7 +1268,7 @@ def test_env_config_view_default(
# This config doesn't mention whether a view is enabled # This config doesn't mention whether a view is enabled
environment_from_manifest( environment_from_manifest(
""" """
env: spack:
specs: specs:
- mpileaks - mpileaks
""" """
@ -1377,7 +1377,7 @@ def test_stack_yaml_definitions(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
specs: specs:
@ -1397,7 +1397,7 @@ def test_stack_yaml_definitions_as_constraints(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
- mpis: [mpich, openmpi] - mpis: [mpich, openmpi]
@ -1422,7 +1422,7 @@ def test_stack_yaml_definitions_as_constraints_on_matrix(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
- mpis: - mpis:
@ -1451,7 +1451,7 @@ def test_stack_yaml_definitions_write_reference(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
- indirect: [$packages] - indirect: [$packages]
@ -1475,7 +1475,7 @@ def test_stack_yaml_add_to_list(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
specs: specs:
@ -1499,7 +1499,7 @@ def test_stack_yaml_remove_from_list(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
specs: specs:
@ -1522,7 +1522,7 @@ def test_stack_yaml_remove_from_list_force(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
specs: specs:
@ -1551,7 +1551,7 @@ def test_stack_yaml_remove_from_matrix_no_effect(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: - packages:
- matrix: - matrix:
@ -1576,7 +1576,7 @@ def test_stack_yaml_force_remove_from_matrix(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: - packages:
- matrix: - matrix:
@ -1618,7 +1618,7 @@ def test_stack_concretize_extraneous_deps(tmpdir, config, mock_packages):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
- install: - install:
@ -1650,7 +1650,7 @@ def test_stack_concretize_extraneous_variants(tmpdir, config, mock_packages):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
- install: - install:
@ -1682,7 +1682,7 @@ def test_stack_concretize_extraneous_variants_with_dash(tmpdir, config, mock_pac
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
- install: - install:
@ -1710,7 +1710,7 @@ def test_stack_definition_extension(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
- packages: [callpath] - packages: [callpath]
@ -1733,7 +1733,7 @@ def test_stack_definition_conditional_false(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
- packages: [callpath] - packages: [callpath]
@ -1757,7 +1757,7 @@ def test_stack_definition_conditional_true(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
- packages: [callpath] - packages: [callpath]
@ -1781,7 +1781,7 @@ def test_stack_definition_conditional_with_variable(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
- packages: [callpath] - packages: [callpath]
@ -1805,7 +1805,7 @@ def test_stack_definition_conditional_with_satisfaction(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
when: arch.satisfies('platform=foo') # will be "test" when testing when: arch.satisfies('platform=foo') # will be "test" when testing
@ -1830,7 +1830,7 @@ def test_stack_definition_complex_conditional(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
- packages: [callpath] - packages: [callpath]
@ -1854,7 +1854,7 @@ def test_stack_definition_conditional_invalid_variable(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
- packages: [callpath] - packages: [callpath]
@ -1873,7 +1873,7 @@ def test_stack_definition_conditional_add_write(tmpdir):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [libelf, mpileaks] - packages: [libelf, mpileaks]
- packages: [callpath] - packages: [callpath]
@ -1890,7 +1890,7 @@ def test_stack_definition_conditional_add_write(tmpdir):
test = ev.read("test") test = ev.read("test")
packages_lists = list( packages_lists = list(
filter(lambda x: "packages" in x, test.manifest["env"]["definitions"]) filter(lambda x: "packages" in x, test.manifest["spack"]["definitions"])
) )
assert len(packages_lists) == 2 assert len(packages_lists) == 2
@ -1908,7 +1908,7 @@ def test_stack_combinatorial_view(
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang'] - compilers: ['%%gcc', '%%clang']
@ -1942,7 +1942,7 @@ def test_stack_view_select(tmpdir, mock_fetch, mock_packages, mock_archive, inst
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang'] - compilers: ['%%gcc', '%%clang']
@ -1982,7 +1982,7 @@ def test_stack_view_exclude(tmpdir, mock_fetch, mock_packages, mock_archive, ins
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang'] - compilers: ['%%gcc', '%%clang']
@ -2024,7 +2024,7 @@ def test_stack_view_select_and_exclude(
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang'] - compilers: ['%%gcc', '%%clang']
@ -2065,7 +2065,7 @@ def test_view_link_roots(tmpdir, mock_fetch, mock_packages, mock_archive, instal
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang'] - compilers: ['%%gcc', '%%clang']
@ -2152,7 +2152,7 @@ def test_view_link_type(
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- mpileaks - mpileaks
view: view:
@ -2181,7 +2181,7 @@ def test_view_link_all(tmpdir, mock_fetch, mock_packages, mock_archive, install_
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, callpath] - packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang'] - compilers: ['%%gcc', '%%clang']
@ -2225,7 +2225,7 @@ def test_stack_view_activate_from_default(
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, cmake] - packages: [mpileaks, cmake]
- compilers: ['%%gcc', '%%clang'] - compilers: ['%%gcc', '%%clang']
@ -2260,7 +2260,7 @@ def test_stack_view_no_activate_without_default(
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, cmake] - packages: [mpileaks, cmake]
- compilers: ['%%gcc', '%%clang'] - compilers: ['%%gcc', '%%clang']
@ -2294,7 +2294,7 @@ def test_stack_view_multiple_views(
with open(filename, "w") as f: with open(filename, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
definitions: definitions:
- packages: [mpileaks, cmake] - packages: [mpileaks, cmake]
- compilers: ['%%gcc', '%%clang'] - compilers: ['%%gcc', '%%clang']
@ -2461,7 +2461,7 @@ def test_env_write_only_non_default_nested(tmpdir):
filename = "spack.yaml" filename = "spack.yaml"
filepath = str(tmpdir.join(filename)) filepath = str(tmpdir.join(filename))
contents = """\ contents = """\
env: spack:
specs: specs:
- matrix: - matrix:
- [mpileaks] - [mpileaks]

View File

@ -25,7 +25,7 @@ def test_undevelop(tmpdir, config, mock_packages, mutable_mock_env_path):
with open("spack.yaml", "w") as f: with open("spack.yaml", "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- mpich - mpich
@ -54,7 +54,7 @@ def test_undevelop_nonexistent(tmpdir, config, mock_packages, mutable_mock_env_p
with open("spack.yaml", "w") as f: with open("spack.yaml", "w") as f:
f.write( f.write(
"""\ """\
env: spack:
specs: specs:
- mpich - mpich

View File

@ -74,7 +74,7 @@ def env_yaml(tmpdir):
with open(env_yaml, "w") as f: with open(env_yaml, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
config: config:
verify_ssl: False verify_ssl: False
dirty: False dirty: False
@ -918,7 +918,7 @@ def test_immutable_scope(tmpdir):
def test_single_file_scope(config, env_yaml): def test_single_file_scope(config, env_yaml):
scope = spack.config.SingleFileScope("env", env_yaml, spack.schema.env.schema, ["env"]) scope = spack.config.SingleFileScope("env", env_yaml, spack.schema.env.schema, ["spack"])
with spack.config.override(scope): with spack.config.override(scope):
# from the single-file config # from the single-file config
@ -943,7 +943,7 @@ def test_single_file_scope_section_override(tmpdir, config):
with open(env_yaml, "w") as f: with open(env_yaml, "w") as f:
f.write( f.write(
"""\ """\
env: spack:
config: config:
verify_ssl: False verify_ssl: False
packages:: packages::
@ -954,7 +954,7 @@ def test_single_file_scope_section_override(tmpdir, config):
""" """
) )
scope = spack.config.SingleFileScope("env", env_yaml, spack.schema.env.schema, ["env"]) scope = spack.config.SingleFileScope("env", env_yaml, spack.schema.env.schema, ["spack"])
with spack.config.override(scope): with spack.config.override(scope):
# from the single-file config # from the single-file config
@ -1015,7 +1015,7 @@ def test_bad_env_yaml(tmpdir):
check_schema( check_schema(
spack.schema.env.schema, spack.schema.env.schema,
"""\ """\
env: spack:
foobar: foobar:
verify_ssl: False verify_ssl: False
dirty: False dirty: False
@ -1169,7 +1169,7 @@ def test_license_dir_config(mutable_config, mock_packages):
@pytest.mark.regression("22547") @pytest.mark.regression("22547")
def test_single_file_scope_cache_clearing(env_yaml): def test_single_file_scope_cache_clearing(env_yaml):
scope = spack.config.SingleFileScope("env", env_yaml, spack.schema.env.schema, ["env"]) scope = spack.config.SingleFileScope("env", env_yaml, spack.schema.env.schema, ["spack"])
# Check that we can retrieve data from the single file scope # Check that we can retrieve data from the single file scope
before = scope.get_section("config") before = scope.get_section("config")
assert before assert before

View File

@ -82,7 +82,7 @@ def test_env_change_spec(tmp_path, mock_packages, config):
_test_matrix_yaml = """\ _test_matrix_yaml = """\
env: spack:
definitions: definitions:
- compilers: ["%gcc", "%clang"] - compilers: ["%gcc", "%clang"]
- desired_specs: ["mpileaks@2.1"] - desired_specs: ["mpileaks@2.1"]