Metadata-Version: 2.1
Name: expandvars
Version: 0.6.0
Summary: Expand system variables Unix style
Home-page: https://github.com/sayanarijit/expandvars
Author: Arijit Basu
Author-email: sayanarijit@gmail.com
License: MIT
Description: expandvars
        ==========
        Expand system variables Unix style
        
        [![PyPI version](https://img.shields.io/pypi/v/expandvars.svg)](https://pypi.org/project/expandvars)
        [![CircleCI](https://circleci.com/gh/sayanarijit/expandvars/tree/master.svg?style=svg)](https://circleci.com/gh/sayanarijit/expandvars/tree/master)
        [![codecov](https://codecov.io/gh/sayanarijit/expandvars/branch/master/graph/badge.svg)](https://codecov.io/gh/sayanarijit/expandvars)
        
        
        Inspiration
        -----------
        This module is inspired by [GNU bash's variable expansion features](https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html). It can be used as an alternative to Python's [os.path.expandvars](https://docs.python.org/3/library/os.path.html#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:
        
        ```toml
        [default]
        my_secret_access_code = "${ACCESS_CODE:-default_access_code}"
        my_important_variable = "${IMPORTANT_VARIABLE:?}"
        my_updated_path = "$PATH:$HOME/.bin"
        ```
        
        > NOTE: Although this module copies most of the common behaviours of bash,
        > it doesn't follow bash strictly. For example, it doesn't work with arrays.
        
        
        Usage
        -----
        
        ```python
        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](https://github.com/sayanarijit/expandvars/blob/master/tests) to see how it behaves.
        
        
        TIPs
        ----
        
        ### nounset=True
        
        If you want to enable strict parsing by default, (similar to `set -u` / `set -o nounset` in bash), pass `nounset=True`.
        
        ```python
        # All the variables must be defined.
        expandvars("$VAR1:${VAR2}:$VAR3", nounset=True)
        
        # Raises UnboundVariable error.
        ```
        
        > NOTE: Another way is to use the `${VAR?}` or `${VAR:?}` syntax. See the examples in tests.
        
        ### EXPANDVARS_RECOVER_NULL="foo"
        
        If you want to temporarily disable strict parsing both for `nounset=True` and the `${VAR:?}` syntax, set environment variable `EXPANDVARS_RECOVER_NULL=somevalue`.
        This helps with certain use cases where you need to temporarily disable strict parsing of critical env vars, e.g. in testing environment, without modifying the code.
        
        e.g.
        
        ```bash
        EXPANDVARS_RECOVER_NULL=foo myapp --config production.ini && echo "All fine."
        ```
        
        > WARNING: Try to avoid `export EXPANDVARS_RECOVER_NULL` because that will disable strict parsing permanently until you log out.
        
        
        Contributing
        ------------
        To contribute, setup environment following way:
        
        ```bash
        # 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
        ```
        
        - Follow [general git guidelines](https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project).
        - Keep it simple. Use [black](https://github.com/python/black) to format code.
        - Test your changes locally by running `pytest`.
        - If you are familiar with [tox](https://tox.readthedocs.io), you may want to use it for testing in different python versions.
        
Keywords: expand system variables
Platform: Any
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Other Audience
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Utilities
Classifier: Topic :: Software Development
Classifier: Operating System :: MacOS
Classifier: Operating System :: Unix
Classifier: Operating System :: POSIX
Classifier: Operating System :: Microsoft
Description-Content-Type: text/markdown
Provides-Extra: testing
Provides-Extra: dev
