Skip to content

Commit

Permalink
feat: Improve CLI usage
Browse files Browse the repository at this point in the history
This feature is a refactor.
The previous logic module is split
into multiple new modules.

Duties are not loaded in a global variable
anymore, but rather in a collection.

The underlying dependency, failprint,
was also updated to provide a function
that allows to reuse its CLI options.

Each duty on the CLI can now accept
flags to alter its context options
(quiet, silent, capture, etc.).
  • Loading branch information
pawamoy committed Jan 20, 2021
1 parent 3c94e2e commit 93e10cd
Show file tree
Hide file tree
Showing 27 changed files with 680 additions and 421 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 0.1.2
_commit: 0.1.11
_src_path: https://github.com/pawamoy/copier-poetry.git
author_email: pawamoy@pm.me
author_fullname: "Timoth\xE9e Mazzucotelli"
Expand Down
27 changes: 14 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Python 3.6
uses: actions/setup-python@v1
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Set up the cache
uses: actions/cache@v1
with:
path: .venv
key: cache-python-packages-2
key: quality-venv-cache

- name: Set up the project
run: |
pip install poetry safety
poetry install -v
pip install poetry
poetry install -vvv || { rm -rf .venv; poetry install -vvv; }
poetry update
- name: Check if the documentation builds correctly
run: poetry run duty check-docs
Expand All @@ -54,15 +55,16 @@ jobs:
run: poetry run duty check-types

- name: Check for vulnerabilities in dependencies
run: poetry run duty check-dependencies
run: |
pip install safety
poetry run duty check-dependencies
tests:

strategy:
max-parallel: 6
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]

runs-on: ${{ matrix.os }}

Expand All @@ -71,22 +73,21 @@ jobs:
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Set up the cache
uses: actions/cache@v1
env:
cache-name: cache-python-packages
with:
path: .venv
key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-2
key: tests-venv-cache-${{ matrix.os }}-py${{ matrix.python-version }}

- name: Set up the project
run: |
pip install poetry
poetry install -v
poetry install -vvv || { rm -rf .venv; poetry install -vvv; }
poetry update
- name: Run the test suite
run: poetry run duty test
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ SHELL := bash

DUTY = $(shell [ -n "${VIRTUAL_ENV}" ] || echo poetry run) duty

args = $(foreach a,$($(subst -,_,$1)_args),$(if $(value $a),$a="$($a)"))
check_code_quality_args = files
docs_serve_args = host port
release_args = version
test_args = match

BASIC_DUTIES = \
changelog \
clean \
combine \
coverage \
docs \
docs-deploy \
Expand All @@ -33,9 +38,8 @@ setup:

.PHONY: $(BASIC_DUTIES)
$(BASIC_DUTIES):
@$(DUTY) $@
@$(DUTY) $@ $(call args,$@)

.PHONY: $(QUALITY_DUTIES)
$(QUALITY_DUTIES):
@bash scripts/multirun.sh duty $@

