1
1
"""Automation using nox.
2
2
"""
3
3
4
- # The following comment should be removed at some point in the future.
5
- # mypy: disallow-untyped-defs=False
6
-
7
4
import glob
8
5
import os
9
6
import shutil
10
7
import sys
11
8
from pathlib import Path
9
+ from typing import Iterator , List , Tuple
12
10
13
11
import nox
14
12
34
32
35
33
36
34
def run_with_protected_pip (session , * arguments ):
35
+ # type: (nox.Session, *str) -> None
37
36
"""Do a session.run("pip", *arguments), using a "protected" pip.
38
37
39
38
This invokes a wrapper script, that forwards calls to original virtualenv
40
39
(stable) version, and not the code being tested. This ensures pip being
41
40
used is not the code being tested.
42
41
"""
43
- env = {"VIRTUAL_ENV" : session .virtualenv .location }
42
+ # https://github.com/theacodes/nox/pull/377
43
+ env = {"VIRTUAL_ENV" : session .virtualenv .location } # type: ignore
44
44
45
45
command = ("python" , LOCATIONS ["protected-pip" ]) + arguments
46
- kwargs = {"env" : env , "silent" : True }
47
- session .run (* command , ** kwargs )
46
+ session .run (* command , env = env , silent = True )
48
47
49
48
50
49
def should_update_common_wheels ():
50
+ # type: () -> bool
51
51
# If the cache hasn't been created, create it.
52
52
if not os .path .exists (LOCATIONS ["common-wheels" ]):
53
53
return True
@@ -72,6 +72,7 @@ def should_update_common_wheels():
72
72
# -----------------------------------------------------------------------------
73
73
@nox .session (python = ["3.6" , "3.7" , "3.8" , "3.9" , "pypy3" ])
74
74
def test (session ):
75
+ # type: (nox.Session) -> None
75
76
# Get the common wheels.
76
77
if should_update_common_wheels ():
77
78
run_with_protected_pip (
@@ -88,7 +89,8 @@ def test(session):
88
89
session .log (msg )
89
90
90
91
# Build source distribution
91
- sdist_dir = os .path .join (session .virtualenv .location , "sdist" )
92
+ # https://github.com/theacodes/nox/pull/377
93
+ sdist_dir = os .path .join (session .virtualenv .location , "sdist" ) # type: ignore
92
94
if os .path .exists (sdist_dir ):
93
95
shutil .rmtree (sdist_dir , ignore_errors = True )
94
96
session .run (
@@ -117,10 +119,12 @@ def test(session):
117
119
118
120
@nox .session
119
121
def docs (session ):
122
+ # type: (nox.Session) -> None
120
123
session .install ("-e" , "." )
121
124
session .install ("-r" , REQUIREMENTS ["docs" ])
122
125
123
126
def get_sphinx_build_command (kind ):
127
+ # type: (str) -> List[str]
124
128
# Having the conf.py in the docs/html is weird but needed because we
125
129
# can not use a different configuration directory vs source directory
126
130
# on RTD currently. So, we'll pass "-c docs/html" here.
@@ -141,6 +145,7 @@ def get_sphinx_build_command(kind):
141
145
142
146
@nox .session
143
147
def lint (session ):
148
+ # type: (nox.Session) -> None
144
149
session .install ("pre-commit" )
145
150
146
151
if session .posargs :
@@ -154,13 +159,15 @@ def lint(session):
154
159
155
160
@nox .session
156
161
def vendoring (session ):
162
+ # type: (nox.Session) -> None
157
163
session .install ("vendoring>=0.3.0" )
158
164
159
165
if "--upgrade" not in session .posargs :
160
166
session .run ("vendoring" , "sync" , "." , "-v" )
161
167
return
162
168
163
169
def pinned_requirements (path ):
170
+ # type: (Path) -> Iterator[Tuple[str, str]]
164
171
for line in path .read_text ().splitlines ():
165
172
one , two = line .split ("==" , 1 )
166
173
name = one .strip ()
@@ -208,6 +215,7 @@ def pinned_requirements(path):
208
215
# -----------------------------------------------------------------------------
209
216
@nox .session (name = "prepare-release" )
210
217
def prepare_release (session ):
218
+ # type: (nox.Session) -> None
211
219
version = release .get_version_from_arguments (session )
212
220
if not version :
213
221
session .error ("Usage: nox -s prepare-release -- <version>" )
@@ -243,6 +251,7 @@ def prepare_release(session):
243
251
244
252
@nox .session (name = "build-release" )
245
253
def build_release (session ):
254
+ # type: (nox.Session) -> None
246
255
version = release .get_version_from_arguments (session )
247
256
if not version :
248
257
session .error ("Usage: nox -s build-release -- YY.N[.P]" )
@@ -274,6 +283,7 @@ def build_release(session):
274
283
275
284
276
285
def build_dists (session ):
286
+ # type: (nox.Session) -> List[str]
277
287
"""Return dists with valid metadata."""
278
288
session .log (
279
289
"# Check if there's any Git-untracked files before building the wheel" ,
@@ -302,6 +312,7 @@ def build_dists(session):
302
312
303
313
@nox .session (name = "upload-release" )
304
314
def upload_release (session ):
315
+ # type: (nox.Session) -> None
305
316
version = release .get_version_from_arguments (session )
306
317
if not version :
307
318
session .error ("Usage: nox -s upload-release -- YY.N[.P]" )
@@ -320,7 +331,7 @@ def upload_release(session):
320
331
f"Remove dist/ and run 'nox -s build-release -- { version } '"
321
332
)
322
333
# Sanity check: Make sure the files are correctly named.
323
- distfile_names = map (os .path .basename , distribution_files )
334
+ distfile_names = (os .path .basename ( fn ) for fn in distribution_files )
324
335
expected_distribution_files = [
325
336
f"pip-{ version } -py3-none-any.whl" ,
326
337
f"pip-{ version } .tar.gz" ,
0 commit comments