pepython


Namepepython JSON
Version 0.2.5 PyPI version JSON
download
home_pagehttps://github.com/nandilugio/pepython
SummarySimple task automation for projects.
upload_time2023-08-24 19:16:38
maintainer
docs_urlNone
authorFernando Stecconi
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![CI](https://github.com/nandilugio/pepython/actions/workflows/ci.yml/badge.svg)

**Current version:** 0.2.5

Tested with Python 3.8, 3,9, 3.10 and 3.11 on latest Linux, MacOS and Windows. Code is simple. Probably works in other versions and platforms.

**Pypi:** https://pypi.org/project/pepython/ </br>
**Github:** https://github.com/nandilugio/pepython

# PePython

Need help organizing your project's tasks?

Don't want to learn a complex tool with an unnecessarily cumbersome syntax or API?

Want to specify your tasks __in plain Python__ still having easy and flexible __access to the shell__?

**Just call PePython!**

## Install

```bash
pip install pepython
```

## Quick start

Define your tasks in a `tasks.py` file your root directory. Tasks are just __plain Python__ functions. Note how dependencies are just calls in the body of the tasks themselves, alowing all kinds of dependencies and parameter forwarding (see the parameters in action further down!).

```python
from pepython.task_def import task, s

@task
def clean():
    s("rm -rf build dist *.egg-info")

@task
def build():
    clean()
    s("pipenv run python setup.py sdist bdist_wheel")

@task
def publish():
    s("pipenv run twine upload dist/*", interactive=True)

@task
def build_and_publish():
    build()     # These are
    publish()   #  dependencies!
```

Then just call PePython!

```
$ pepython --help
Usage:
        pepython [--defs-path path-to-your-tasks-definitions.py] task [task params ...]

$ pepython clean
Executed task 'clean' successfuly.

$ pepython build_and_publish
Enter your username: your-name-here
Enter your password: ************
Uploading distributions to https://test.pypi.org/legacy/
Uploading pepython-0.1.0-py2-none-any.whl
100%|█████████████████████████████████████████████████████| 7.77k/7.77k [00:00<00:00, 42.6kB/s]
Uploading pepython-0.1.0.tar.gz
100%|█████████████████████████████████████████████████████| 5.65k/5.65k [00:01<00:00, 4.74kB/s]

Executed task 'build_and_publish' successfuly.
```

Note how **dependencies** are __just method calls__ in the body of the tasks themselves. This allows easy forwarding of params and a more flexible schema than some configured pre/post dependencies, like it's done in other tools.

If you need task **arguments**, they are defined naturally, again in plain Pyhton:

```python
@task
def task_args(first_arg, second_arg, *rest_of_args):
    print(
        f"You've passed {first_arg} and {second_arg} as "
        f"the 2 first parms, then passed:\n{rest_of_args}."
    )
```

```
$ pepython task_args a b c d e
You've passed a and b as the 2 first parms, then passed:
('c', 'd', 'e').

Executed task 'task_args' successfuly.
```

The main idea is to use the Python language for your task automation, with all of it's flexibility but without loosing the shell. This is why there's `s()` (short for _shell_).

`s()` is meant to to be easy to use. Above we saw how using the `interactive` option, the password prompt was **handled interactively by the user**, while other **non interactive processes** can be left to be managed by the task. We'll demonstrate it here, along with the `fail_fast` option, that when set to false, allows the task to manage the errors:

```python
@task
def process_python_files():
    ls_result = s("ls *py", fail_fast=False)

    if not ls_result.ok:
        exit("No python files here")

    python_files_raw = ls_result.value['out'].split("\n")
    python_files = [f.strip() for f in python_files_raw if f.strip()]

    print(
        f"These are the python files in this directory:\n{python_files}"
    )
```

```
$ pepython process_python_files
These are the python files in this directory:
['setup.py', 'tasks.py']

Executed task 'shell_returned_values' successfuly.
```

`s()` can also receive the `verbose` option so you can see the exit code, stdout and stderr printed as follows:

```
Executed shell command 'ls *py'
exit code was: 0
stdout was:
setup.py
tasks.py

stderr was:

```

## Contributing

Make sure you have the lastest `pip` and `pipenv` versions:

```bash
pip install --upgrade pip pipenv
```

To start developing, start the environment by:

```bash
pipenv shell
pipenv install -d
```

The installed `pepython` within the pipenv environment is the editable (alla `pip install -e .`) version of the package, so you can manually test right away.

This tool uses both [`pipenv`](https://pipenv.readthedocs.io/) for development and [`setuptools`](https://setuptools.readthedocs.io/) for packaging and distribution. To this date there is not a 100% community-accepted best practice so I've taken [this approach](https://github.com/pypa/pipenv/issues/209#issuecomment-337409290). In summary:

To add an _application_ dependency, add it in `setup.py` and leave it with a loose version definition. Then, just do `pipenv install -e .` to install the dependency. Pipenv locking mecanism will work as expected, since pepython itself is in the `[packages]` section of `Pipfile` (check `Pipfile.lock` and you'll find the deps there).

To add a _development_ dependency, add it to `Pipfile` via `pipenv install -d <my-dependency>`.

This way there's a single source of truth for package definition. No need to repeat the deps in `setup.py` and `Pipfile*`.

### Tests

To test the project run [`pytest`](https://docs.pytest.org/) inside the `pipenv`. Once you have something running, run [`tox`](https://github.com/tox-dev/tox) to check it's compatible with all python versions supported.

IMPORTANT: in order to make `tox` test with different python versions, those have to be installed. [`pyenv`](https://github.com/pyenv/pyenv) is used for that purpose and should work out of the box. Check the required versions in [`tox.ini`](https://github.com/nandilugio/bumpytrack/blob/master/tox.ini) and related files.

### Dev tasks automation and publishing to PyPI

This project uses `pepython` itself for automation. There you'll find tasks to build and publish the package to PyPI.

## License

This project is licensed under the MIT License - see the [`LICENSE`](https://github.com/nandilugio/pepython/blob/master/LICENSE) file for details.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nandilugio/pepython",
    "name": "pepython",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Fernando Stecconi",
    "author_email": "nandilugio@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/80/eb/0cf64b13dfa226ed3ce71908016ce964e2bf7f945d81afe057119a35fcb9/pepython-0.2.5.tar.gz",
    "platform": null,
    "description": "![CI](https://github.com/nandilugio/pepython/actions/workflows/ci.yml/badge.svg)\n\n**Current version:** 0.2.5\n\nTested with Python 3.8, 3,9, 3.10 and 3.11 on latest Linux, MacOS and Windows. Code is simple. Probably works in other versions and platforms.\n\n**Pypi:** https://pypi.org/project/pepython/ </br>\n**Github:** https://github.com/nandilugio/pepython\n\n# PePython\n\nNeed help organizing your project's tasks?\n\nDon't want to learn a complex tool with an unnecessarily cumbersome syntax or API?\n\nWant to specify your tasks __in plain Python__ still having easy and flexible __access to the shell__?\n\n**Just call PePython!**\n\n## Install\n\n```bash\npip install pepython\n```\n\n## Quick start\n\nDefine your tasks in a `tasks.py` file your root directory. Tasks are just __plain Python__ functions. Note how dependencies are just calls in the body of the tasks themselves, alowing all kinds of dependencies and parameter forwarding (see the parameters in action further down!).\n\n```python\nfrom pepython.task_def import task, s\n\n@task\ndef clean():\n    s(\"rm -rf build dist *.egg-info\")\n\n@task\ndef build():\n    clean()\n    s(\"pipenv run python setup.py sdist bdist_wheel\")\n\n@task\ndef publish():\n    s(\"pipenv run twine upload dist/*\", interactive=True)\n\n@task\ndef build_and_publish():\n    build()     # These are\n    publish()   #  dependencies!\n```\n\nThen just call PePython!\n\n```\n$ pepython --help\nUsage:\n        pepython [--defs-path path-to-your-tasks-definitions.py] task [task params ...]\n\n$ pepython clean\nExecuted task 'clean' successfuly.\n\n$ pepython build_and_publish\nEnter your username: your-name-here\nEnter your password: ************\nUploading distributions to https://test.pypi.org/legacy/\nUploading pepython-0.1.0-py2-none-any.whl\n100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 7.77k/7.77k [00:00<00:00, 42.6kB/s]\nUploading pepython-0.1.0.tar.gz\n100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 5.65k/5.65k [00:01<00:00, 4.74kB/s]\n\nExecuted task 'build_and_publish' successfuly.\n```\n\nNote how **dependencies** are __just method calls__ in the body of the tasks themselves. This allows easy forwarding of params and a more flexible schema than some configured pre/post dependencies, like it's done in other tools.\n\nIf you need task **arguments**, they are defined naturally, again in plain Pyhton:\n\n```python\n@task\ndef task_args(first_arg, second_arg, *rest_of_args):\n    print(\n        f\"You've passed {first_arg} and {second_arg} as \"\n        f\"the 2 first parms, then passed:\\n{rest_of_args}.\"\n    )\n```\n\n```\n$ pepython task_args a b c d e\nYou've passed a and b as the 2 first parms, then passed:\n('c', 'd', 'e').\n\nExecuted task 'task_args' successfuly.\n```\n\nThe main idea is to use the Python language for your task automation, with all of it's flexibility but without loosing the shell. This is why there's `s()` (short for _shell_).\n\n`s()` is meant to to be easy to use. Above we saw how using the `interactive` option, the password prompt was **handled interactively by the user**, while other **non interactive processes** can be left to be managed by the task. We'll demonstrate it here, along with the `fail_fast` option, that when set to false, allows the task to manage the errors:\n\n```python\n@task\ndef process_python_files():\n    ls_result = s(\"ls *py\", fail_fast=False)\n\n    if not ls_result.ok:\n        exit(\"No python files here\")\n\n    python_files_raw = ls_result.value['out'].split(\"\\n\")\n    python_files = [f.strip() for f in python_files_raw if f.strip()]\n\n    print(\n        f\"These are the python files in this directory:\\n{python_files}\"\n    )\n```\n\n```\n$ pepython process_python_files\nThese are the python files in this directory:\n['setup.py', 'tasks.py']\n\nExecuted task 'shell_returned_values' successfuly.\n```\n\n`s()` can also receive the `verbose` option so you can see the exit code, stdout and stderr printed as follows:\n\n```\nExecuted shell command 'ls *py'\nexit code was: 0\nstdout was:\nsetup.py\ntasks.py\n\nstderr was:\n\n```\n\n## Contributing\n\nMake sure you have the lastest `pip` and `pipenv` versions:\n\n```bash\npip install --upgrade pip pipenv\n```\n\nTo start developing, start the environment by:\n\n```bash\npipenv shell\npipenv install -d\n```\n\nThe installed `pepython` within the pipenv environment is the editable (alla `pip install -e .`) version of the package, so you can manually test right away.\n\nThis tool uses both [`pipenv`](https://pipenv.readthedocs.io/) for development and [`setuptools`](https://setuptools.readthedocs.io/) for packaging and distribution. To this date there is not a 100% community-accepted best practice so I've taken [this approach](https://github.com/pypa/pipenv/issues/209#issuecomment-337409290). In summary:\n\nTo add an _application_ dependency, add it in `setup.py` and leave it with a loose version definition. Then, just do `pipenv install -e .` to install the dependency. Pipenv locking mecanism will work as expected, since pepython itself is in the `[packages]` section of `Pipfile` (check `Pipfile.lock` and you'll find the deps there).\n\nTo add a _development_ dependency, add it to `Pipfile` via `pipenv install -d <my-dependency>`.\n\nThis way there's a single source of truth for package definition. No need to repeat the deps in `setup.py` and `Pipfile*`.\n\n### Tests\n\nTo test the project run [`pytest`](https://docs.pytest.org/) inside the `pipenv`. Once you have something running, run [`tox`](https://github.com/tox-dev/tox) to check it's compatible with all python versions supported.\n\nIMPORTANT: in order to make `tox` test with different python versions, those have to be installed. [`pyenv`](https://github.com/pyenv/pyenv) is used for that purpose and should work out of the box. Check the required versions in [`tox.ini`](https://github.com/nandilugio/bumpytrack/blob/master/tox.ini) and related files.\n\n### Dev tasks automation and publishing to PyPI\n\nThis project uses `pepython` itself for automation. There you'll find tasks to build and publish the package to PyPI.\n\n## License\n\nThis project is licensed under the MIT License - see the [`LICENSE`](https://github.com/nandilugio/pepython/blob/master/LICENSE) file for details.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple task automation for projects.",
    "version": "0.2.5",
    "project_urls": {
        "Homepage": "https://github.com/nandilugio/pepython"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dacc8783c6211f0ae124995d33aa7a38ab19b2d1ce2e6cbf475c1c29cfbc132e",
                "md5": "8e6f39e68091ff36f377b19cda8e5a5e",
                "sha256": "3dd024de1a3719529bc205970b2c81020e7775e81a847c6532fdbec845d61694"
            },
            "downloads": -1,
            "filename": "pepython-0.2.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8e6f39e68091ff36f377b19cda8e5a5e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7125,
            "upload_time": "2023-08-24T19:16:36",
            "upload_time_iso_8601": "2023-08-24T19:16:36.549376Z",
            "url": "https://files.pythonhosted.org/packages/da/cc/8783c6211f0ae124995d33aa7a38ab19b2d1ce2e6cbf475c1c29cfbc132e/pepython-0.2.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "80eb0cf64b13dfa226ed3ce71908016ce964e2bf7f945d81afe057119a35fcb9",
                "md5": "b540e501661c0902b952274003b1d226",
                "sha256": "72f741bf5acf621865fdd3262d1c78a5359a057aa6422fbaf76bb7127f7bc5ff"
            },
            "downloads": -1,
            "filename": "pepython-0.2.5.tar.gz",
            "has_sig": false,
            "md5_digest": "b540e501661c0902b952274003b1d226",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6475,
            "upload_time": "2023-08-24T19:16:38",
            "upload_time_iso_8601": "2023-08-24T19:16:38.433136Z",
            "url": "https://files.pythonhosted.org/packages/80/eb/0cf64b13dfa226ed3ce71908016ce964e2bf7f945d81afe057119a35fcb9/pepython-0.2.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-24 19:16:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nandilugio",
    "github_project": "pepython",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pepython"
}
        
Elapsed time: 0.13132s