Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rfrowe committed Jun 12, 2020
0 parents commit 8fec212
Show file tree
Hide file tree
Showing 15 changed files with 639 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish Python Package

on:
release:
types: [published]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools pipenv
pipenv install --dev
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
pipenv run python setup.py sdist
pipenv run twine upload dist/*
27 changes: 27 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Push CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install -U pip pipenv
pipenv install --dev
- name: Lint with flake8
uses: grantmcconnaughey/[email protected]
if: github.event_name == 'pull_request'
- name: Unit tests
run: |
pipenv run python -m unittest
133 changes: 133 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# IntelliJ
.DS_Store
.idea
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2020 Xevo Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
10 changes: 10 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[[source]]
name = 'pypi'
url = 'https://pypi.org/simple'
verify_ssl = true

[packages]
argexec = {editable = true, path = '.'}

[dev-packages]
argexec = {editable = true, path = '.', extras = ['dev']}
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Argexec

![Build status](https://img.shields.io/github/workflow/status/XevoInc/argexec/Push%20CI/master)
[![PyPI](https://img.shields.io/pypi/v/argexec)](https://pypi.org/project/argexec/)
![PyPI - License](https://img.shields.io/pypi/l/argexec)

An unobtrusive, elegant mechanism to provide seamless command line interfaces through argparse for Python functions.
All you have to do is decorate your function of choice with `@argexec` and away you go!

## Features
* Description parsing from docstring
* Argument help parsing from reStructuredText-like docstrings
* Argument type enforcement via [typeguard](https://github.com/agronholm/typeguard) from
[type hints](https://www.python.org/dev/peps/pep-0484/)
* Argument default values from function signature
* Support for the following argument types:
* All builtin primitives (`bool`, `int`, `float`, `str`, `bytes`)
* Fixed length tuples of a supported type
* Variable length tuples of a supported type
* Lists of a supported type
* Extensible, complex custom type parsing via [`dynamic_dispatch`](https://github.com/XevoInc/dynamic_dispatch)

## Install

You may install this via the [`argexec`](https://pypi.org/project/argexec/) package on [PyPi](https://pypi.org):

```bash
pip3 install argexec
```

## Usage

The decorator may be applied to any Python function that meets the following requirements:
* Is not a member function
* Has [PEP 484](https://www.python.org/dev/peps/pep-0484/) type hints for all parameters
* Does not use `*args` or `**kwargs`

Example (`foo.py`):
```python
#!/usr/bin/python3

from typing import Tuple

from argexec import argexec
from argexec.types import LogLevel

@argexec
def foo(w: int, x: Tuple[str, ...], y: LogLevel, z: bool = True):
"""
Hello, world!
:param w: foo.
:param x: bar.
:param y: baz.
:param z: qux.
"""
pass
```

```
$ ./foo.py --help
usage: scratch_1.py [-h] [-y] [--no-z] w [x [x ...]]
Hello, world!
positional arguments:
w [int] foo
x [Tuple[str, ...]] bar
optional arguments:
-h, --help show this help message and exit
-y, --y [LogLevel=CRITICAL] baz (more flags for lower level)
--no-z [bool=True] qux
```



## Development

When developing, it is recommended to use Pipenv. To create your development environment:

```bash
pipenv install --dev
```

### Testing

TODO
8 changes: 8 additions & 0 deletions argexec/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
An unobtrusive, elegant mechanism to provide seamless command line interfaces
through argparse for Python functions. All you have to do is decorate your
function of choice with `@argexec` and away you go!
"""

# Please sort alphabetically.
from ._decorator import argexec
Loading

0 comments on commit 8fec212

Please sign in to comment.