-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnoxfile.py
134 lines (113 loc) · 3.48 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# SPDX-License-Identifier: BSD-3-Clause
import shutil
from pathlib import Path
from os import getenv
from setuptools_scm import get_version, ScmVersion
import nox
from nox.sessions import Session
ROOT_DIR = Path(__file__).parent
BUILD_DIR = (ROOT_DIR / 'build')
CNTRB_DIR = (ROOT_DIR / 'contrib')
DOCS_DIR = (ROOT_DIR / 'docs')
DIST_DIR = (BUILD_DIR / 'dist')
IN_CI = getenv('GITHUB_WORKSPACE') is not None
ENABLE_COVERAGE = IN_CI or (getenv('SQUISHY_TEST_COVERAGE') is not None)
# Default sessions to run
nox.options.sessions = (
'test',
'lint',
'typecheck'
)
def squishy_version() -> str:
def scheme(version: ScmVersion) -> str:
if version.tag and not version.distance:
return version.format_with('')
else:
return version.format_choice('+{node}', '+{node}.dirty')
return get_version(
root = str(ROOT_DIR),
version_scheme = 'guess-next-dev',
local_scheme = scheme,
relative_to = __file__
)
@nox.session(reuse_venv = True, venv_params = ['--system-site-packages'])
def test(session: Session) -> None:
out_dir = (BUILD_DIR / 'tests')
out_dir.mkdir(parents = True, exist_ok = True)
unitest_args = ('-m', 'unittest', 'discover', '-v', '-s', str(ROOT_DIR))
session.install('.')
if ENABLE_COVERAGE:
session.log('Coverage support enabled')
session.install('coverage')
coverage_args = (
'-m', 'coverage', 'run',
f'--rcfile={CNTRB_DIR / "coveragerc"}'
)
else:
coverage_args = ()
session.chdir(str(out_dir))
session.run(
'python', *coverage_args, *unitest_args, *session.posargs
)
if ENABLE_COVERAGE:
session.run(
'python', '-m', 'coverage', 'xml',
f'--rcfile={CNTRB_DIR / "coveragerc"}'
)
@nox.session
def docs(session: Session) -> None:
out_dir = (BUILD_DIR / 'docs')
shutil.rmtree(out_dir, ignore_errors = True)
session.install('-r', str(DOCS_DIR / 'requirements.txt'))
session.install('.')
session.run('sphinx-build', '-b', 'html', str(DOCS_DIR), str(out_dir))
shutil.copy(ROOT_DIR / 'LICENSE.docs', out_dir / 'LICENSE')
@nox.session
def docs_linkcheck(session: Session) -> None:
out_dir = (BUILD_DIR / 'docs-linkcheck')
shutil.rmtree(out_dir, ignore_errors = True)
session.install('-r', str(DOCS_DIR / 'requirements.txt'))
session.install('.')
session.run('sphinx-build', '-b', 'linkcheck', str(DOCS_DIR), str(out_dir))
@nox.session
def typecheck(session: Session) -> None:
out_dir = (BUILD_DIR / 'mypy')
out_dir.mkdir(parents = True, exist_ok = True)
session.install('mypy')
session.install('lxml')
session.install('construct-typing')
session.install('.')
session.run(
'mypy', '--non-interactive', '--install-types', '--pretty',
'--cache-dir', str((out_dir / '.mypy-cache').resolve()),
'--config-file', str((CNTRB_DIR / '.mypy.ini').resolve()),
'-p', 'squishy', '--html-report', str(out_dir.resolve())
)
@nox.session
def lint(session: Session) -> None:
session.install('flake8')
session.run(
'flake8', '--config', str((CNTRB_DIR / '.flake8').resolve()),
'./squishy'
)
session.run(
'flake8', '--config', str((CNTRB_DIR / '.flake8').resolve()),
'./tests'
)
@nox.session
def dist(session: Session) -> None:
session.install('build')
session.run(
'python', '-m', 'build',
'-o', str(DIST_DIR)
)
@nox.session
def upload(session: Session) -> None:
session.install('twine')
dist(session)
session.log(f'Uploading squishy-{squishy_version()} to PyPi')
session.run(
'python', '-m', 'twine', 'upload',
f'{DIST_DIR}/squishy-{squishy_version()}.tar.gz',
f'{DIST_DIR}/squishy-{squishy_version()}-py3-*.whl'
)