env
¶
Global environment and platform information support.
This package provide a class called Env used to store global information. Env is a singleton so there is in fact only one instance.
Module Contents¶
Classes¶
Environment Handling. |
|
BaseEnv. |
|
Env shows the current environment in used. |
Attributes¶
- env.logger¶
- env.CANADIAN_EXCEPTIONS = (('x86-windows', 'x86_64-windows'), ('sparc-solaris', 'sparc64-solaris'))¶
- env.EnvInfo¶
- class env.AbstractBaseEnv(build: e3.platform.Platform | None = None, host: e3.platform.Platform | None = None, target: e3.platform.Platform | None = None)¶
Environment Handling.
Abstract class to factorize code between BaseEnv and Env. :ivar build: current build Platform :vartype build: Platform :ivar host: current host Platform :vartype host: Platform :ivar target: current target Platform :vartype target: Platform :ivar main_options: The command-line switches, after parsing by the e3.Main class (see the documentation of that class).
- property platform: str¶
Compute the platform name based on the host and the target.
For example for target ppc-elf hosted on linux, platform will be ppc-elf-linux. So the concept of platform embed both target and host concept.
- property is_canadian: bool¶
Return true if this is a canadian configuration.
- property is_cross: bool¶
Return true if this is a cross configuration.
- property dll_path_var: str¶
- property discriminants: list[str]¶
Compute discriminants.
- Returns:
the list of discriminants associated with the current context (target, host, …). This is mainly used for testsuites to ensure a coherent set of base discriminants.
- property tmp_dir: str¶
Return current temporary directory.
- Returns:
a path
The function looks for several variables
TMPDIR
,TMP
and in case none of these variables are defined fallback on on/tmp
.
- abstract _initialized() bool ¶
Whether the new instance should be initialized.
This is mostly useful to implement a singleton, as done in Env()
- abstract _items() Iterable ¶
Return the list of instance variables.
- set_build(name: str | None = None, version: str | None = None, machine: str | None = None, mode: str | None = None) None ¶
Set build platform.
- Parameters:
name – a string that identify the system to be considered as the build. If None then build is unchanged. Note that passing an empty value will force the autodetection and possibly reset to the default value.
version – a string containing the system version. If set to None the version is either a default or autodetected when possible
machine – a string containing the name of the target machine.
mode – a string containing the name of the mode. This notion is needed on some targets such as VxWorks to switch between kernel mode and other modes such as rtp
When calling set_build, the target and host systems are reset to the build one. Thus you should call set_build before calling either set_host or set_target.
- set_host(name: str | None = None, version: str | None = None, machine: str | None = None, mode: str | None = None) None ¶
Set host platform.
- Parameters:
name – a string that identify the system to be considered as the host. If None then host is set to the build one (the autodetected platform). If set to ‘build’ or ‘target’ then host is set respectively to current ‘build’ or ‘target’ value
version – a string containing the system version. If set to None the version is either a default or autodetected when possible
machine – a string containing the name of the target machine.
mode – a string containing the name of the mode. This notion is needed on some targets such as VxWorks to switch between kernel mode and other modes such as rtp
When calling set_host, the target system is reset to the host one. Thus you should call set_host before set_target otherwise your call to set_target will be ignored. Note also that is the host_name is equal to the build platform, host_version will be ignored.
- set_target(name: str | None = None, version: str | None = None, machine: str | None = None, mode: str | None = None) None ¶
Set target platform.
- Parameters:
name – a string that identify the system to be considered as the host. If None then host is set to the host one. If set to ‘build’ or ‘host’ then target is set respectively to current ‘build’ or ‘host’ value. In that case target_version and target_machine are ignored.
version – a string containing the system version. If set to None the version is either a default or autodetected when possible.
machine – a string containing the name of the target machine.
mode – a string containing the name of the mode. This notion is needed on some targets such as VxWorks to switch between kernel mode and other modes such as rtp
The target parameters are ignored if the target_name is equal to the host platform.
- set_env(build: str | None = None, host: str | None = None, target: str | None = None) None ¶
Set build/host/target.
- Parameters:
build – string as passed to –build option
host – string as passed to –host
target – string as passed to –target
- str_triplet() EnvInfo ¶
Return a triplet of strings suitable to call set_env.
- Returns:
a namedtuple suitable for a call to set_env
- cmd_triplet() list[str] ¶
Return command line parameters corresponding to current env.
- Returns:
a list of command line parameters
- get_attr(name: str, default_value: Any = None, forced_value: Any = None) Any ¶
Return an attribute value.
- Parameters:
name – name of the attribute to check. Name can contain ‘.’
default_value – returned value if forced_value not set and the attribute does not exist
forced_value – if not None, this is the return value
- Returns:
the attribute value
This function is useful to get the value of optional functions parameters whose default value might depend on the environment.
- classmethod add_path(path: str, append: bool = False) None ¶
Set a path to PATH environment variable.
- Parameters:
path – path to add
append – if True append, otherwise prepend. Default is prepend
- classmethod add_search_path(env_var: str, path: str, append: bool = False) None ¶
Add a path to the env_var search paths.
- Parameters:
env_var – the environment variable name (e.g. PYTHONPATH, LD_LIBRARY_PATH, …)
path – path to add
append – if True append, otherwise prepend. Default is prepend
- add_dll_path(path: str, append: bool = False) None ¶
Add a path to the dynamic libraries search paths.
- Parameters:
path – path to add
append – if True append, otherwise prepend. Default is prepend
- to_dict() dict ¶
Get current env as a dictionary.
- Returns:
the dictionary entries are all strings and thus the result can be used to format string. For example
Env().target.os.name
will appear with the keytarget_os_name
, …
- classmethod from_platform_name(platform: str) AbstractBaseEnv | None ¶
Return a BaseEnv object from a platform name.
That’s the reverse of platform property
- env.BaseEnv_T¶
- class env.BaseEnv(build: e3.platform.Platform | None = None, host: e3.platform.Platform | None = None, target: e3.platform.Platform | None = None)¶
Bases:
AbstractBaseEnv
BaseEnv.
- _initialized = False¶
- __setattr__(name: str, value: Any) None ¶
Implement setattr(self, name, value).
- __getattr__(name: str) None ¶
- _items() Iterable[Any] ¶
Return the list of instance variables.
- copy(build: str | None = None, host: str | None = None, target: str | None = None) BaseEnv_T ¶
Copy an env.
- Parameters:
build – like build set_env parameter
host – like host set_env parameter
target – like target set_env parameter
- Returns:
a deep copy of the current env
- class env.Env¶
Bases:
AbstractBaseEnv
Env shows the current environment in used.
Env is a singleton holding the current environment and platform information. It is set by e3.main when the –build/–host/–target option are passed to the command line and can be then changed by calling py:meth:set_build, py:meth:set_host, and py:meth:set_target.
- property _initialized: bool¶
Whether the new instance should be initialized.
This is mostly useful to implement a singleton, as done in Env()
- _instance: dict[str, Any]¶
- _context: list[Any] = []¶
- __setattr__(name: str, value: Any) None ¶
Implement setattr(self, name, value).
- __getattr__(name: str) Any ¶
- _items() Iterable[Any] ¶
Return the list of instance variables.
- store(filename: str | None = None) None ¶
Save environment into memory or file.
- Parameters:
filename – a string containing the path of the filename in which the environment will be saved. If set to None the environment is saved into memory in a stack like structure.
- restore(filename: str | None = None) None ¶
Restore environment from memory or a file.
- Parameters:
filename – a string containing the path of the filename from which the environment will be restored. If set to None the environment is pop the last saved one