@bash scripts/multirun.sh duty $@ $(call args,$@)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![ci](https://github.com/pawamoy/duty/workflows/ci/badge.svg)](https://github.com/pawamoy/duty/actions?query=workflow%3Aci)
[![documentation](https://img.shields.io/badge/docs-mkdocs%20material-blue.svg?style=flat)](https://pawamoy.github.io/duty/)
[![pypi version](https://img.shields.io/pypi/v/duty.svg)](https://pypi.org/project/duty/)
[![gitter](https://badges.gitter.im/join%20chat.svg)](https://gitter.im/duty/community)

A simple task runner.

Expand Down
1 change: 0 additions & 1 deletion config/coverage.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ precision = 2
omit =
src/duty/__init__.py
src/duty/__main__.py
duties.py
tests/*

[coverage:html]
Expand Down
1 change: 1 addition & 0 deletions docs/reference/collection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: duty.collection
1 change: 1 addition & 0 deletions docs/reference/context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: duty.context
1 change: 1 addition & 0 deletions docs/reference/decorator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: duty.decorator
1 change: 1 addition & 0 deletions docs/reference/exceptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: duty.exceptions
1 change: 0 additions & 1 deletion docs/reference/logic.md

This file was deleted.

21 changes: 5 additions & 16 deletions duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
PY_SRC_LIST = tuple(str(_) for _ in PY_SRC_PATHS)
PY_SRC = " ".join(PY_SRC_LIST)
TESTING = os.environ.get("TESTING", "0") in {"1", "true"}
CI = os.environ.get("CI", "0") in {"1", "true"}
CI = os.environ.get("CI", "0") in {"1", "true", "yes", ""}
WINDOWS = os.name == "nt"
PTY = not WINDOWS
PTY = not WINDOWS and not CI


def latest(lines: List[str], regex: Pattern) -> Optional[str]:
Expand Down Expand Up @@ -317,7 +317,7 @@ def docs(ctx):


@duty(pre=[docs_regen])
def docs_serve(ctx, host="127.0.0.1", port=8000):
def docs_serve(ctx, host: str = "127.0.0.1", port: int = 8000):
"""
Serve the documentation (localhost:8000).
Expand Down Expand Up @@ -358,7 +358,7 @@ def format(ctx): # noqa: W0622 (we don't mind shadowing the format builtin)


@duty
def release(ctx, version):
def release(ctx, version: str):
"""
Release a new Python package.
Expand All @@ -378,17 +378,6 @@ def release(ctx, version):
ctx.run("mkdocs gh-deploy", title="Deploying documentation", pty=PTY)


@duty
def combine(ctx):
"""
Combine coverage data from multiple runs.
Arguments:
ctx: The context instance (passed automatically).
"""
ctx.run("coverage combine --rcfile=config/coverage.ini")


@duty(silent=True)
def coverage(ctx):
"""
Expand All @@ -402,7 +391,7 @@ def coverage(ctx):


@duty(pre=[duty(lambda ctx: ctx.run("rm -f .coverage", silent=True))])
def test(ctx, match=""):
def test(ctx, match: str = ""):
"""
Run the test suite.
Expand Down
47 changes: 25 additions & 22 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ repo_url: "https://github.com/pawamoy/duty"
repo_name: "pawamoy/duty"

nav:
- Overview: index.md
- API Reference:
- cli.py: reference/cli.md
- logic.py: reference/logic.md
- Contributing: contributing.md
- Code of Conduct: code_of_conduct.md
- Changelog: changelog.md
- Credits: credits.md
- Overview: index.md
- Code Reference:
- cli.py: reference/cli.md
- collection.py: reference/collection.md
- context.py: reference/context.md
- decorator.py: reference/decorator.md
- exceptions.py: reference/exceptions.md
- Contributing: contributing.md
- Code of Conduct: code_of_conduct.md
- Changelog: changelog.md
- Credits: credits.md

theme:
name: material
Expand All @@ -22,21 +25,21 @@ theme:
accent: purple

extra_css:
- css/mkdocstrings.css
- css/mkdocstrings.css

markdown_extensions:
- admonition
- markdown_include.include
- pymdownx.emoji
- pymdownx.magiclink
- pymdownx.superfences
- pymdownx.tabbed
- pymdownx.tasklist
- toc:
permalink: "¤"
- admonition
- markdown_include.include
- pymdownx.emoji
- pymdownx.magiclink
- pymdownx.superfences
- pymdownx.tabbed
- pymdownx.tasklist
- toc:
permalink: "¤"

plugins:
- search
- mkdocstrings:
watch:
- src/duty
- search
- mkdocstrings:
watch:
- src/duty
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "duty"
Expand All @@ -20,7 +20,7 @@ include = [

[tool.poetry.dependencies]
python = "^3.6"
failprint = "^0.6.0"
failprint = "^0.6.2"

[tool.poetry.dev-dependencies]
autoflake = "^1.4"
Expand All @@ -40,7 +40,7 @@ jinja2-cli = "^0.7.0"
markdown-include = "^0.6.0"
mkdocs = "^1.1.2"
mkdocs-material = "^5.5.12"
mkdocstrings = "^0.13.1"
mkdocstrings = "^0.14.0"
mypy = "^0.782"
pytest = "^6.0.1"
pytest-cov = "^2.10.1"
Expand Down Expand Up @@ -116,7 +116,7 @@ exclude = ["tests/fixtures"]
"-WPS322", # multi-line strings (incompatible with attributes docstrings)
"-WPS326", # implicit string concatenation
"-WPS336", # explicit string concatenation
"-WPS402", # nosa overuse
"-WPS402", # noqa overuse
"-WPS412", # __init__ modules with logic
"-WPS428", # statement with no effect (not compatible with attribute docstrings)
"-WPS433", # redundant with C0415 (not top-level import)
Expand Down
2 changes: 1 addition & 1 deletion scripts/multirun.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

PYTHON_VERSIONS="${PYTHON_VERSIONS:-3.6 3.7 3.8}"
PYTHON_VERSIONS="${PYTHON_VERSIONS:-3.6 3.7 3.8 3.9}"

if [ -n "${PYTHON_VERSIONS}" ]; then
for python_version in ${PYTHON_VERSIONS}; do
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

PYTHON_VERSIONS="${PYTHON_VERSIONS:-3.6 3.7 3.8}"
PYTHON_VERSIONS="${PYTHON_VERSIONS:-3.6 3.7 3.8 3.9}"

install_with_pipx() {
if ! command -v "$1" &>/dev/null; then
Expand Down
2 changes: 1 addition & 1 deletion src/duty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

from typing import List

from duty.logic import duty
from duty.decorator import duty

__all__: List[str] = ["duty"] # noqa: WPS410 (the only __variable__ we use)
Loading

0 comments on commit 93e10cd

Please sign in to comment.