Skip to content

Commit 0a55256

Browse files
Eric Lopesnullhack
andcommitted
Check code on every push (#14)
Co-authored-by: Eric Lopes <nullhack@users.noreply.github.com> Reviewed-on: https://gitea.eol.myds.me/cluster-projects/python-project-template/pulls/14
1 parent 02da7f0 commit 0a55256

File tree

10 files changed

+647
-460
lines changed

10 files changed

+647
-460
lines changed

.github/workflows/check-code.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Check Code standards
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
set-up-docker:
8+
runs-on: ubuntu-latest
9+
steps:
10+
-
11+
name: Checkout
12+
uses: actions/checkout@v4
13+
-
14+
name: Install ruff and cookiecutter
15+
run: |
16+
apt update && apt install -y python3-pip && pip install ruff cookiecutter
17+
-
18+
name: run cookiecutter
19+
run: |
20+
cookiecutter . --no-input
21+
-
22+
name: lint tests
23+
run: |
24+
cd python-project-example
25+
echo 'Code check tests:'
26+
ruff check
27+
echo 'Code format tests:'
28+
ruff format --diff
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
name: Release Docker Image CI/CD
3+
4+
on:
5+
release:
6+
types:
7+
- published
8+
9+
jobs:
10+
set-up-docker:
11+
runs-on: ubuntu-latest
12+
steps:
13+
-
14+
name: Checkout
15+
uses: actions/checkout@v4
16+
-
17+
name: Install docker
18+
run: apt update && apt install -y docker-compose
19+
-
20+
name: Login to Docker Hub
21+
uses: docker/login-action@v3
22+
with:
23+
registry: ${{ vars.DOCKER_REGISTRY_URL }}
24+
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
25+
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
26+
-
27+
name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
-
30+
name: Build and push
31+
uses: docker/build-push-action@v5
32+
with:
33+
context: .
34+
file: ./Dockerfile
35+
push: true
36+
tags: ${{ vars.DOCKER_REGISTRY_URL }}/${{ github.event.repository.name }}:${{ github.ref_name }}
37+

{{cookiecutter.project_slug}}/.github/workflows/check-code.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ jobs:
1212
name: Checkout
1313
uses: actions/checkout@v4
1414
-
15-
name: Install ruff and black
15+
name: Install ruff
1616
run: |
1717
python -m pip install --upgrade pip
18-
pip install black ruff
18+
pip install ruff
1919
-
2020
name: run ruff
2121
run: |
2222
ruff check **/*.py
2323
-
24-
name: run poetry
24+
name: run ruff format
2525
run: |
26-
black **/*.py
26+
ruff format **/*.py
2727
{% endraw %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: {{cookiecutter.package_name}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: tests

{{cookiecutter.project_slug}}/docs/mkdocs.yaml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ repo_url: https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.pro
88

99
plugins:
1010
- search
11-
- mkapi
11+
- mkdocstrings:
12+
handlers:
13+
python:
14+
options:
15+
show_submodules: true
16+
show_if_no_docstring: true
17+
modernize_annotations: true
18+
separate_signature: true
19+
docstring_section_style: list
1220
- awesome-pages
1321
- gen-files:
1422
scripts:
@@ -21,17 +29,7 @@ theme:
2129
scheme: default
2230
primary: blue
2331
accent: amber
24-
toggle:
25-
icon: material/lightbulb-outline
26-
name: Switch to light mode
27-
- media: '(prefers-color-scheme: dark)'
28-
scheme: slate
29-
primary: black
30-
accent: amber
31-
toggle:
32-
icon: material/lightbulb
33-
name: Switch to dark mode
34-
features:
32+
atures:
3533
- search.suggest
3634
- search.highlight
3735
- content.tabs.link
@@ -41,11 +39,9 @@ theme:
4139
#favicon: img/favicon.png
4240
language: en
4341

44-
4542
nav:
4643
- index.md
4744
- ... | glob=readme.md
45+
- reference.md
4846
- ... | regex=scenarios/.+.md
49-
- API: mkapi/api/{{cookiecutter.package_name}}
50-
- Tests: mkapi/tests/tests
51-
47+
- tests.md

{{cookiecutter.project_slug}}/poetry.lock

Lines changed: 540 additions & 408 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,24 @@ packages = [
1313
]
1414

1515
[tool.poetry.dependencies]
16-
python = "^3.10"
16+
python = "^3.11"
1717

1818
[tool.poetry.group.dev.dependencies]
1919
pre-commit = "^2.18.1"
20-
black = {version = "^22.3.0", allow-prereleases = true}
2120
xdoctest = "^1.0.0"
2221
poethepoet = "^0.16.4"
23-
ruff = "^0.0.253"
24-
pytest = "7.1.1"
25-
pytest-html = "^3.1.1"
26-
pytest-sugar = "^0.9.6"
27-
pytest-reverse = "^1.5.0"
28-
pytest-cov = "^3.0.0"
29-
pytest-bdd = "^6.1.1"
30-
mkdocs = "^1.4.2"
31-
mkdocs-material = "^8.5.10"
32-
mkdocs-gen-files = "^0.4.0"
33-
mkdocs-awesome-pages-plugin = "^2.8.0"
34-
mkapi = "^1.0.14"
22+
ruff = ">=0.1.7"
23+
pytest = ">=7.1.1"
24+
pytest-html = ">=4.1.0"
25+
pytest-sugar = ">=0.9.6"
26+
pytest-cov = ">=5.0.0"
27+
pytest-xdist = ">=3.6.1"
28+
pytest-bdd = ">=7.1.2"
29+
mkdocs = ">=1.6.0"
30+
mkdocs-material = ">=9.5.0"
31+
mkdocs-gen-files = ">=0.5.0"
32+
mkdocs-awesome-pages-plugin = ">=2.9.2"
33+
mkdocstrings = {extras = ["python"], version = "^0.25.1"}
3534

3635
[tool.poetry.scripts]
3736
-c = "poethepoet:main"
@@ -40,15 +39,10 @@ mkapi = "^1.0.14"
4039
requires = ["poetry-core>=1.0.0"]
4140
build-backend = "poetry.core.masonry.api"
4241

43-
[tool.black]
44-
line-length = 79
45-
target-version = ['py310']
46-
include = '\.pyi?$'
47-
4842
[tool.ruff]
49-
ignore = ["E501"]
43+
lint.ignore = ["E501"]
5044
line-length = 79
51-
select = [
45+
lint.select = [
5246
"C9",
5347
"E",
5448
"F",
@@ -66,21 +60,20 @@ select = [
6660
]
6761

6862

69-
[tool.ruff.mccabe]
63+
[tool.ruff.lint.mccabe]
7064
max-complexity = 10
7165

72-
[tool.ruff.pydocstyle]
66+
[tool.ruff.lint.pydocstyle]
7367
convention = "google"
7468

75-
[tool.ruff.per-file-ignores]
69+
[tool.ruff.lint.per-file-ignores]
7670
"tests/*" = ["S101"]
7771

7872
[tool.pytest.ini_options]
7973
minversion = "6.0"
8074
addopts = """
8175
--verbose \
8276
--maxfail=1 \
83-
--reverse \
8477
--color=yes \
8578
--cov={{cookiecutter.package_name}} \
8679
--html=docs/pytest_report.html \
@@ -119,9 +112,9 @@ test = "pytest"
119112
install-pre-commit = "pre-commit install"
120113
run-pre-commit = "pre-commit run --all-files"
121114
pre-commit = ["install-pre-commit", "run-pre-commit"]
122-
lint-ruff = "ruff check **/*.py --fix"
123-
lint-black = "black **/*.py"
124-
lint = ["lint-black", "lint-ruff"]
115+
ruff-check = "ruff check **/*.py --fix"
116+
ruff-format = "ruff format **/*.py"
117+
lint = ["ruff-check", "ruff-format"]
125118
doc = "mkdocs serve --use-directory-urls -f docs/mkdocs.yaml"
126119
doc-html = "mkdocs build --no-directory-urls -f docs/mkdocs.yaml"
127120
doc-publish = """mkdocs gh-deploy \

{{cookiecutter.project_slug}}/tests/scenarios/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
as test files in pytest. The new features will trigger errors because
55
steps are not implemented.
66
"""
7+
78
from pathlib import Path
89

910
import pytest
@@ -31,7 +32,6 @@ def pytest_configure(config: pytest.Config) -> None:
3132
features = []
3233

3334
for feat in features:
34-
3535
feature_dir = Path(feat.filename).parent
3636
file_dir = (
3737
conftest_dir / "steps" / feature_dir.relative_to(features_base_dir)

{{cookiecutter.project_slug}}/tests/{{cookiecutter.package_name}}_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
* Prefer tmpdir over global test artifacts
1212
1313
"""
14-
from typing import TypeVar
14+
15+
from typing import Self
1516

1617
import pytest
1718

1819
from {{cookiecutter.package_name}} import {{cookiecutter.module_name}} as m
1920

20-
Self = TypeVar("Self", bound="TestGroup")
21-
2221

2322
@pytest.mark.parametrize(
2423
("param1", "param2"),

0 commit comments

Comments
 (0)