Skip to content

Commit 945523d

Browse files
committed
test: use hatch test
1 parent 31bad00 commit 945523d

File tree

6 files changed

+233
-141
lines changed

6 files changed

+233
-141
lines changed

.github/actions/setup/action.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: General Setup
2+
description: checkout & setup python
3+
inputs:
4+
python-version: # id of input
5+
description: the python version to use
6+
required: false
7+
default: '3.12'
8+
runs:
9+
using: composite
10+
steps:
11+
- name: Install uv
12+
uses: astral-sh/setup-uv@v5
13+
with:
14+
python-version: ${{inputs.python-version}}
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
18+
with:
19+
python-version: ${{inputs.python-version}}
20+
architecture: x64
21+
allow-prereleases: true

.github/workflows/ci.yml

Lines changed: 95 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,82 +6,128 @@ on:
66
branches: [main]
77

88
jobs:
9+
910
mypy:
1011
runs-on: ubuntu-latest
1112
strategy:
1213
matrix:
13-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
14+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
1415
steps:
15-
- uses: actions/checkout@v3
16-
- uses: actions/setup-python@v4
16+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
- uses: ./.github/actions/setup
1718
with:
1819
python-version: ${{matrix.python-version}}
19-
architecture: x64
20-
- run: |
21-
pip install hatch
22-
hatch run +python=${{matrix.python-version}} all:test-mypy
20+
- run: uvx hatch run +py=${{matrix.python-version}} types:check
2321

2422
test:
2523
runs-on: ${{matrix.os}}
2624
strategy:
2725
matrix:
28-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
29-
os: [ubuntu-latest, windows-latest]
26+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', pypy3.9, pypy3.10]
27+
os: [ubuntu-latest, windows-latest, macos-13]
28+
env:
29+
TOP: ${{github.workspace}}
30+
COVERAGE_PROCESS_START: ${{github.workspace}}/pyproject.toml
3031
steps:
31-
- uses: actions/checkout@v3
32-
- uses: actions/setup-python@v4
32+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
33+
- uses: ./.github/actions/setup
3334
with:
3435
python-version: ${{matrix.python-version}}
35-
architecture: x64
36-
37-
- name: run tests for ${{matrix.python-version}}
38-
env:
39-
TOP: ${{github.workspace}}
40-
COVERAGE_PROCESS_START: ${{github.workspace}}/pyproject.toml
41-
run: |
42-
pip install hatch
43-
hatch run +python=${{matrix.python-version}} all:test-cov
4436

45-
- name: Combine data
46-
env:
47-
TOP: ${{github.workspace}}
48-
COVERAGE_PROCESS_START: ${{github.workspace}}/pyproject.toml
49-
run: |
50-
pip install coverage
51-
coverage combine
52-
mv .coverage .coverage.${{ matrix.python-version }}.${{matrix.os}}
37+
- run: |
38+
uv run -m ${{ matrix.os == 'ubuntu-latest' && 'coverage run -m' || '' }} pytest ${{ matrix.os != 'windows-latest' && '-n=auto' || '' }} -vv
39+
- run: |
40+
uv run -m coverage combine
41+
mv .coverage .coverage.${{ matrix.python-version }}-${{matrix.os}}-${{strategy.job-index}}
42+
if: matrix.os == 'ubuntu-latest'
5343
5444
- name: Upload coverage data
55-
uses: actions/upload-artifact@v3
45+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
46+
if: matrix.os == 'ubuntu-latest'
5647
with:
57-
name: coverage
48+
name: coverage-data-${{github.run_id}}-${{ matrix.python-version }}-${{matrix.os}}-${{strategy.job-index}}
5849
path: .coverage.*
50+
include-hidden-files: true
51+
if-no-files-found: ignore
5952

60-
combine_coverage:
61-
name: combine coverage and check for 100%
53+
coverage:
54+
name: Combine & check coverage
55+
env:
56+
TOP: ${{github.workspace}}
57+
if: always()
6258
needs: test
6359
runs-on: ubuntu-latest
6460

6561
steps:
66-
- uses: actions/checkout@v3
67-
- uses: actions/setup-python@v4
68-
with:
69-
python-version: '3.11'
70-
architecture: x64
62+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
63+
- uses: ./.github/actions/setup
7164

72-
- name: Download coverage data
73-
uses: actions/download-artifact@v3
65+
- uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
7466
with:
75-
name: coverage
67+
pattern: coverage-data-${{github.run_id}}-*
68+
merge-multiple: true
7669

