Skip to content

Commit

Permalink
taskify!
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonycorletti committed Apr 23, 2023
1 parent 9e9e97b commit f21d2ae
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 60 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@ end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[Makefile]
indent_style = tab
7 changes: 5 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ jobs:
cache: "pip"
cache-dependency-path: "pyproject.toml"

- name: install invoke
run: pip install invoke

- name: build
run: make build
run: inv build

- name: publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: make publish
run: inv publish
9 changes: 6 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ jobs:
cache: "pip"
cache-dependency-path: "pyproject.toml"

- name: install invoke
run: pip install invoke

- name: install
run: make install
run: inv install

- name: lint
run: make lint
run: inv lint

- name: test
run: make test
run: inv test
18 changes: 12 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,34 @@ You should see paths that use the .venv/bin in your current working directory.

## Installing dependencies

This project uses `pip` to manage our project's dependencies.
This project uses `pip` to manage our project's dependencies and all tasks are managed with `invoke`. Invoke is a python package that allows you to define tasks in a python file and run them from the command line, similar to `make` and `rake`, but with a pythonic syntax, it's really great!

Install dependencies;
In your virtual environment, install `invoke` by running;

```sh
make install
pip install invoke
```

Then to install the project's dependencies, run;

```sh
inv install
```

## Linting

```sh
make lint
inv lint
```

## Formatting

```sh
make format
inv format
```

## Tests

```sh
make test
inv test
```
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2021 Anthony Corletti
Copyright 2023 Anthony Corletti

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
42 changes: 0 additions & 42 deletions Makefile

This file was deleted.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ A minimal python project template that can be used for CLIs, APIs, GRPC, and oth
1. Replace all instances of `python_project_template` across the entire repository with the namespace of your project.
1. Rename the directory `python_project_template` with the same name too.
1. Replace `pyproject.toml` with relevant values for your project.
1. Use [pyenv](https://github.com/pyenv/pyenv) for managing your python environment.
1. Set up your virtual environment.
1. Run `make`
1. Follow the instructions in `CONTRIBUTING.md` to get started.
1. You're all set! Make this readme whatever you want now. The future is yours!
176 changes: 176 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,182 @@

PACKAGE_NAME = "python_project_template"
VERSION_FILE = f"{PACKAGE_NAME}/__init__.py"
SOURCES = " ".join(["python_project_template", "tests", "tasks.py"])


@task
def clean(ctx: Context) -> None:
"""clean
Remove all build, test, coverage and Python artifacts.
"""
ctx.run(
" ".join(
[
"rm -rf",
"build",
"dist",
"*.egg-info",
".pytest_cache",
".mypy_cache",
".coverage",
"htmlcov",
".ruff_cache",
"coverage.xml",
]
),
pty=True,
echo=True,
)


@task
def install(ctx: Context) -> None:
"""install
Install dependencies.
"""
ctx.run(
"pip install --upgrade pip",
pty=True,
echo=True,
)
ctx.run(
"pip install --no-cache-dir -e '.[dev,test]'",
pty=True,
echo=True,
)
ctx.run(
"pre-commit install",
pty=True,
echo=True,
)
ctx.run(
"pre-commit autoupdate",
pty=True,
echo=True,
)
ctx.run(
"if command -v pyenv 1>/dev/null 2>&1; then pyenv rehash; fi",
pty=True,
echo=True,
)


@task
def lint(ctx: Context) -> None:
"""lint
Check typing and formatting.
"""
ctx.run(
f"mypy {SOURCES}",
pty=True,
echo=True,
)
ctx.run(
f"black {SOURCES} --check",
pty=True,
echo=True,
)
ctx.run(
f"ruff {SOURCES}",
pty=True,
echo=True,
)


@task
def format(ctx: Context) -> None:
"""format
Format the code.
"""
ctx.run(
f"black {SOURCES}",
pty=True,
echo=True,
)
ctx.run(
f"ruff {SOURCES} --fix",
pty=True,
echo=True,
)


@task
def test(ctx: Context) -> None:
"""test
Run the tests.
"""
ctx.run(
" ".join(
[
"pytest",
"-o",
"console_output_style=progress",
"--disable-warnings",
"--cov=python_project_template",
"--cov=tests",
"--cov-report=term-missing",
"--cov-report=xml",
"--cov-report=html",
"--cov-fail-under=100",
]
),
pty=True,
echo=True,
)


@task
def build(ctx: Context) -> None:
"""build
Build the package.
"""
ctx.run(
"pip install --upgrade build",
pty=True,
echo=True,
)
ctx.run(
"python -m build",
pty=True,
echo=True,
)


@task
def publish(ctx: Context) -> None:
"""publish
Publish the package.
"""
ctx.run(
"pip install --upgrade twine",
pty=True,
echo=True,
)
ctx.run(
"twine upload dist/*",
pty=True,
echo=True,
)


@task
def all(ctx: Context) -> None:
"""all
Run all the tasks that matter for local dev.
"""
clean(ctx)
install(ctx)
format(ctx)
lint(ctx)
test(ctx)


@unique
Expand Down

0 comments on commit f21d2ae

Please sign in to comment.