-
Notifications
You must be signed in to change notification settings - Fork 22
/
noxfile.py
87 lines (68 loc) · 2.76 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
"""Notes:
* 'test' command: nox will use poetry.lock to determine dependency versions
* 'lint' command: tools and environments are managed by 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
import nox
from nox_poetry import session
nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = ['lint', 'cov']
DOCS_DIR = Path('docs')
LIVE_DOCS_PORT = 8181
LIVE_DOCS_IGNORE = ['*.pyc', '*.tmp', join('**', 'modules', '*')]
LIVE_DOCS_WATCH = ['aiohttp_client_cache', 'examples']
CLEAN_DIRS = ['dist', 'build', DOCS_DIR / '_build', DOCS_DIR / 'modules']
TEST_DIR = Path('test')
UNIT_TESTS = TEST_DIR / 'unit'
INTEGRATION_TESTS = TEST_DIR / 'integration'
COVERAGE_ARGS = (
'--cov --cov-report=term --cov-report=html' # Generate HTML + stdout coverage report
)
XDIST_ARGS = '--numprocesses=auto --dist=loadfile' # Run tests in parallel, grouped by test module
@session(python=['3.8', '3.9', '3.10', '3.11', '3.12'])
def test(session):
"""Run tests for a specific python version"""
test_paths = session.posargs or [UNIT_TESTS]
session.install('.', 'pytest', 'pytest-aiohttp', 'pytest-asyncio', 'pytest-xdist')
cmd = f'pytest -rs {XDIST_ARGS}'
session.run(*cmd.split(' '), *test_paths)
@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) # type: ignore[arg-type]
@session(python=False, name='cov')
def coverage(session):
"""Run tests and generate coverage report"""
cmd_1 = f'pytest {UNIT_TESTS} -rs {XDIST_ARGS} {COVERAGE_ARGS}'
cmd_2 = f'pytest {INTEGRATION_TESTS} -rs {XDIST_ARGS} {COVERAGE_ARGS} --cov-append'
session.run(*cmd_1.split(' '))
session.run(*cmd_2.split(' '))
@session(python=False)
def docs(session):
"""Build Sphinx documentation"""
cmd = 'sphinx-build docs docs/_build/html -j auto'
session.run(*cmd.split(' '))
@session(python=False)
def livedocs(session):
"""Auto-build docs with live reload in browser.
Add `--open` to also open the browser after starting.
"""
args = ['-a']
args += [f'--watch {pattern}' for pattern in LIVE_DOCS_WATCH]
args += [f'--ignore {pattern}' for pattern in LIVE_DOCS_IGNORE]
args += [f'--port {LIVE_DOCS_PORT}', '-j auto']
if session.posargs == ['open']:
args.append('--open-browser')
clean(session)
cmd = 'sphinx-autobuild docs docs/_build/html ' + ' '.join(args)
session.run(*cmd.split(' '))
@session(python=False)
def lint(session):
"""Run linters and code formatters via pre-commit"""
cmd = 'pre-commit run --all-files'
session.run(*cmd.split(' '))