77-
- name: Combine data
78-
env:
79-
TOP: ${{github.workspace}}
80-
COVERAGE_PROCESS_START: ${{github.workspace}}/pyproject.toml
70+
- name: Combine coverage & fail if it's <100%
8171
run: |
82-
# i have problems to combine windows coverage files with linux coverage files
83-
rm .coverage.*.windows-latest
84-
pip install coverage
72+
uv pip install --upgrade coverage[toml]
73+
8574
coverage combine
86-
coverage
87-
coverage report --fail-under 100
75+
coverage html --skip-covered --skip-empty
76+
77+
# Report and write to summary.
78+
coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
79+
80+
# Report again and fail if under 100%.
81+
coverage report --fail-under=100
82+
83+
- name: Upload HTML report if check failed
84+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
85+
with:
86+
name: html-report
87+
path: htmlcov
88+
if: ${{ failure() }}
89+
90+
91+
publish:
92+
name: Publish new release
93+
runs-on: ubuntu-latest
94+
needs: [test, coverage]
95+
environment: pypi
96+
permissions:
97+
# IMPORTANT: this permission is mandatory for Trusted Publishing
98+
id-token: write
99+
# this permission is mandatory to create github releases
100+
contents: write
101+
102+
steps:
103+
- name: Checkout main
104+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
105+
with:
106+
fetch-depth: 0
107+
- uses: ./.github/actions/setup
108+
109+
- name: Check if the commit has a vx.y.z tag
110+
id: check-version
111+
run: |
112+
if git tag --list --points-at ${{ github.sha }} | grep -q -E '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
113+
echo "is new version"
114+
echo "should_continue=true" >> "$GITHUB_OUTPUT"
115+
else
116+
echo "is not a new version"
117+
echo "should_continue=false" >> "$GITHUB_OUTPUT"
118+
fi
119+
120+
- run: uv pip install hatch scriv
121+
122+
- name: build package
123+
run: hatch build
124+
125+
- name: Publish package distributions to PyPI
126+
if: ${{ steps.check-version.outputs.should_continue == 'true' }}
127+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
128+
129+
- name: create github release
130+
if: ${{ steps.check-version.outputs.should_continue == 'true' }}
131+
env:
132+
GITHUB_TOKEN: ${{ github.token }}
133+
run: scriv github-release

.pre-commit-config.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
- id: check-json
1818
- id: end-of-file-fixer
1919
repo: https://github.com/pre-commit/pre-commit-hooks
20-
rev: v4.6.0
20+
rev: v5.0.0
2121
- hooks:
2222
- args:
2323
- --in-place
@@ -29,12 +29,12 @@ repos:
2929
rev: v2.3.1
3030

3131
- repo: https://github.com/asottile/setup-cfg-fmt
32-
rev: v2.5.0
32+
rev: v2.8.0
3333
hooks:
3434
- id: setup-cfg-fmt
3535

3636
- repo: https://github.com/asottile/reorder-python-imports
37-
rev: v3.13.0
37+
rev: v3.15.0
3838
hooks:
3939
- args:
4040
- --py38-plus
@@ -44,15 +44,15 @@ repos:
4444
- --py38-plus
4545
id: pyupgrade
4646
repo: https://github.com/asottile/pyupgrade
47-
rev: v3.17.0
47+
rev: v3.20.0
4848
- hooks:
4949
- id: black
5050
repo: https://github.com/psf/black
51-
rev: 24.8.0
51+
rev: 25.1.0
5252
- hooks:
5353
- id: blacken-docs
5454
repo: https://github.com/asottile/blacken-docs
55-
rev: 1.18.0
55+
rev: 1.19.1
5656

5757
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
5858
rev: v2.14.0
@@ -71,11 +71,11 @@ repos:
7171
stages:
7272
- commit-msg
7373
repo: https://github.com/commitizen-tools/commitizen
74-
rev: v3.28.0
74+
rev: v4.8.2
7575

7676

7777
- repo: https://github.com/PyCQA/docformatter
78-
rev: v1.7.5
78+
rev: v1.7.7
7979
hooks:
8080
- id: docformatter
8181

pyproject.toml

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ Documentation = "https://github.com/15r10nk/lazy-imports-lite#readme"
3838
Issues = "https://github.com/15r10nk/lazy-imports-lite/issues"
3939
Source = "https://github.com/15r10nk/lazy-imports-lite"
4040

