parameter-expansion-patched


Nameparameter-expansion-patched JSON
Version 0.3.1 PyPI version JSON
download
home_pagehttps://github.com/nexB/parameter-expansion-patched
SummaryShell parameter expansion in Python. Patched by co-maintainer for a PyPI release.
upload_time2022-05-04 14:54:59
maintainer
docs_urlNone
authorMichael A. Smith and Philippe Ombredanne
requires_python
licenseApache-2.0
keywords parameter expansion shell posix bash
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # POSIX Parameter Expansion

![GitHub](https://img.shields.io/github/license/kojiromike/parameter-expansion)
![PyPI](https://img.shields.io/pypi/v/parameter-expansion)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/parameter-expansion)
![PyPI - Wheel](https://img.shields.io/pypi/wheel/parameter-expansion)
![PyPI - Downloads](https://img.shields.io/pypi/dm/parameter-expansion)

[![Tests](https://github.com/kojiromike/parameter-expansion/actions/workflows/test.yml/badge.svg)](https://github.com/kojiromike/parameter-expansion/actions/workflows/test.yml)
[![CodeQL](https://github.com/kojiromike/parameter-expansion/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/kojiromike/parameter-expansion/actions/workflows/codeql-analysis.yml)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)


This is an experimental Python library to enable
[POSIX parameter expansion][1] in a string.
It supports also a subset of [Bash parameter expansion][2].


Note that this is a fork from upstream to support proper release on PyPI.

This repo https://github.com/nexB/parameter_expansion_patched is released at
https://pypi.org/project/parameter-expansion-patched/ on PyPI.

Upstream is less active lately at https://github.com/kojiromike/parameter-expansion/


## Why not spawning a shell directly for this?
One reason is that it may be security risk. Another reason is to
support lightweight analysis or evaluation of shell parameters with
few system dependencies and outside of a running shell.

For instance this use in [scancode-toolkit][3] as part of a lightweight
shell script parser to extract and expand parameters found in some
build scripts.

## Which expansions are supported?
All the standard shell expansions are supported, including some level
of nested expansion, as long as this is not too complex or ambiguous.
In addition, we support Bash substrings and string replacement.
There is an extensive test suite listing [all supported substitions][4]


## How does this work?
The `expand()` function accepts a string and a dictionary of variables
(otherwise it uses the current environmnent variables). The string is
parsed with a custom parser and interpreted to perform the various
expansion procedures using these variables.

### Obvious Test Cases

```python
    >>> from parameter_expansion import expand
    >>> foo = 'abc/123-def.ghi'
    >>> # Bland Expansion
    >>> expand('abc $foo abc')
    'abc abc/123-def.ghi abc'
    >>> expand('abc${foo}abc')
    'abcabc/123-def.ghiabc'
    >>>
    >>> # Default Value Expansion
    >>> expand('-${foo:-bar}-')
    '-abc/123-def.ghi-'
    >>> expand('-${bar:-bar}-')
    '-bar-'
```

### Default Value Expansion

```python
    >>> foo = 'abc/123-def.ghi'
    >>> expand('abc $foo abc')
    'abc abc/123-def.ghi abc'
    >>> expand('abc${foo}abc')
    'abcabc/123-def.ghiabc'
```




## Any other library doing similar thing?

-  https://github.com/sayanarijit/expandvars has similar features yet does not cover all the expansions that this library supports (such as %, # and nested variables).

-  https://github.com/sloria/environs





[1]: https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02
[2]: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
[3]: https://github.com/nexB/scancode-toolkit/blob/develop/src/packagedcode/bashparse.py
[4]: https://github.com/kojiromike/parameter-expansion/blob/main/parameter_expansion/tests/test_pe.py



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nexB/parameter-expansion-patched",
    "name": "parameter-expansion-patched",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "parameter expansion,shell,POSIX,bash",
    "author": "Michael A. Smith and Philippe Ombredanne",
    "author_email": "michael@smith-li.com",
    "download_url": "https://files.pythonhosted.org/packages/7e/15/0c6fa115b269418a0d53d4564809afb74684d8afa417323b406be26de08b/parameter-expansion-patched-0.3.1.tar.gz",
    "platform": null,
    "description": "# POSIX Parameter Expansion\n\n![GitHub](https://img.shields.io/github/license/kojiromike/parameter-expansion)\n![PyPI](https://img.shields.io/pypi/v/parameter-expansion)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/parameter-expansion)\n![PyPI - Wheel](https://img.shields.io/pypi/wheel/parameter-expansion)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/parameter-expansion)\n\n[![Tests](https://github.com/kojiromike/parameter-expansion/actions/workflows/test.yml/badge.svg)](https://github.com/kojiromike/parameter-expansion/actions/workflows/test.yml)\n[![CodeQL](https://github.com/kojiromike/parameter-expansion/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/kojiromike/parameter-expansion/actions/workflows/codeql-analysis.yml)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)\n\n\nThis is an experimental Python library to enable\n[POSIX parameter expansion][1] in a string.\nIt supports also a subset of [Bash parameter expansion][2].\n\n\nNote that this is a fork from upstream to support proper release on PyPI.\n\nThis repo https://github.com/nexB/parameter_expansion_patched is released at\nhttps://pypi.org/project/parameter-expansion-patched/ on PyPI.\n\nUpstream is less active lately at https://github.com/kojiromike/parameter-expansion/\n\n\n## Why not spawning a shell directly for this?\nOne reason is that it may be security risk. Another reason is to\nsupport lightweight analysis or evaluation of shell parameters with\nfew system dependencies and outside of a running shell.\n\nFor instance this use in [scancode-toolkit][3] as part of a lightweight\nshell script parser to extract and expand parameters found in some\nbuild scripts.\n\n## Which expansions are supported?\nAll the standard shell expansions are supported, including some level\nof nested expansion, as long as this is not too complex or ambiguous.\nIn addition, we support Bash substrings and string replacement.\nThere is an extensive test suite listing [all supported substitions][4]\n\n\n## How does this work?\nThe `expand()` function accepts a string and a dictionary of variables\n(otherwise it uses the current environmnent variables). The string is\nparsed with a custom parser and interpreted to perform the various\nexpansion procedures using these variables.\n\n### Obvious Test Cases\n\n```python\n    >>> from parameter_expansion import expand\n    >>> foo = 'abc/123-def.ghi'\n    >>> # Bland Expansion\n    >>> expand('abc $foo abc')\n    'abc abc/123-def.ghi abc'\n    >>> expand('abc${foo}abc')\n    'abcabc/123-def.ghiabc'\n    >>>\n    >>> # Default Value Expansion\n    >>> expand('-${foo:-bar}-')\n    '-abc/123-def.ghi-'\n    >>> expand('-${bar:-bar}-')\n    '-bar-'\n```\n\n### Default Value Expansion\n\n```python\n    >>> foo = 'abc/123-def.ghi'\n    >>> expand('abc $foo abc')\n    'abc abc/123-def.ghi abc'\n    >>> expand('abc${foo}abc')\n    'abcabc/123-def.ghiabc'\n```\n\n\n\n\n## Any other library doing similar thing?\n\n-  https://github.com/sayanarijit/expandvars has similar features yet does not cover all the expansions that this library supports (such as %, # and nested variables).\n\n-  https://github.com/sloria/environs\n\n\n\n\n\n[1]: https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02\n[2]: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html\n[3]: https://github.com/nexB/scancode-toolkit/blob/develop/src/packagedcode/bashparse.py\n[4]: https://github.com/kojiromike/parameter-expansion/blob/main/parameter_expansion/tests/test_pe.py\n\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Shell parameter expansion in Python. Patched by co-maintainer for a PyPI release.",
    "version": "0.3.1",
    "split_keywords": [
        "parameter expansion",
        "shell",
        "posix",
        "bash"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "7a99e938eafd91abc8f142711af6518d",
                "sha256": "832f04bed2a81e32d9d233cbe27448a7a22edf9a744086dbd01066c41ad0f535"
            },
            "downloads": -1,
            "filename": "parameter_expansion_patched-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7a99e938eafd91abc8f142711af6518d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11839,
            "upload_time": "2022-05-04T14:54:56",
            "upload_time_iso_8601": "2022-05-04T14:54:56.296028Z",
            "url": "https://files.pythonhosted.org/packages/6c/9f/2eb2762808faed5218faba5559415b5bb62b39376cf9a38acc01f9786481/parameter_expansion_patched-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "42fd64babe52ba313bb26948fba48cd2",
                "sha256": "ff5dbc89fbde582f3336562d196b710771e92baa7b6d59356a14b085a0b6740b"
            },
            "downloads": -1,
            "filename": "parameter-expansion-patched-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "42fd64babe52ba313bb26948fba48cd2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14584,
            "upload_time": "2022-05-04T14:54:59",
            "upload_time_iso_8601": "2022-05-04T14:54:59.740885Z",
            "url": "https://files.pythonhosted.org/packages/7e/15/0c6fa115b269418a0d53d4564809afb74684d8afa417323b406be26de08b/parameter-expansion-patched-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-05-04 14:54:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "nexB",
    "github_project": "parameter-expansion-patched",
    "lcname": "parameter-expansion-patched"
}
        
Elapsed time: 0.27715s