Skip to content

Commit ef30bd6

Browse files
committed
nox & gh action
1 parent 949209b commit ef30bd6

3 files changed

Lines changed: 57 additions & 22 deletions

File tree

.copier-answers-py.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# https://github.com/level12/coppy/wiki#creating-a-project
55
#
66
# Otherwise, NEVER EDIT MANUALLY
7-
_commit: v1.20250622.1-48-g59caa6d
7+
_commit: v1.20250622.1-48-g491417c
88
_src_path: /home/rsyring/projects/coppy-pkg
99
author_email: jpicard@starfleet.space
1010
author_name: Picard

.github/workflows/nox.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ jobs:
3434
runs-on: ubuntu-latest
3535

3636
permissions:
37-
contents: read # For actions/checkout
3837
id-token: write # For codecov OIDC
3938

4039
steps:

noxfile.py

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
from os import environ
12
from pathlib import Path
23

34
import nox
45

56

67
package_path = Path(__file__).parent
8+
is_circleci = 'CIRCLECI' in environ
9+
710
nox.options.default_venv_backend = 'uv'
811

912

1013
@nox.session
1114
def pytest(session: nox.Session):
12-
uv_sync(session, 'pytest')
15+
uv_sync(session)
1316
pytest_run(session)
1417

1518

@@ -26,45 +29,78 @@ def precommit(session: nox.Session):
2629
@nox.session
2730
def audit(session: nox.Session):
2831
# Much faster to install the deps first and have pip-audit run against the venv
29-
uv_sync(session, 'audit')
32+
uv_sync(session)
3033
session.run(
3134
'pip-audit',
3235
'--desc',
3336
'--skip-editable',
3437
)
3538

3639

40+
def pytest_run(session: nox.Session, *args, **env):
41+
"""
42+
Using functions for pytest and uv enables more advanced uses cases. Examples:
43+
44+
py_all = ['3.10', '3.11', '3.12', '3.13']
45+
46+
@session(py=py_all)
47+
@parametrize('db', ['pg', 'sqlite'])
48+
def pytest(session: Session, db: str):
49+
uv_sync(session)
50+
pytest_run(session, WEBTEST_DB=db)
51+
52+
53+
@session(py=py_single)
54+
def pytest_mssql(session: Session):
55+
uv_sync(session, 'pytest', 'mssql')
56+
pytest_run(session, WEBTEST_DB='mssql')
57+
58+
59+
@session(py=py_single)
60+
def pytest_i18n(session: Session):
61+
uv_sync(session, extra='i18n')
62+
pytest_run(session, WEBTEST_DB='sqlite')
63+
64+
"""
65+
junit_opt = f'--junit-xml={package_path}/ci/test-reports/{session.name}.pytests.xml'
66+
junit_args = (junit_opt,) if is_circleci else ()
67+
68+
session.run(
69+
'pytest',
70+
'-ra',
71+
'--tb=native',
72+
'--strict-markers',
73+
'--cov',
74+
'--cov-report=xml',
75+
'--no-cov-on-fail',
76+
*junit_args,
77+
package_path / 'tests',
78+
*args,
79+
*session.posargs,
80+
env=env,
81+
)
82+
83+
3784
def uv_sync(session: nox.Session, *groups, project=False, extra=None):
3885
if not groups:
3986
groups = (session.name,)
87+
88+
# At least pytest needs the project installed.
4089
project_args = () if project or session.name.startswith('pytest') else ('--no-install-project',)
90+
4191
group_args = [arg for group in groups for arg in ('--group', group)]
4292
extra_args = ('--extra', extra) if extra else ()
93+
4394
run_args = (
4495
'uv',
4596
'sync',
4697
'--active',
98+
'--exact',
99+
# Use --no-default-groups instead of --only-group as the latter implies
100+
# --no-install-project.
47101
'--no-default-groups',
48102
*project_args,
49103
*group_args,
50104
*extra_args,
51105
)
52106
session.run(*run_args)
53-
54-
55-
def pytest_run(session: nox.Session, *args, **env):
56-
session.run(
57-
'pytest',
58-
'-ra',
59-
'--tb=native',
60-
'--strict-markers',
61-
'--cov',
62-
'--cov-config=.coveragerc',
63-
f'--junit-xml={package_path}/ci/test-reports/{session.name}.pytests.xml',
64-
f'--cov-report=xml:{package_path}/ci/coverage/{session.name}.xml',
65-
'--no-cov-on-fail',
66-
package_path / 'tests',
67-
*args,
68-
*session.posargs,
69-
env=env,
70-
)

0 commit comments

Comments
 (0)