Skip to content

Commit 07c3b67

Browse files
authored
Merge pull request #28 from tnijboer/v2
feat: add ruff, remove black, add github actions
2 parents 9dac232 + f866c6f commit 07c3b67

File tree

12 files changed

+491
-140
lines changed

12 files changed

+491
-140
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ end_of_line = lf
55
insert_final_newline = true
66
indent_style = space
77
indent_size = 4
8+
9+
[*.{yml,yaml}]
10+
end_of_line = lf
11+
insert_final_newline = true
12+
charset = utf-8
13+
indent_style = space
14+
indent_size = 2
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Bootstrap Poetry
2+
description: Configure the environment with the specified Python and Poetry version.
3+
4+
inputs:
5+
python-version:
6+
description: Desired node-semver compatible Python version expression (or 'default')
7+
default: "default"
8+
python-latest:
9+
description: Use an uncached Python if a newer match is available
10+
default: "false"
11+
poetry-spec:
12+
description: pip-compatible installation specification to use for Poetry
13+
default: "poetry"
14+
15+
outputs:
16+
python-path:
17+
description: Path to the installed Python interpreter
18+
value: ${{ steps.setup-python.outputs.python-path }}
19+
python-version:
20+
description: Version of the installed Python interpreter
21+
value: ${{ steps.setup-python.outputs.python-version }}
22+
23+
runs:
24+
using: composite
25+
steps:
26+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
27+
id: setup-python
28+
if: inputs.python-version != 'default'
29+
with:
30+
python-version: ${{ inputs.python-version }}
31+
check-latest: ${{ inputs.python-latest == 'true' }}
32+
allow-prereleases: true
33+
update-environment: false
34+
35+
- run: pipx install ${PYTHON_PATH:+--python "$PYTHON_PATH"} "${POETRY_SPEC}"
36+
shell: bash
37+
env:
38+
PYTHON_PATH: ${{ inputs.python-version != 'default' && steps.setup-python.outputs.python-path || '' }}
39+
POETRY_SPEC: ${{ inputs.poetry-spec }}
40+
41+
# Use Poetry Python for virtual environments
42+
# (Otherwise, the system Python will be used per default instead of the Python version we just installed)
43+
- run: poetry config virtualenvs.use-poetry-python true
44+
shell: bash
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Poetry Install
2+
description: Run `poetry install` with optional artifact and metadata caching
3+
4+
inputs:
5+
args:
6+
description: Arguments for `poetry install`
7+
cache:
8+
description: Enable transparent Poetry artifact and metadata caching
9+
default: "true"
10+
11+
outputs:
12+
cache-hit:
13+
description: Whether an exact cache hit occured
14+
value: ${{ steps.cache.outputs.cache-hit }}
15+
16+
runs:
17+
using: composite
18+
steps:
19+
- run: printf 'cache-dir=%s\n' "$(poetry config cache-dir)" >> $GITHUB_OUTPUT
20+
id: poetry-config
21+
shell: bash
22+
23+
# Bust the cache every 24 hours to prevent it from expanding over time.
24+
- run: printf 'date=%s\n' "$(date -I)" >> $GITHUB_OUTPUT
25+
id: get-date
26+
if: inputs.cache == 'true'
27+
shell: bash
28+
29+
- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
30+
id: cache
31+
if: inputs.cache == 'true'
32+
with:
33+
path: |
34+
${{ steps.poetry-config.outputs.cache-dir }}/artifacts
35+
${{ steps.poetry-config.outputs.cache-dir }}/cache
36+
key: poetry-${{ steps.get-date.outputs.date }}-${{ runner.os }}-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
37+
# The cache is cross-platform, and other platforms are used to seed cache misses.
38+
restore-keys: |
39+
poetry-${{ steps.get-date.outputs.date }}-${{ runner.os }}-
40+
poetry-${{ steps.get-date.outputs.date }}-
41+
enableCrossOsArchive: true
42+
43+
- run: poetry install ${ARGS}
44+
shell: bash
45+
env:
46+
ARGS: ${{ inputs.args }}
47+
48+
- run: poetry env info
49+
shell: bash
50+
51+
- run: poetry show
52+
shell: bash
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Reusable workflow consumed by tests.yaml; used to share a single matrix across jobs.
2+
on:
3+
workflow_call:
4+
inputs:
5+
runner:
6+
required: true
7+
type: string
8+
python-version:
9+
required: true
10+
type: string
11+
run-mypy:
12+
required: true
13+
type: boolean
14+
run-pytest:
15+
required: true
16+
type: boolean
17+
run-ruff-format:
18+
required: true
19+
type: boolean
20+
run-ruff-check:
21+
required: true
22+
type: boolean
23+
24+
defaults:
25+
run:
26+
shell: bash
27+
28+
env:
29+
PYTHONWARNDEFAULTENCODING: "true"
30+
31+
jobs:
32+
mypy:
33+
name: mypy
34+
runs-on: ${{ inputs.runner }}
35+
if: inputs.run-mypy
36+
steps:
37+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38+
with:
39+
persist-credentials: false
40+
41+
- uses: ./.github/actions/bootstrap-poetry
42+
id: bootstrap-poetry
43+
with:
44+
python-version: ${{ inputs.python-version }}
45+
46+
- uses: ./.github/actions/poetry-install
47+
48+
- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
49+
with:
50+
path: .mypy_cache
51+
key: mypy-${{ runner.os }}-py${{ steps.bootstrap-poetry.outputs.python-version }}-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
52+
restore-keys: |
53+
mypy-${{ runner.os }}-py${{ steps.bootstrap-poetry.outputs.python-version }}-
54+
mypy-${{ runner.os }}-
55+
56+
- run: poetry run mypy
57+
58+
pytest:
59+
name: pytest
60+
runs-on: ${{ inputs.runner }}
61+
if: inputs.run-pytest
62+
steps:
63+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
64+
with:
65+
persist-credentials: false
66+
67+
- uses: ./.github/actions/bootstrap-poetry
68+
with:
69+
python-version: ${{ inputs.python-version }}
70+
71+
- uses: ./.github/actions/poetry-install
72+
with:
73+
args: --with github-actions
74+
75+
- run: poetry run pytest -v
76+
- run: git diff --exit-code --stat HEAD
77+
78+
ruff-format:
79+
name: ruff-format
80+
runs-on: ${{ inputs.runner }}
81+
if: inputs.run-ruff-format
82+
steps:
83+
- uses: astral-sh/ruff-action@v3
84+
with:
85+
args: "format --check --diff"

