PEX runtime environment variables

class pex.variables.DefaultedProperty(func, default)[source]

Bases: object

Represents a property with a default value.

To determine the value of the property without the default value applied, access it through the class and call the strip_default method, passing the instance in question.

strip_default(instance)[source]

Return the value of this property without the default value applied.

If the property is not set None will be returned and if there is an associated @validator that validator will be skipped.

Parameters

instance – The instance to check for the non-defaulted property value.

Returns

The property value or None if not set.

validator(func)[source]

Associate a validation function with this defaulted property.

The function will be used to validate this property’s final computed value.

Parameters

func – The validation function to associate with this property descriptor.

exception pex.variables.NoValueError[source]

Bases: Exception

Indicates a property has no value set.

When raised from a method decorated with @defaulted_property(default) indicates the default value should be used.

class pex.variables.Variables(environ=None, rc=None)[source]

Bases: object

Environment variables supported by the PEX runtime.

property PEX_COVERAGE_FILENAME

Filename.

Write the coverage data to the specified filename. If PEX_COVERAGE_FILENAME is not specified but PEX_COVERAGE is, coverage information will be printed to stdout and not saved.

property PEX_EMIT_WARNINGS

Boolean.

Emit UserWarnings to stderr. When false, warnings will only be logged at PEX_VERBOSE >= 1. When unset the build-time value of –emit-warnings will be used. Default: unset.

property PEX_EXTRA_SYS_PATH

String.

A colon-separated string containing paths to add to the runtime sys.path.

Should be used sparingly, e.g., if you know that code inside this PEX needs to interact with code outside it.

Ex: “/path/to/lib1:/path/to/lib2”

This is distinct from PEX_INHERIT_PATH, which controls how the interpreter’s existing sys.path (which you may not have control over) is scrubbed.

See also PEX_PATH for how to merge packages from other pexes into the current environment.

property PEX_MODULE

String.

Override the entry point into the PEX file. Can either be a module, e.g. ‘SimpleHTTPServer’, or a specific entry point in module:symbol form, e.g. “myapp.bin:main”.

property PEX_PROFILE_FILENAME

Filename.

Profile the application and dump a profile into the specified filename in the standard “profile” module format.

property PEX_PYTHON

String.

Override the Python interpreter used to invoke this PEX. Can be either an absolute path to an interpreter or a base name e.g. “python3.3”. If a base name is provided, the $PATH will be searched for an appropriate match.

property PEX_PYTHON_PATH

String.

A colon-separated string containing paths of blessed Python interpreters for overriding the Python interpreter used to invoke this PEX. Can be absolute paths to interpreters or standard $PATH style directory entries that are searched for child files that are python binaries.

Ex: “/path/to/python27:/path/to/python36-distribution/bin”

property PEX_SCRIPT

String.

The script name within the PEX environment to execute. This must either be an entry point as defined in a distribution’s console_scripts, or a script as defined in a distribution’s scripts section. While Python supports any script including shell scripts, PEX only supports invocation of Python scripts in this fashion.

classmethod from_rc(rc=None)[source]

Read pex runtime configuration variables from a pexrc file.

Parameters

rc – an absolute path to a pexrc file.

Returns

A dict of key value pairs found in processed pexrc files.

patch(**kw)[source]

Update the environment for the duration of a context.

pex.variables.defaulted_property(default)[source]

Creates a @property with a default value.

Accessors decorated with this function should raise NoValueError to indicate the default value should be used.