forked from scrapd/scrapd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
177 lines (127 loc) · 4.52 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from pathlib import Path
import nox
# Behavior's options.
nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = ["venv"]
# Configuration values.
nox_file = Path()
project_name = 'scrapd'
dockerfile = 'Dockerfile'
docker_org = 'scrapd'
docker_repo = f'{docker_org}/{project_name}'
docker_img = f'{docker_repo}'
@nox.session()
def ci(session):
"""Run all the CI tasks."""
session.install('-rrequirements-dev.txt')
session.install('-e', '.')
run_sphinx(session)
run_yapf(session, True)
run_all_linters(session)
run_pytest_units(session)
run_pytest_integrations(session)
@nox.session()
def dist(session):
"""Package the application."""
session.install('-rrequirements-dev.txt')
session.install('-e', '.')
session.run('python', 'setup.py', 'bdist_wheel')
@nox.session()
def dist_upload(session):
"""Package the application."""
session.install('-rrequirements-dev.txt')
session.run('twine', 'upload', 'dist/*')
@nox.session()
def docs(session):
"""Ensure the documentation builds."""
session.install('-rrequirements-dev.txt')
session.install('-e', '.')
run_sphinx(session)
@nox.session()
def format(session):
"""Format the codebase using YAPF."""
session.install('-rrequirements-dev.txt')
run_yapf(session, diff=False)
@nox.session()
def lint(session):
"""Run all the linters."""
session.install('-rrequirements-dev.txt')
session.install('-e', '.')
run_all_linters(session)
@nox.session(name='lint-format')
def lint_format(session):
"""Check the formatting of the codebase using YAPF."""
session.install('-rrequirements-dev.txt')
run_yapf(session, diff=True)
@nox.session()
def pydocstyle(session):
"""Check the docstrings."""
session.install('-rrequirements-dev.txt')
session.install('-e', '.')
run_pydocstyle(session)
@nox.session()
def pylint(session):
"""Run the pylint linter."""
session.install('-rrequirements-dev.txt')
session.install('-e', '.')
run_pylint(session)
@nox.session(python='python3.7')
def test(session):
"""Run all the tests."""
session.install('-rrequirements-dev.txt')
session.install('-e', '.')
run_pytest(session)
@nox.session(python='python3.7', name='test-units')
def test_units(session):
"""Run the unit tests."""
session.install('-rrequirements-dev.txt')
session.install('-e', '.')
run_pytest_units(session)
@nox.session(python='python3.7', name='test-integrations')
def test_integrations(session):
"""Run the integration tests."""
session.install('-rrequirements-dev.txt')
session.install('-e', '.')
run_pytest_integrations(session)
@nox.session()
def venv(session):
"""Setup the developper environment."""
# Install dependencies.
session.install("--upgrade", "pip", "setuptools")
session.install("-r", "requirements-dev.txt")
session.install("-e", ".")
# Customize the venv.
env_dir = Path(session.bin)
activate = env_dir / 'activate'
with activate.open('a') as f:
f.write(f'\n[ -f {activate.resolve()}/postactivate ] && . {activate.resolve()}/postactivate\n')
scrapd_complete = nox_file / 'contrib/scrapd-complete.sh'
postactivate = env_dir / 'postactivate'
with postactivate.open('a') as f:
f.write('export PYTHONBREAKPOINT=bpdb.set_trace\n')
f.write(f'source {scrapd_complete.resolve()}\n')
predeactivate = env_dir / 'predeactivate'
with predeactivate.open('a') as f:
f.write('unset PYTHONBREAKPOINT\n')
def run_all_linters(session):
run_flake8(session)
run_pydocstyle(session)
run_pylint(session)
def run_flake8(session):
session.run('flake8', 'scrapd')
def run_pydocstyle(session):
session.run('pydocstyle', 'scrapd')
def run_pylint(session):
session.run('pylint', '--ignore=tests', 'scrapd')
def run_pytest(session, *posargs):
session.run('pytest', '-x', '--junitxml=/tmp/pytest/junit-py37.xml', '--cov-report', 'term-missing', '--cov-report',
'html', '--cov=scrapd', *posargs, f'{(nox_file / "tests").resolve()}')
def run_pytest_units(session):
run_pytest(session, '-m', 'not integrations and not dump')
def run_pytest_integrations(session):
run_pytest(session, '-m', 'integrations', '--reruns', '3', '--reruns-delay', '5', '-r', 'R')
def run_sphinx(session):
session.run('python', 'setup.py', 'build_sphinx')
def run_yapf(session, diff=True):
mode = '-d' if diff else '-i'
session.run('yapf', '-r', mode, '-e', '*.nox/*', '-e', '*.tox/*', '-e', '*venv/*', '-e', '*.eggs/*', '.')