process
⚓︎
Current running process info
Classes:
-
Env–os.environproxy with attribute access
Functions:
-
tmpenv–Context manager that restores
os.environon exit -
env_dict–Return the current environment-variables as a dictionary
-
is_mac–Determine if current operating system is macos/osx
-
ismac–Alias for is_mac()
-
is_win–Determine if current operating system is windows
-
iswin–Alias for is_win()
-
is_wsl–Return True if python is running under (WSL); Return False otherwise
-
iswsl–Alias for is_wsl()
-
is_notebook–Determine if running in ipython/jupyter notebook; returns True/False
-
is_pypy–Return True if running on pypy3; False otherwise
-
is_cpython–Return True if running on CPython; False otherwise
-
opsys–Return the current process' os type: 'mac' | 'lin' | 'win' | 'wsl'
-
rhel_version–Return 'rhelX' based on the current linux version
-
linux_version–Return rhel7 or rhel8 based on the current linux version
-
hostname–Return the current computer's hostname
-
sys_path_sep–Return the system path separator string (; on windows -- : otherwise)
-
syspath_paths–Return the current sys.path as a list
Env
⚓︎
os.environ proxy with attribute access
Not meant to be instantiated — use the class itself (or its env/ENV
aliases). Attribute, item, and mapping access all read and write the live
os.environ; unset variables read as None instead of raising.
Examples:
>>> from os import environ
>>> if 'SOMEENVVARIABLE' in environ:
... del environ['SOMEENVVARIABLE']
>>> environ.get('SOMEENVVARIABLE') # Does not exist in environ
>>> Env.SOMEENVVARIABLE
>>> Env.SOMEENVVARIABLE = 'value'
>>> Env.SOMEENVVARIABLE
'value'
>>> environ.get('SOMEENVVARIABLE')
'value'
>>> environ['SOMEENVVARIABLE']
'value'
>>> 'SOMEENVVARIABLE' in Env
True
>>> {k: v for k, v in Env.items() if k == 'SOMEENVVARIABLE'}
{'SOMEENVVARIABLE': 'value'}
>>> del Env['SOMEENVVARIABLE']
>>> 'SOMEENVVARIABLE' in Env
False
tmpenv
⚓︎
Context manager that restores os.environ on exit
Parameters:
Yields:
Examples:
>>> from shellfish.process import tmpenv
>>> with tmpenv(SOME_TMP_VAR="value") as e:
... e.SOME_TMP_VAR
'value'
>>> import os
>>> "SOME_TMP_VAR" in os.environ
False
is_mac
⚓︎
is_mac() -> bool
Determine if current operating system is macos/osx
Returns:
-
bool–True if on a mac; False otherwise
is_win
⚓︎
is_win() -> bool
Determine if current operating system is windows
Returns:
-
bool–True if on a windows machine; False otherwise
is_notebook
⚓︎
is_notebook() -> bool
Determine if running in ipython/jupyter notebook; returns True/False
hostname
⚓︎
hostname() -> str
Return the current computer's hostname
Returns:
-
str(str) –hostname
Examples:
>>> hn = hostname()
>>> isinstance(hn, str)
True
sys_path_sep
⚓︎
sys_path_sep() -> str
Return the system path separator string (; on windows -- : otherwise)
Examples:
>>> import os
>>> sep = sys_path_sep()
>>> isinstance(sep, str)
True
>>> os.pathsep == sep
True
syspath_paths
⚓︎
Return the current sys.path as a list
Examples:
>>> sys_paths = syspath_paths()
>>> isinstance(sys_paths, list)
True
>>> sys_path_arg = 'path1;path2;path3' if is_win() else 'path1:path2:path3'
>>> sys_paths_w_args = syspath_paths(syspath=sys_path_arg)
>>> isinstance(sys_paths_w_args, list)
True
>>> sys_paths_w_args == ['path1', 'path2', 'path3']
True