Expand system variables Unix style
Project description
expandvars
Expand system variables Unix style
Inspiration
This module is inspired by GNU bash's variable expansion features. It can be used as an alternative to Python's os.path.expandvars function.
A good use case is reading config files with the flexibility of reading values from environment variables using advanced features like returning a default value if some variable is not defined. For example:
[default]
my_secret_access_code = "${ACCESS_CODE:-default_access_code}"
NOTE: Although it copies most of the common behaviours, it doesn't follow it strictly. For example, it doesn't work with arrays.
Usage
from expandvars import expandvars
print(expandvars("$PATH:$HOME/bin:${SOME_UNDEFINED_PATH:-/default/path}"))
# /bin:/sbin:/usr/bin:/usr/sbin:/home/you/bin:/default/path
Examples
For now, refer to the test cases to see how it behaves.
Contributing
To contribute, setup environment following way:
# Clone repo
git clone https://github.com/sayanarijit/expandvars && cd expandvars
# Create virtualenv
virtualenv .venv && source .venv/bin/activate
# Install library in edit mode along with other handy dev tools
pip install -r dev-requirements.txt
# Optional install: black, ipython, isort
pip install black ipython isort
- Follow general git guidelines.
- Keep it simple. Use black to format code.
- Keep it simple. Use isort to sort imports.
- Test your changes locally by running
pytest
orpython setup.py test
. - If you are familiar with tox, you may want to use it for testing in different python versions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file expandvars-0.3.tar.gz
.
File metadata
- Download URL: expandvars-0.3.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e470d2ba3958c9215186f587dd841feb7ce3d493c93c3cb193698ddc0eb64b3f |
|
MD5 | ca224de9ee06e511108b08de36b7a634 |
|
BLAKE2b-256 | cf1fb635f4b5ac78384dd830f3dd7cf9e83a286624c8444e784a19e1f84bc7b8 |
File details
Details for the file expandvars-0.3-py3-none-any.whl
.
File metadata
- Download URL: expandvars-0.3-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8a706c5b967588b35b1ac306ab3789e75d0281833c8334bd50feb284b4af8a8 |
|
MD5 | 88ee371534776aef8ca8b6a050214a1b |
|
BLAKE2b-256 | 9b28f69da32ee931658765b5d327d84353dcc9fe510661b6b2c7cfbb569e6f96 |