.github/workflows/tests.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
merge_group:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
10+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
11+
12+
defaults:
13+
run:
14+
shell: bash
15+
16+
permissions: {}
17+
18+
jobs:
19+
changes:
20+
name: Detect changed files
21+
runs-on: ubuntu-latest
22+
outputs:
23+
project: ${{ steps.changes.outputs.project }}
24+
fixtures-pypi: ${{ steps.changes.outputs.fixtures-pypi }}
25+
src: ${{ steps.changes.outputs.src }}
26+
tests: ${{ steps.changes.outputs.tests }}
27+
steps:
28+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
with:
30+
persist-credentials: false
31+
32+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
33+
id: changes
34+
with:
35+
filters: |
36+
workflow: &workflow
37+
- '.github/actions/**'
38+
- '.github/workflows/tests.yaml'
39+
- '.github/workflows/.tests-matrix.yaml'
40+
project: &project
41+
- *workflow
42+
- 'poetry.lock'
43+
- 'pyproject.toml'
44+
src:
45+
- *project
46+
- 'src/**/*.py'
47+
tests:
48+
- *project
49+
- 'src/**/*.py'
50+
- 'tests/**'
51+
52+
lockfile:
53+
name: Check poetry.lock
54+
runs-on: ubuntu-latest
55+
if: needs.changes.outputs.project == 'true'
56+
needs: changes
57+
steps:
58+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
59+
with:
60+
persist-credentials: false
61+
62+
- uses: ./.github/actions/bootstrap-poetry
63+
64+
- run: poetry check --lock
65+
66+
tests-matrix:
67+
# Use this matrix with multiple jobs defined in a reusable workflow:
68+
uses: ./.github/workflows/.tests-matrix.yaml
69+
name: "Python ${{ matrix.python-version }}"
70+
if: "!failure()"
71+
needs:
72+
- changes
73+
- lockfile
74+
with:
75+
runner: ubuntu-latest
76+
python-version: ${{ matrix.python-version }}
77+
run-mypy: ${{ needs.changes.outputs.tests == 'true' }}
78+
run-pytest: ${{ needs.changes.outputs.tests == 'true' }}
79+
secrets: inherit
80+
strategy:
81+
matrix:
82+
python-version:
83+
- "3.9"
84+
- "3.10"
85+
- "3.11"
86+
- "3.12"
87+
- "3.13"
88+
fail-fast: false
89+
90+
status:
91+
name: Status
92+
runs-on: ubuntu-latest
93+
if: always()
94+
needs:
95+
- lockfile
96+
- tests-matrix
97+
steps:
98+
- run: ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 'false' || 'true' }}

