rsgalloway / envstack

Stacked environment variable management system.
Other
3 stars 0 forks source link

bug in init and export/clear #13

Closed rsgalloway closed 5 days ago

rsgalloway commented 6 days ago

There is a bug in envstack.init() that is clearing env vars like PATH and PYTHONPATH if they are defined in the stack .env file, which means if they are referenced like this PATH: ${BIN}:%{PATH} then the values are cleared before they can be resolved

    # clear vars from stack namespace
    env = load_environ(name, environ=None)
    for key in env.keys():
        if key in os.environ:
            del os.environ[key]

    # store the name of the environment stack (e.g. for $PS1)
    os.environ["ENVSTACK"] = name

    # load the new environment
    env = load_environ(name)

The same bug exists in the export and clear functions where it's unsetting env vars that are defined in the stack file, even if they existed in the old environment, e.g. PATH and PYTHONPATH:

$ envstack --export
...
export PATH="${BIN}:blah"
export PYTHONPATH="${LIB}:blah"

Then PATH and PYTHONPATH get unset unintentionally:

$ envstack --clear
...
unset PATH
unset PYTHONPATH

when they should really be restored to the old values:

$ envstack --clear
...
set PATH=${_OLD_PATH}
set PYTHONPATH=${_OLD_PYTHONPATH}
rsgalloway commented 5 days ago

addressed on 0.6.4