ros2 / launch

Tools for launching multiple processes and for writing tests involving multiple processes.
Apache License 2.0
124 stars 139 forks source link

Fix the restoring of os.environ to maintain type. #656

Closed clalancette closed 1 year ago

clalancette commented 1 year ago

During the LaunchContext constructor or _push_environment(), we take a copy of the environment via os.environ.copy(). That function returns a dict, but it turns out that os.environ itself is an os._Environ object, not a dict. Thus, when restoring the environment in either _pop_environment() or _reset_environment(), we cannot just set os.environ to that value. Instead, we clear out the environment and then set the key/value pairs one-by-one into the environment. That maintains os.environ as a os._Environ object while also performing the desired pop or reset of the environment variables.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

clalancette commented 1 year ago

FYI, this should be backported to all distributions.

clalancette commented 1 year ago

Full CI:

clalancette commented 1 year ago

New full CI after fixes:

jacobperron commented 1 year ago
clalancette commented 1 year ago

CI is happy and this is approved, so merging. I'll backport next.

clalancette commented 1 year ago

@Mergifyio backport humble galactic foxy

mergify[bot] commented 1 year ago

backport humble galactic foxy

✅ Backports have been created

* [#660 Fix the restoring of os.environ to maintain type. (backport #656)](https://github.com/ros2/launch/pull/660) has been created for branch `humble` * [#661 Fix the restoring of os.environ to maintain type. (backport #656)](https://github.com/ros2/launch/pull/661) has been created for branch `galactic` * [#662 Fix the restoring of os.environ to maintain type. (backport #656)](https://github.com/ros2/launch/pull/662) has been created for branch `foxy`