.pre-commit-config.yaml

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,78 @@
1-
# See https://pre-commit.com for more information
2-
# See https://pre-commit.com/hooks.html for more hooks
1+
ci:
2+
autofix_commit_msg: "chore(pre-commit): autofix run"
3+
autoupdate_commit_msg: "chore(pre-commit): autoupdate hooks"
4+
5+
default_install_hook_types:
6+
- pre-commit
7+
- commit-msg
8+
- post-checkout
9+
- post-merge
10+
311
repos:
4-
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v3.2.0
6-
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- repo: local
10-
hooks:
11-
- id: black
12-
name: black
13-
entry: bash -c 'poetry run black .'
14-
require_serial: true
15-
language: system
16-
types: [python]
17-
pass_filenames: false
18-
files: ^src/clearskies/
19-
- id: pytest
20-
name: pytest
21-
entry: bash -c 'cd src && poetry run pytest'
22-
require_serial: true
23-
language: system
24-
types: [python]
25-
pass_filenames: false
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v5.0.0
14+
hooks:
15+
- id: check-added-large-files
16+
- id: check-ast
17+
- id: check-builtin-literals
18+
- id: check-case-conflict
19+
- id: check-docstring-first
20+
- id: check-json
21+
- id: check-merge-conflict
22+
- id: check-shebang-scripts-are-executable
23+
- id: check-symlinks
24+
- id: check-toml
25+
- id: check-vcs-permalinks
26+
- id: check-xml
27+
- id: check-yaml
28+
exclude: (.gitlab-ci.yml|mkdocs.yml)
29+
- id: debug-statements
30+
- id: destroyed-symlinks
31+
- id: detect-private-key
32+
- id: end-of-file-fixer
33+
types: [python]
34+
- id: fix-byte-order-marker
35+
- id: mixed-line-ending
36+
- id: name-tests-test
37+
args: [--pytest-test-first]
38+
stages: ["pre-commit"]
39+
- id: trailing-whitespace
40+
types: [python]
41+
- repo: https://github.com/python-poetry/poetry
42+
rev: 2.1.3 # add version here
43+
hooks:
44+
- id: poetry-check
45+
- id: poetry-lock
46+
- id: poetry-install
47+
- repo: https://github.com/pre-commit/mirrors-mypy
48+
rev: v1.16.1 # Use the sha / tag you want to point at
49+
hooks:
50+
- id: mypy
51+
types: [python]
52+
additional_dependencies: [types-requests]
53+
stages: ["pre-commit"]
54+
- repo: https://github.com/astral-sh/ruff-pre-commit
55+
# Ruff version.
56+
rev: v0.12.0
57+
hooks:
58+
# Run the linter.
59+
- id: ruff-check
60+
stages: ["pre-commit"]
61+
args:
62+
- --diff
63+
# Run the formatter.
64+
- id: ruff-format
65+
stages: ["pre-commit"]
66+
args:
67+
- --diff --check
68+
- repo: local
69+
hooks:
70+
- id: pytest
71+
name: pytest
72+
entry: bash -c 'cd src && poetry run pytest'
73+
language: system
74+
types: [python]
75+
pass_filenames: false
76+
always_run: true
77+
stages: ["pre-commit"]
78+

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

0 commit comments

Comments
 (0)