Since our development environment is controlled completely by passing environment variables from one process to its children, in general we allow all variables to flow freely. There are, however, a few circumstances in which we need to inhibit this flow.
Maya and Nuke, for example, add to the
PYTHONHOME, and our
launchers add to
SITETOOLS_SITES (e.g., for the app’s special flavour of
PyQt, etc.), and these changes must not propigate to child processes.
These tools allow us to manage those variables which should not propigate. In a “freeze”, the current state of given variables will be stored in the environment (for which you can provide part of the variable name). Then you can modify those variables for use, and launch the app. Upon Python startup, these tools will reset any variables which have been flagged with the default, unnamed, namespace.
Where the default, unnamed, freeze is stored.
Do not use this directly, as the format is subject to change without notice. Instead, use
freeze(environ, names, label=None)¶
Flag the given names to reset to their current value in the next Python.
This is useful to reset environment variables that are set by wrapper scripts that are nessesary to bootstrap the process, but we do not want to carry into any subprocess. E.g.
This may be called multiple times for the same label as it updates any existing freezes.
import os from subprocess import call from sitecustomize.environ import freeze env = dict(os.environ) env['DEMO'] = 'one' freeze(env, ['DEMO']) env['DEMO'] = 'two' call(['python', '-c', 'import os; print os.environ["DEMO"]'], env=env) # Prints: one
unfreeze(label, pop=False, environ=None)¶
Reset the environment to its state before it was frozen by
A context manager to re-freeze the environment on exit.
unfreeze('nuke') # or with unfreeze('maya'): # do something