41+
42+
[dependency-groups]
43+
dev = [
44+
"pytest-freezer>=0.4.8",
45+
"pytest-mock>=3.14.0",
46+
"pytest-xdist>=3.6.1",
47+
"coverage[toml]>=7.6.1",
48+
"coverage-enable-subprocess>=1.0",
49+
"inline-snapshot[black]",
50+
"astunparse",
51+
"pip>=25.0.1"
52+
]
53+
54+
4155
[tool.black]
4256
target-version = ["py38"]
4357

@@ -74,65 +88,29 @@ from lazy_imports_lite._loader import setup
7488
setup()
7589
"""
7690

77-
[tool.hatch.envs.default]
78-
scripts.test = "pytest {args:tests}"
79-
dependencies = [
80-
"pytest",
81-
"inline-snapshot",
82-
"astunparse"
91+
[tool.hatch.envs.cov.scripts]
92+
github=[
93+
"- rm htmlcov/*",
94+
"gh run download -n html-report -D htmlcov",
95+
"xdg-open htmlcov/index.html",
8396
]
8497

85-
# all
86-
[tool.hatch.envs.all]
87-
dependencies = [
88-
"coverage[toml]>=6.5",
89-
"coverage-enable-subprocess",
90-
"pytest",
91-
"inline-snapshot",
92-
"astunparse",
93-
"mypy",
94-
]
95-
env-vars.TOP = "{root}"
96-
scripts.test-cov = "coverage run -m pytest {args:tests}"
97-
scripts.test = "pytest {args:tests}"
98-
scripts.test-mypy = "mypy src tests"
99-
100-
[[tool.hatch.envs.all.matrix]]
101-
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
98+
[[tool.hatch.envs.hatch-test.matrix]]
99+
python = ["3.8", "3.9", "3.10", "3.11", "3.12","3.13","pypy3.9","pypy3.10"]
102100

103-
# coverage
104-
[tool.hatch.envs.all-cov]
105-
template="all"
101+
[tool.hatch.envs.hatch-test]
106102
extra-dependencies = [
107-
"coverage[toml]>=6.5",
108-
"coverage-enable-subprocess",
103+
"inline-snapshot[black]",
104+
"astunparse",
105+
"pip>=25.0.1"
109106
]
110107
env-vars.TOP = "{root}"
111-
scripts.test = "coverage run -m pytest {args:tests}"
112108

113-
[[tool.hatch.envs.all-cov.matrix]]
114-
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
115-
116-
[tool.hatch.envs.cov]
117-
dependencies = ["coverage[toml]>=6.5"]
118-
detached = true
119-
env-vars.TOP = "{root}"
120-
env-vars.COVERAGE_PROCESS_START = "{root}/pyproject.toml"
121-
scripts.all = [
122-
"- coverage erase",
123-
"hatch run all-cov:test -- {args}",
124-
"coverage combine",
125-
"coverage html",
126-
"coverage report --fail-under 100 "
127-
]
128-
129-
scripts.one = [
130-
"- coverage erase",
131-
"hatch run +py=3.12 all-cov:test -- {args}",
132-
"coverage combine",
133-
"coverage html",
134-
"coverage report --fail-under 100 "
135-
]
109+
[tool.hatch.envs.hatch-test.scripts]
110+
run = "pytest{env:HATCH_TEST_ARGS:} {args}"
111+
run-cov = "coverage run -m pytest{env:HATCH_TEST_ARGS:} {args}"
112+
cov-combine = "coverage combine"
113+
cov-report=["coverage report","coverage html"]
136114

137115

138116

@@ -146,3 +124,21 @@ scripts.serve = ["mkdocs serve {args}"]
146124

147125
[tool.hatch.version]
148126
path = "src/lazy_imports_lite/__init__.py"
127+
128+
129+
130+
[tool.hatch.envs.types]
131+
extra-dependencies = [
132+
"inline-snapshot[black,dirty-equals]",
133+
"mypy>=1.0.0",
134+
"hypothesis>=6.75.5",
135+
"pydantic",
136+
"attrs",
137+
"typing-extensions"
138+
]
139+
140+
[[tool.hatch.envs.types.matrix]]
141+
python = ["3.8", "3.9", "3.10", "3.11", "3.12","3.13"]
142+
143+
[tool.hatch.envs.types.scripts]
144+
check = "mypy --install-types --non-interactive {args:src/lazy_imports_lite tests}"

0 commit comments

Comments
 (0)