-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnoxfile.py
More file actions
107 lines (83 loc) · 3.14 KB
/
Copy pathnoxfile.py
File metadata and controls
107 lines (83 loc) · 3.14 KB
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
105
106
107
"""Notes:
* 'test' command: nox will use poetry.lock to determine dependency versions
* 'lint' command: tools and environments are managed by prek/pre-commit
* All other commands: the current environment will be used instead of creating new ones
"""
from os.path import join
from pathlib import Path
from shutil import rmtree
from tempfile import gettempdir
import nox
nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = ['lint', 'cov']
CLEAN_DIRS = ['dist', 'build', join('docs', '_build')]
LIVE_DOCS_PORT = 8181
LIVE_DOCS_IGNORE = ['*.csv', '*.ipynb', '*.pyc', '*.tmp', '**/modules/*']
DEFAULT_COVERAGE_FORMATS = ['html', 'term']
DOC_BUILD_DIR = join('docs', '_build', 'html')
TEMP_DB = Path(gettempdir()) / 'pyinat.db'
def install_deps(session):
"""Install project and test dependencies into a nox session using uv"""
session.env['UV_PROJECT_ENVIRONMENT'] = session.virtualenv.location
session.run_install(
'uv',
'sync',
'--frozen',
'--all-extras',
)
@nox.session(python=['3.10', '3.11', '3.12', '3.13', '3.14', '3.15'], venv_backend='uv')
def test(session):
"""Run tests for a specific python version"""
test_paths = session.posargs or ['test']
install_deps(session)
session.run('pytest', '-n', 'auto', *test_paths)
@nox.session(python=False)
def clean(session):
"""Clean up temporary build + documentation files"""
for dir in CLEAN_DIRS:
print(f'Removing {dir}')
rmtree(dir, ignore_errors=True)
@nox.session(python=False, name='cov')
def coverage(session):
"""Run tests and generate coverage report"""
cmd = ['pytest', '-n', 'auto', '--cov']
# Add coverage formats
cov_formats = session.posargs or DEFAULT_COVERAGE_FORMATS
cmd += [f'--cov-report={f}' for f in cov_formats]
session.run(*cmd)
@nox.session(python=False)
def docs(session):
"""Build Sphinx documentation"""
cmd = 'sphinx-build docs docs/_build/html -j auto'
session.run(*cmd.split(' '))
@nox.session(python=False)
def livedocs(session):
"""Auto-build docs with live reload in browser.
Add `-- open` to also open the browser after starting.
"""
cmd = ['sphinx-autobuild', 'docs', DOC_BUILD_DIR]
cmd += ['-a']
cmd += ['--host', '0.0.0.0']
cmd += ['--port', str(LIVE_DOCS_PORT), '-j', 'auto']
cmd += ['--watch', 'pyinaturalist_convert']
for pattern in LIVE_DOCS_IGNORE:
cmd += ['--ignore', pattern]
if session.posargs == ['open']:
cmd.append('--open-browser')
clean(session)
session.run(*cmd)
@nox.session(python=False)
def lint(session):
"""Run linters and code formatters via prek/pre-commit"""
cmd = 'prek run --all-files'
session.run(*cmd.split(' '))
@nox.session(python=False, name='db-generate')
def db_generate(session):
"""Generate an alembic revision using autogenerate.
Usage: nox -e db-generate -- "revision message"
"""
message = session.posargs[0] if session.posargs else 'schema update'
session.env['INAT_DB_PATH'] = TEMP_DB
TEMP_DB.unlink(missing_ok=True)
session.run('alembic', 'upgrade', 'head')
session.run('alembic', 'revision', '--autogenerate', '-m', message)