pipen-cli-require


Namepipen-cli-require JSON
Version 0.12.0 PyPI version JSON
download
home_pageNone
SummaryA pipen cli plugin to check requirements for processes of a pipeline
upload_time2024-07-23 22:28:36
maintainerNone
docs_urlNone
authorpwwang
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pipen-cli-require

Checking the requirements for processes of a [pipen][1] pipeline

## Install

```shell
pip install -U pipen-cli-require
```

## Usage

### Defining requirements of a process

```python
# example_pipeline.py
from pipen import Pipen, Proc

class P1(Proc):
    """Process 1

    Requires:
        pipen: Run `pip install -U pipen` to install
          - check: |
            {{proc.lang}} -c "import pipen"
        liquidpy: Run `pip install -U liquidpy` to install
          - check: |
            {{proc.lang}} -c "import liquid"
        nonexist: Run `pip install -U nonexist` to install
          - check: |
            {{proc.lang}} -c "import nonexist"
        conditional:
          - if: {{envs.require_conditional}}
          - check:
            {{proc.lang}} -c "import optional"

    """
    input = "a"
    output = "outfile:file:out.txt"
    envs = {"require_conditional": False}
    lang = "python"

# Setup the pipeline
# Must be outside __main__
# Or define a function to return the pipeline
class Pipeline(Pipen):
    starts = P1


if __name__ == '__main__':
    # Pipeline must run with __main__
    Pipeline().run()
```

### Parsing process requirements using API

```python
from pipen_cli_require import parse_proc_requirements


def parse_proc_requirements(
    proc: Type[Proc]
) -> Tuple[OrderedDiot, OrderedDiot]:
    """Parse the requirements of a process

    Args:
        proc: The process class

    Returns:
        A tuple of two OrderedDiot's.
        The first one is the annotated sections by pipen_annotate
        The second one is the requirements. The key is the name of the
            requirement, the value is a dict with message, check and if_ keys.
    """
```

## Checking the requirements via the CLI

```shell
> pipen require --verbose --ncores 2 example_pipeline.py:pipeline

Checking requirements for pipeline: PIPEN-0
│
└── P1: Process 1
    ├── ✅ pipen
    ├── ✅ liquidpy
    ├── ❎ nonexist: Run `pip install -U nonexist` to install
    │   └── Traceback (most recent call last):
    │         File "<string>", line 1, in <module>
    │       ModuleNotFoundError: No module named 'nonexist'
    │
    └── ⏩ conditional (skipped by if-statement)
```

## Checking requirements with runtime arguments

For example, when I use a different python to run the pipeline:

Add this to the head of `example_pipeline.py`:

```python
import pipen_args
```

See also `tests/pipen_args_pipeline.py`

Then specify the path of the python to use:

```shell
pipen require example_pipeline.py:pipeline --P1.lang /path/to/another/python
```

