-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnoxfile.py
104 lines (77 loc) · 2.98 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
import sys
import nox
nox.options.sessions = ['test', 'lint', 'type_check', 'rust_lint']
nox.options.python = False
def build(session, use_pip: bool = False):
if _is_ci():
# Install form wheels
install(session, '--no-index', '--no-deps', '--find-links', 'wheels/', 'serpyco-rs', use_pip=use_pip)
install(session, '--find-links', 'wheels/', 'serpyco-rs', use_pip=use_pip)
return
session.run_always('maturin', 'develop', '-r')
@nox.session(python=False)
def test(session):
build(session)
install(session, '-r', 'requirements/dev.txt')
session.run('pytest', '-vvs', 'tests/', *session.posargs)
@nox.session(python=False)
def lint(session):
build(session)
install(session, '-r', 'requirements/lint.txt')
session.cd('python/serpyco_rs')
paths = ['.', '../../tests', '../../bench']
session.run('ruff', 'format', *(['--check', '--diff', *paths] if _is_ci() else paths))
session.run('ruff', 'check', '.', *([] if _is_ci() else ['--fix']))
@nox.session(python=False)
def rust_lint(session):
session.run('cargo', 'fmt', '--all', *(['--', '--check'] if _is_ci() else []))
session.run('cargo', 'clippy', '--all-targets', '--all-features', '--', '-D', 'warnings')
@nox.session(python=False)
def type_check(session):
build(session)
install(session, '-r', 'requirements/type_check.txt')
session.cd('python/serpyco_rs')
session.run('pyright', '.', success_codes=[0, 1] if _is_ci() else [0])
session.run('pyright', '.', '--verifytypes', 'serpyco_rs')
session.run('mypy', '.', '--strict', '--implicit-reexport', '--pretty')
@nox.session(python=False)
def bench(session):
build(session)
install(session, '-r', 'requirements/bench.txt')
session.run(
'pytest',
*(session.posargs if session.posargs else ['bench']),
'--verbose',
'--benchmark-min-time=0.5',
'--benchmark-max-time=1',
'--benchmark-disable-gc',
'--benchmark-autosave',
'--benchmark-save-data',
'--benchmark-compare',
)
@nox.session(python=False)
def test_rc_leaks(session):
# uv don't resolve wheels when used python debug build
build(session, use_pip=True)
install(session, '-r', 'requirements/bench.txt', use_pip=True)
session.run(
'pytest',
*(session.posargs if session.posargs else ['bench']),
'--verbose',
'--debug-refs',
'--debug-refs-gc',
)
@nox.session
def bench_codespeed(session):
build(session)
install(session, '-r', 'requirements/bench.txt')
install(session, 'pytest-codspeed')
session.run('pytest', 'bench', '--ignore=bench/compare/test_benchmarks.py', '--codspeed')
def install(session, *args, use_pip: bool = False):
if session._runner.global_config.no_install:
return
cmd = ['pip', 'install'] if use_pip else ['uv', 'pip', 'install', '--python', sys.executable]
session.run_always(*cmd, *args)
def _is_ci() -> bool:
return bool(os.environ.get('CI', None))