Skip to content

Environment context manager does not deactivate previous environment #49188

@alalazo

Description

@alalazo

Steps to reproduce

This can be reproduced with the following config_scopes.py script:

# config_scopes.py
import spack.config
import spack.environment

print(f"BEFORE: {', '.join(spack.config.CONFIG.scopes)}\n")
with spack.environment.read("test"):
    print(f"test-env: {', '.join(spack.config.CONFIG.scopes)}\n")
print(f"AFTER: {', '.join(spack.config.CONFIG.scopes)}\n")

Running the following commands:

$ spack env create test
$ spack env activate --temp
$ spack python config_scopes.py

Error message

No error message, but the output:

$ spack python try.py 
BEFORE: _builtin, defaults, defaults/linux, system, system/linux, site, site/linux, user, user/linux, env:/tmp/spack-usl4w43m, command_line

test-env: _builtin, defaults, defaults/linux, system, system/linux, site, site/linux, user, user/linux, env:/tmp/spack-usl4w43m, env:test, command_line

AFTER: _builtin, defaults, defaults/linux, system, system/linux, site, site/linux, user, user/linux, env:/tmp/spack-usl4w43m, command_line

shows that within the context manager two environment scopes are active.

Information on your system

  • Spack: 1.0.0.dev0 (9e508b0)
  • Python: 3.13.0
  • Platform: linux-ubuntu20.04-icelake

General information

  • I have run spack debug report and reported the version of Spack/Python/Platform
  • I have searched the issues of this repo and believe this is not a duplicate
  • I have run the failing commands in debug mode and reported the output

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions