pydu/docs/environ.md

45 lines
877 B
Markdown
Raw Permalink Normal View History

2018-05-10 16:41:13 +00:00
# Environ
2018-01-14 16:16:33 +00:00
2018-03-10 05:12:01 +00:00
Utils for handling environment.
2018-01-14 16:16:33 +00:00
2018-05-10 16:41:13 +00:00
## environ.environ
```python
environ(**kwargs)
```
2018-01-14 16:16:33 +00:00
2018-05-10 16:41:13 +00:00
Context manager for updating one or more environment variables.
2018-01-14 16:16:33 +00:00
2018-05-10 16:41:13 +00:00
Preserves the previous environment variable (if available) and
recovers when exiting the context manager.
2018-01-14 16:16:33 +00:00
2018-05-10 16:41:13 +00:00
If given variable_name=None, it means removing the variable from
environment temporarily.
2018-05-10 16:41:13 +00:00
```python
>>> from pydu.environ import environ
>>> with environ(a='a'):
... print(os.environ['a'])
...
a
```
2018-01-14 16:16:33 +00:00
2018-01-16 16:11:36 +00:00
2018-05-10 16:41:13 +00:00
## environ.path
```python
path(append=None, prepend=None, replace=None)
```
2018-01-16 16:11:36 +00:00
2018-05-10 16:41:13 +00:00
Context manager for updating the PATH environment variable which
appends, prepends or replaces the PATH with given string or
a list of strings.
```python
>>> import os
>>> from pydu.environ import path
>>> with path(append='/foo'):
... print(os.environ['PATH'])
...
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/foo
```