Skip to content

Commit

Permalink
improve task runner (#49)
Browse files Browse the repository at this point in the history
use poethepoet as task runner, and update some of the runner. also
update the github action to use the task runner
  • Loading branch information
kiraware committed Sep 18, 2024
1 parent fff66bc commit c295435
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 52 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ jobs:
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
key: venv-dev-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --with docs
- name: Activate virtual environment
run: source $VENV
- name: Lint with Ruff
run: poetry run ruff check
run: poetry run poe ruff
- name: Check code security with Bandit
run: poetry run bandit -c pyproject.toml -r .
run: poetry run poe bandit
- name: Typing with mypy
run: poetry run mypy
run: poetry run poe mypy
- name: Format with Ruff
run: poetry run ruff format --check
run: poetry run poe format-check
- name: Build docs with Material for MkDocs
run: poetry run mkdocs build
run: poetry run poe docs-build
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ jobs:
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
key: venv-test-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --without dev,docs
run: poetry install --no-interaction --no-root
- name: Activate virtual environment
run: source $VENV
- name: Test with pytest
run: poetry run pytest --cov=src --cov-report=xml
run: poetry run poe test --cov-report=xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
53 changes: 43 additions & 10 deletions docs/how-to-guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The pull request submitted must be very specific so that
one pull request specifically describes one change.

First clone the forked repository with the
following command:
following command

```console
git clone https://github.com/YOUR-USERNAME/PyBMKG
Expand All @@ -49,7 +49,7 @@ git clone https://github.com/YOUR-USERNAME/PyBMKG
Then create a branch for pull requests in the fork
repository with a short branch name that explains in
general what pull request will be submitted. For
example in the following command:
example in the following command

```console
git branch fix-docs-typos
Expand All @@ -65,15 +65,15 @@ git switch fix-docs-typos
After that, make sure your terminal's working directory
is active in the PyBMKG folder and [pre-commit](https://pre-commit.com/)
is installed globally. Then to install pre-commit git
hook use the following command:
hook use the following command

```console
pre-commit install
```

We use [Poetry](https://python-poetry.org/) as the project
packaging and dependency management. Install development
dependency with the following command:
dependency with the following command

```console
poetry install
Expand All @@ -94,20 +94,26 @@ We use [Ruff](https://docs.astral.sh/ruff/) as a linter,
[mypy](https://mypy.readthedocs.io/en/stable/) as a static type
checker, and [Bandit](https://bandit.readthedocs.io/en/latest/)
for find common security issues in Python code. To run the Ruff,
mypy and Bandit linter together you can use the following command:
mypy and Bandit linter together you can use the following command

```console
poetry run poe lint
```

Or if you want to do it one by one you can use the following command:
Or if you want to do it one by one you can use the following command

```console
poetry run poe ruff
poetry run poe mypy
poetry run poe bandit
```

For fix lint with ruff, run

```console
poetry run poe ruff-fix
```

### Formatting

We use [Ruff](https://docs.astral.sh/ruff/) also as a formatter.
Expand All @@ -117,15 +123,27 @@ To run Ruff formatter you can use the following command
poetry run poe format
```

If you want to check only, use

```console
poetry run poe format-check
```

### Testing

We use [pytest](https://docs.pytest.org/en/stable/) for testing.
To run pytest you can use the following command:
To run pytest you can use the following command

```console
poetry run poe test
```

To pass more argument to pytest, use like the following example

```console
poetry run poe test --cov-report=html
```

We really pay attention to testing coverage, therefore to
contribute we are expected to make tests and if possible increase
the code coverage.
Expand All @@ -135,7 +153,7 @@ the code coverage.
We use [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/)
as static site documentation with markdown. PyBMKG does not include
docs dependencies by default, to install it you can use the
following command:
following command

```console
poetry install --with docs
Expand All @@ -144,10 +162,16 @@ poetry install --with docs
Documentation is very important to make it easier for users to use
a library. So writing documentation for changes to contributed code
is very important. To run development mode you can use the following
command:
command

```console
poetry run poe docs-serve
```

And to build the documentation use the following command

```console
poetry run mkdocs serve
poetry run poe docs-build
```

### Releasing
Expand All @@ -158,6 +182,15 @@ to the workflow is in the GitHub environment with the name `production`.
Each release tag must be the same as `version` in `pyproject.toml` in
the `tool.poetry` section.

### Update Dependency

We use GitHub dependabot to automatically update dependency and GitHub
action. To update the dependency in pre-commit, you can use command

```console
pre-commit autoupdate
```

### License

By contributing to PyBMKG, you agree that your contributions will be
Expand Down
46 changes: 13 additions & 33 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ name = "PyBMKG"
version = "2.1.1"
description = "Python BMKG API Wrapper"
authors = ["Kira <kiraware@github.com>"]
maintainers = [
"Kira <kiraware@github.com>",
"vexra <vexra@github.com>",
]
packages = [
{ include = "*", from = "src" }
]
maintainers = ["Kira <kiraware@github.com>", "vexra <vexra@github.com>"]
packages = [{ include = "*", from = "src" }]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/kiraware/PyBMKG"
Expand Down Expand Up @@ -53,7 +48,7 @@ optional = true
[tool.poetry.group.docs.dependencies]
mkdocs = "^1.5.3"
mkdocs-material = "^9.5.4"
mkdocstrings = {extras = ["python"], version = "^0.25.0"}
mkdocstrings = { extras = ["python"], version = "^0.25.0" }

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand All @@ -63,10 +58,14 @@ backend-path = ["src"]
[tool.poe.tasks]
bandit = "bandit -c pyproject.toml -r ."
mypy = "mypy"
ruff = "ruff check --fix"
ruff-fix = "ruff check --fix"
ruff = "ruff check"
lint = ["bandit", "mypy", "ruff"]
format-check = "ruff format --check"
format = "ruff format"
test = "pytest --cov=src --cov-report=html"
docs-build = "poetry run mkdocs build"
docs-serve = "poetry run mkdocs serve"
test = "pytest --cov=src"

[tool.bandit]
targets = ["src", "tests"]
Expand All @@ -80,39 +79,20 @@ files = ["src", "tests"]
strict_optional = false

[tool.ruff]
exclude = [
".venv",
".git",
"__pycache__",
"build",
"dist",
"venv",
]
exclude = [".venv", ".git", "__pycache__", "build", "dist", "venv"]
line-length = 88
target-version = "py311"
src = ["src", "tests"]

[tool.ruff.lint]
select = [
"E",
"F",
"W",
"I",
]
select = ["E", "F", "W", "I"]
ignore = []

[tool.ruff.format]
docstring-code-format = true

[tool.pytest.ini_options]
addopts = [
"-vvv",
"--doctest-modules",
"--import-mode=importlib",
]
pythonpath = [
".",
"src",
]
addopts = ["-vvv", "--doctest-modules", "--import-mode=importlib"]
pythonpath = [".", "src"]
testpaths = ["tests", "src"]
asyncio_mode = "auto"

0 comments on commit c295435

Please sign in to comment.