[1]: https://github.com/pwwang/pipen

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pipen-cli-require",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "pwwang",
    "author_email": "pwwang@pwwang.com",
    "download_url": "https://files.pythonhosted.org/packages/05/e0/732ca6c73297726fa10f2624b279532628709f3e987dab0c9dd8b835f331/pipen_cli_require-0.12.0.tar.gz",
    "platform": null,
    "description": "# pipen-cli-require\n\nChecking the requirements for processes of a [pipen][1] pipeline\n\n## Install\n\n```shell\npip install -U pipen-cli-require\n```\n\n## Usage\n\n### Defining requirements of a process\n\n```python\n# example_pipeline.py\nfrom pipen import Pipen, Proc\n\nclass P1(Proc):\n    \"\"\"Process 1\n\n    Requires:\n        pipen: Run `pip install -U pipen` to install\n          - check: |\n            {{proc.lang}} -c \"import pipen\"\n        liquidpy: Run `pip install -U liquidpy` to install\n          - check: |\n            {{proc.lang}} -c \"import liquid\"\n        nonexist: Run `pip install -U nonexist` to install\n          - check: |\n            {{proc.lang}} -c \"import nonexist\"\n        conditional:\n          - if: {{envs.require_conditional}}\n          - check:\n            {{proc.lang}} -c \"import optional\"\n\n    \"\"\"\n    input = \"a\"\n    output = \"outfile:file:out.txt\"\n    envs = {\"require_conditional\": False}\n    lang = \"python\"\n\n# Setup the pipeline\n# Must be outside __main__\n# Or define a function to return the pipeline\nclass Pipeline(Pipen):\n    starts = P1\n\n\nif __name__ == '__main__':\n    # Pipeline must run with __main__\n    Pipeline().run()\n```\n\n### Parsing process requirements using API\n\n```python\nfrom pipen_cli_require import parse_proc_requirements\n\n\ndef parse_proc_requirements(\n    proc: Type[Proc]\n) -> Tuple[OrderedDiot, OrderedDiot]:\n    \"\"\"Parse the requirements of a process\n\n    Args:\n        proc: The process class\n\n    Returns:\n        A tuple of two OrderedDiot's.\n        The first one is the annotated sections by pipen_annotate\n        The second one is the requirements. The key is the name of the\n            requirement, the value is a dict with message, check and if_ keys.\n    \"\"\"\n```\n\n## Checking the requirements via the CLI\n\n```shell\n> pipen require --verbose --ncores 2 example_pipeline.py:pipeline\n\nChecking requirements for pipeline: PIPEN-0\n\u2502\n\u2514\u2500\u2500 P1: Process 1\n    \u251c\u2500\u2500 \u2705 pipen\n    \u251c\u2500\u2500 \u2705 liquidpy\n    \u251c\u2500\u2500 \u274e nonexist: Run `pip install -U nonexist` to install\n    \u2502   \u2514\u2500\u2500 Traceback (most recent call last):\n    \u2502         File \"<string>\", line 1, in <module>\n    \u2502       ModuleNotFoundError: No module named 'nonexist'\n    \u2502\n    \u2514\u2500\u2500 \u23e9 conditional (skipped by if-statement)\n```\n\n## Checking requirements with runtime arguments\n\nFor example, when I use a different python to run the pipeline:\n\nAdd this to the head of `example_pipeline.py`:\n\n```python\nimport pipen_args\n```\n\nSee also `tests/pipen_args_pipeline.py`\n\nThen specify the path of the python to use:\n\n```shell\npipen require example_pipeline.py:pipeline --P1.lang /path/to/another/python\n```\n\n[1]: https://github.com/pwwang/pipen\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A pipen cli plugin to check requirements for processes of a pipeline",
    "version": "0.12.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "56192dc9c45b3e9fab07719e4bc35880537f9008ac45fea4f41098be64fbcd59",
                "md5": "51bc83d2ce9340c7d26645578ef346fe",
                "sha256": "4dedb48152d47f96506afd29fbc4bdf4abd6f60c1954a0189fe722f46bb2c40a"
            },
            "downloads": -1,
            "filename": "pipen_cli_require-0.12.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "51bc83d2ce9340c7d26645578ef346fe",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 6488,
            "upload_time": "2024-07-23T22:28:35",
            "upload_time_iso_8601": "2024-07-23T22:28:35.102322Z",
            "url": "https://files.pythonhosted.org/packages/56/19/2dc9c45b3e9fab07719e4bc35880537f9008ac45fea4f41098be64fbcd59/pipen_cli_require-0.12.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "05e0732ca6c73297726fa10f2624b279532628709f3e987dab0c9dd8b835f331",
                "md5": "78f6ba1af2b2c4d638f27e4ecb151229",
                "sha256": "9ded9dc3891aab90000b2ccc7d416658f7171aa5101064e3675cd8de45a54340"
            },
            "downloads": -1,
            "filename": "pipen_cli_require-0.12.0.tar.gz",
            "has_sig": false,
            "md5_digest": "78f6ba1af2b2c4d638f27e4ecb151229",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 5829,
            "upload_time": "2024-07-23T22:28:36",
            "upload_time_iso_8601": "2024-07-23T22:28:36.168690Z",
            "url": "https://files.pythonhosted.org/packages/05/e0/732ca6c73297726fa10f2624b279532628709f3e987dab0c9dd8b835f331/pipen_cli_require-0.12.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-23 22:28:36",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pipen-cli-require"
}
        
Elapsed time: 0.28255s