-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnoxfile.py
93 lines (73 loc) · 2.94 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
import os
import shutil
import tempfile
from pathlib import Path
import nox
nox.options.reuse_existing_virtualenvs = True
PYTHON_VERSIONS = ['pypy3', '3.7', '3.8', '3.9']
CI_ENVIRONMENT = 'GITHUB_ACTIONS' in os.environ
@nox.session(python=PYTHON_VERSIONS[-1])
def lint(session):
"""Performs pep8 and security checks."""
source_code = 'scalpel'
session.install('flake8==3.9.2', 'bandit==1.7.4', 'black==22.3.0')
session.run('flake8', source_code)
session.run('bandit', '-r', source_code)
session.run('black', source_code, 'tests', '--check')
@nox.session(python=PYTHON_VERSIONS[-1])
def safety(session):
"""Checks vulnerabilities of the installed packages."""
session.install('poetry>=1.0.0,<2.0.0')
session.run('poetry', 'install')
session.run('safety', 'check')
@nox.session(python=PYTHON_VERSIONS)
def tests(session):
"""
Runs the test suite.
You can also run a part of the test suite by specifying the parts you want to test. The values "core", "green"
and "any_io" are accepted as extra arguments. They can be cumulated.
"""
to_test = ['core', 'any_io', 'green']
for item in session.posargs:
if item not in to_test:
session.error(f'{item} is not part of {to_test}')
to_test = session.posargs if session.posargs else to_test
session.install('poetry>=1.0.0,<2.0.0')
session.run('poetry', 'install', '-E', 'full')
for part in to_test:
arguments = ['coverage', 'run', f'--source=scalpel/{part}', '-m', 'pytest', f'tests/{part}']
if part == 'green':
arguments.insert(3, '--concurrency=gevent')
session.run(*arguments)
session.run('coverage', 'xml', '-o', f'coverage-{part}.xml')
if not CI_ENVIRONMENT:
session.notify('clean-robots-cache')
@nox.session(python=PYTHON_VERSIONS[-1])
def docs(session):
"""Builds the documentation."""
session.install('poetry>=1.0.0,<2.0.0')
session.run('poetry', 'install')
session.run('mkdocs', 'build', '--clean')
@nox.session(python=False)
def deploy(session):
"""
Deploys on pypi.
"""
session.install('poetry>=1.0.0,<2.0.0')
if 'POETRY_PYPI_TOKEN_PYPI' not in os.environ:
session.error('you must specify your pypi token api to deploy your package')
session.run('poetry', 'publish', '--build')
@nox.session(python=False, name='clean-nox')
def clean_nox(_):
"""Since nox take a bit of memory, this command helps to clean nox environment."""
shutil.rmtree('.nox', ignore_errors=True)
@nox.session(python=False, name='clean-robots-cache')
def clean_robots_cache(_):
"""
The creation of core.config.Configuration class creates a temporary directory.
So as long as we write tests, more folders are created. This command helps to delete them
"""
temp_dir = Path(tempfile.gettempdir())
for path in temp_dir.iterdir():
if path.is_dir() and path.name.startswith('robots_'):
shutil.rmtree(f'{path.absolute()}')