forked from planetlabs/planet-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
152 lines (107 loc) · 3.64 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
from pathlib import Path
import shutil
import nox
nox.options.stop_on_first_error = True
nox.options.reuse_existing_virtualenvs = False
nox.options.sessions = ['lint', 'analyze', 'test', 'coverage', 'docs']
source_files = ("planet", "examples", "tests", "setup.py", "noxfile.py")
BUILD_DIRS = ['build', 'dist']
@nox.session
def analyze(session):
session.install(".[lint]")
session.run("mypy", "--ignore-missing", "planet")
@nox.session
def coverage(session):
session.install("-e", ".[test]")
session.run('coverage',
'run',
'-m',
'pytest',
'-qq',
'--no-header',
'--no-summary',
'--no-cov',
'--ignore',
'examples/')
session.run('coverage', 'report')
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"])
def test(session):
session.install(".[test]")
options = session.posargs
session.run('pytest', '--ignore', 'examples/', '-v', *options)
@nox.session
def lint(session):
session.install("-e", ".[lint]")
session.run("flake8", *source_files)
session.run('yapf', '--diff', '-r', *source_files)
@nox.session
def docs_test(session):
session.install("-e", ".[docs]")
options = session.posargs
# Because these doc examples can be long-running, output
# the INFO and above log messages so we know what's happening
session.run('pytest',
'--doctest-glob',
'*.md',
'--no-cov',
'--ignore',
'examples/',
'--ignore',
'tests/',
'--log-cli-level=INFO',
*options)
@nox.session
def docs(session):
session.install("-e", ".[docs]")
session.run("mkdocs", "build")
@nox.session
def watch(session):
'''Build and serve live docs for editing'''
session.install("-e", ".[docs]")
session.run("mkdocs", "serve")
@nox.session
def examples(session):
session.install("-e", ".[test]")
options = session.posargs
# Because these example scripts can be long-running, output the
# example's stdout so we know what's happening
session.run('pytest', '--no-cov', 'examples/', '-s', *options)
@nox.session
def build(session):
'''Build package'''
# check preexisting
exist_but_should_not = [p for p in BUILD_DIRS if Path(p).is_dir()]
if exist_but_should_not:
session.error(f"Pre-existing {', '.join(exist_but_should_not)}. "
"Run clean session and try again")
session.install('build', 'twine', 'check-wheel-contents')
session.run(*'python -m build --sdist --wheel'.split())
session.run('check-wheel-contents', 'dist')
@nox.session
def clean(session):
'''Remove build directories'''
to_remove = [Path(d) for d in BUILD_DIRS if Path(d).is_dir()]
for p in to_remove:
shutil.rmtree(p)
@nox.session
def publish_testpypi(session):
'''Publish to TestPyPi using API token'''
_publish(session, 'testpypi')
@nox.session
def publish_pypi(session):
'''Publish to PyPi using API token'''
_publish(session, 'pypi')
def _publish(session, repository):
missing = [p for p in BUILD_DIRS if not Path(p).is_dir()]
if missing:
session.error(
f"Missing one or more build directories: {', '.join(missing)}. "
"Run build session and try again")
session.install('twine')
files = [str(f) for f in Path('dist').iterdir()]
session.run("twine", "check", *files)
session.run("twine",
"upload",
f"--repository={repository}",
'-u=__token__',
*files)