Skip to content

Commit b588c58

Browse files
authored
Merge pull request #9411 from jdufresne/type-noxfile
Complete typing of noxfile.py
2 parents f3f4ef2 + 7ffd0ca commit b588c58

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ repos:
7474
- id: mypy
7575
exclude: docs|tests
7676
args: ["--pretty"]
77+
additional_dependencies: ['nox==2020.12.31']
7778

7879
- repo: https://github.com/pre-commit/pygrep-hooks
7980
rev: v1.7.0

news/adba2b7a-af01-49c9-9b72-2d3d4a89b11a.trivial.rst

Whitespace-only changes.

noxfile.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
"""Automation using nox.
22
"""
33

4-
# The following comment should be removed at some point in the future.
5-
# mypy: disallow-untyped-defs=False
6-
74
import glob
85
import os
96
import shutil
107
import sys
118
from pathlib import Path
9+
from typing import Iterator, List, Tuple
1210

1311
import nox
1412

@@ -34,20 +32,22 @@
3432

3533

3634
def run_with_protected_pip(session, *arguments):
35+
# type: (nox.Session, *str) -> None
3736
"""Do a session.run("pip", *arguments), using a "protected" pip.
3837
3938
This invokes a wrapper script, that forwards calls to original virtualenv
4039
(stable) version, and not the code being tested. This ensures pip being
4140
used is not the code being tested.
4241
"""
43-
env = {"VIRTUAL_ENV": session.virtualenv.location}
42+
# https://github.com/theacodes/nox/pull/377
43+
env = {"VIRTUAL_ENV": session.virtualenv.location} # type: ignore
4444

4545
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)
4847

4948

5049
def should_update_common_wheels():
50+
# type: () -> bool
5151
# If the cache hasn't been created, create it.
5252
if not os.path.exists(LOCATIONS["common-wheels"]):
5353
return True
@@ -72,6 +72,7 @@ def should_update_common_wheels():
7272
# -----------------------------------------------------------------------------
7373
@nox.session(python=["3.6", "3.7", "3.8", "3.9", "pypy3"])
7474
def test(session):
75+
# type: (nox.Session) -> None
7576
# Get the common wheels.
7677
if should_update_common_wheels():
7778
run_with_protected_pip(
@@ -88,7 +89,8 @@ def test(session):
8889
session.log(msg)
8990

9091
# 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
9294
if os.path.exists(sdist_dir):
9395
shutil.rmtree(sdist_dir, ignore_errors=True)
9496
session.run(
@@ -117,10 +119,12 @@ def test(session):
117119

118120
@nox.session
119121
def docs(session):
122+
# type: (nox.Session) -> None
120123
session.install("-e", ".")
121124
session.install("-r", REQUIREMENTS["docs"])
122125

123126
def get_sphinx_build_command(kind):
127+
# type: (str) -> List[str]
124128
# Having the conf.py in the docs/html is weird but needed because we
125129
# can not use a different configuration directory vs source directory
126130
# on RTD currently. So, we'll pass "-c docs/html" here.
@@ -141,6 +145,7 @@ def get_sphinx_build_command(kind):
141145

142146
@nox.session
143147
def lint(session):
148+
# type: (nox.Session) -> None
144149
session.install("pre-commit")
145150

146151
if session.posargs:
@@ -154,13 +159,15 @@ def lint(session):
154159

155160
@nox.session
156161
def vendoring(session):
162+
# type: (nox.Session) -> None
157163
session.install("vendoring>=0.3.0")
158164

159165
if "--upgrade" not in session.posargs:
160166
session.run("vendoring", "sync", ".", "-v")
161167
return
162168

163169
def pinned_requirements(path):
170+
# type: (Path) -> Iterator[Tuple[str, str]]
164171
for line in path.read_text().splitlines():
165172
one, two = line.split("==", 1)
166173
name = one.strip()
@@ -208,6 +215,7 @@ def pinned_requirements(path):
208215
# -----------------------------------------------------------------------------
209216
@nox.session(name="prepare-release")
210217
def prepare_release(session):
218+
# type: (nox.Session) -> None
211219
version = release.get_version_from_arguments(session)
212220
if not version:
213221
session.error("Usage: nox -s prepare-release -- <version>")
@@ -243,6 +251,7 @@ def prepare_release(session):
243251

244252
@nox.session(name="build-release")
245253
def build_release(session):
254+
# type: (nox.Session) -> None
246255
version = release.get_version_from_arguments(session)
247256
if not version:
248257
session.error("Usage: nox -s build-release -- YY.N[.P]")
@@ -274,6 +283,7 @@ def build_release(session):
274283

275284

276285
def build_dists(session):
286+
# type: (nox.Session) -> List[str]
277287
"""Return dists with valid metadata."""
278288
session.log(
279289
"# Check if there's any Git-untracked files before building the wheel",
@@ -302,6 +312,7 @@ def build_dists(session):
302312

303313
@nox.session(name="upload-release")
304314
def upload_release(session):
315+
# type: (nox.Session) -> None
305316
version = release.get_version_from_arguments(session)
306317
if not version:
307318
session.error("Usage: nox -s upload-release -- YY.N[.P]")
@@ -320,7 +331,7 @@ def upload_release(session):
320331
f"Remove dist/ and run 'nox -s build-release -- {version}'"
321332
)
322333
# 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)
324335
expected_distribution_files = [
325336
f"pip-{version}-py3-none-any.whl",
326337
f"pip-{version}.tar.gz",

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ per-file-ignores =
3131
tests/*: B011
3232

3333
[mypy]
34-
follow_imports = silent
3534
ignore_missing_imports = True
3635
disallow_untyped_defs = True
3736
disallow_any_generics = True

tools/automation/release/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def get_version_from_arguments(session: Session) -> Optional[str]:
2626
# We delegate to a script here, so that it can depend on packaging.
2727
session.install("packaging")
2828
cmd = [
29-
os.path.join(session.bin, "python"),
29+
# https://github.com/theacodes/nox/pull/378
30+
os.path.join(session.bin, "python"), # type: ignore
3031
"tools/automation/release/check_version.py",
3132
version
3233
]
@@ -153,11 +154,12 @@ def workdir(
153154
"""Temporarily chdir when entering CM and chdir back on exit."""
154155
orig_dir = pathlib.Path.cwd()
155156

156-
nox_session.chdir(dir_path)
157+
# https://github.com/theacodes/nox/pull/376
158+
nox_session.chdir(dir_path) # type: ignore
157159
try:
158160
yield dir_path
159161
finally:
160-
nox_session.chdir(orig_dir)
162+
nox_session.chdir(orig_dir) # type: ignore
161163

162164

163165
@contextlib.contextmanager

0 commit comments

Comments
 (0)