Skip to content

Commit

Permalink
Modernized
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsca committed Jan 20, 2023
1 parent a5bdf1d commit c33c1d6
Show file tree
Hide file tree
Showing 24 changed files with 1,412 additions and 336 deletions.
50 changes: 50 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[flake8]

application-package-names = proper_cli
application-import-names = proper_cli
import-order-style = pycharm

select =
# bugbear
B,
# mccabe, comprehensions, commas
C,
# pycodestyle errors
E,
# pyflakes
F,
# logging format
G,
# imports
I,
P,
# quotes
Q,
# pycodestyle warnings
W,

ignore =
# x is too complex
C901,
# whitespace before ':'
E203,
E501,
# x defined from star imports
F405,
# line break before binary operator
W503,
W605,

max-line-length = 92
max-complexity = 10

inline-quotes = double
multiline-quotes = double
docstring-quotes = double

exclude =
.git,
.venv,
__pycache__,
conftest.py,
docs,
14 changes: 9 additions & 5 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: pip install -U pip wheel
- run: pip install -e .[test]
- name: "Installs dependencies"
run: |
curl -sSL https://install.python-poetry.org | python3 -
- run: ~/.local/share/pypoetry/venv/bin/poetry install --with test
- run: make lint
tests:
name: tests
strategy:
matrix:
python: ['3.7', '3.8', '3.9', '3.10']
python: ['3.9', '3.10', '3.11']
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- run: pip install -U pip wheel
- run: pip install -e .[test]
- name: "Installs dependencies"
run: |
curl -sSL https://install.python-poetry.org | python3 -
- run: ~/.local/share/pypoetry/venv/bin/poetry install --with test
- run: make test
29 changes: 29 additions & 0 deletions .github/workflows/upload-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Upload to PyPI

on:
# Triggers the workflow when a release is created
release:
types: [released]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9

- name: "Installs poetry"
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: "Builds and uploads to PyPI"
run: |
~/.local/share/pypoetry/venv/bin/poetry build
~/.local/share/pypoetry/venv/bin/poetry publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.TOKEN_PYPI }}
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
exclude: ^(docs/)
default_stages: [push]
fail_fast: true
repos:
- repo: local
hooks:
- id: flake8
name: flake8
entry: flake8 --config=setup.cfg proper_cli tests
entry: make lint
language: system
types: [python]
pass_filenames: false
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
.PHONY: test
test:
pytest -x proper_cli tests
poetry run pytest -x src/proper_cli tests

.PHONY: lint
lint:
flake8 --config=setup.cfg proper_cli tests
poetry run flake8 src/proper_cli tests

.PHONY: coverage
coverage:
pytest --cov-report html --cov proper_cli proper_cli tests
poetry run pytest --cov-config=pyproject.toml --cov-report html --cov proper_cli src/proper_cli tests

.PHONY: types
types:
poetry run pyright src/proper_cli

.PHONY: install
install:
pip install -e .[test,dev]
# pre-commit install --hook-type pre-push
poetry install --with dev,test
poetry run pre-commit install
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ python run.py first -arg1 -no-arg2
```


### Subcommands
### Subgroups

If an attribute is a subclass of `proper_cli.Cli`, it will be a subcommand:
If an attribute is a subclass of `proper_cli.Cli`, it will be a subgroup:

```python
from proper_cli import Cli
Expand All @@ -70,7 +70,7 @@ class DBSub(Cli):
pass

class Manage(Cli):
# A subcommand
# A subgroup
db = DBSub # NOT `DBSub()`
```

Expand Down Expand Up @@ -137,7 +137,7 @@ class MyCli(Cli):
"""Simple program that greets NAME for a total of COUNT times."""
pass

# A subcommand!
# A subgroup!
db = DBCli


Expand All @@ -151,7 +151,7 @@ if __name__ == "__main__":

## Coloring the Output

Whenever you output text, you can surround the text with tags to color its output.
Whenever you output text, you can surround the text with tags to color its output (thanks to https://github.com/sdispater/pastel).
This is automatically enabled for the docstrings, but you can also have it by using `proper_cli.echo()`
as a drop-in replacement of `print()`.

Expand Down
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
pass

# A subcommand!
# A group!
db = DBCli


Expand Down
Binary file modified output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c33c1d6

Please sign in to comment.