Skip to content

Commit 4817d36

Browse files
committed
Don't use nox.session.create_tmp.
It's basically a footgun, in that it: * doesn't create a pseudorandom temporary directory, it just gives you the path 'tmp/' * thereby then doesn't create separate directories if you call it multiple times * mutates the global (shell) environment state by setting TMPDIR to this 'new' directory so other processes can now 'accidentally' end up sticking things in it (In particular I was really confused how/why non-distribution files were being plopped into my python -m build's outdir, but it was because TMPDIR was sticking around)
1 parent 7046da1 commit 4817d36

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

noxfile.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
from tempfile import TemporaryDirectory
23
import os
34

45
import nox
@@ -106,18 +107,11 @@ def audit(session, installable):
106107

107108
@session(tags=["build"])
108109
def build(session):
109-
session.install("build")
110-
tmpdir = session.create_tmp()
111-
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
112-
113-
114-
@session(tags=["style"])
115-
def readme(session):
116110
session.install("build", "docutils", "twine")
117-
tmpdir = session.create_tmp()
118-
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
119-
session.run("python", "-m", "twine", "check", "--strict", tmpdir + "/*")
120-
session.run("rst2html5.py", "--halt=warning", CHANGELOG, "/dev/null")
111+
with TemporaryDirectory() as tmpdir:
112+
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
113+
session.run("twine", "check", "--strict", tmpdir + "/*")
114+
session.run("rst2html5.py", "--halt=warning", CHANGELOG, "/dev/null")
121115

122116

123117
@session()
@@ -154,20 +148,21 @@ def typing(session):
154148
)
155149
def docs(session, builder):
156150
session.install("-r", DOCS / "requirements.txt")
157-
tmpdir = Path(session.create_tmp())
158-
argv = ["-n", "-T", "-W"]
159-
if builder != "spelling":
160-
argv += ["-q"]
161-
session.run(
162-
"python",
163-
"-m",
164-
"sphinx",
165-
"-b",
166-
builder,
167-
DOCS,
168-
tmpdir / builder,
169-
*argv,
170-
)
151+
with TemporaryDirectory() as tmpdir_str:
152+
tmpdir = Path(tmpdir_str)
153+
argv = ["-n", "-T", "-W"]
154+
if builder != "spelling":
155+
argv += ["-q"]
156+
session.run(
157+
"python",
158+
"-m",
159+
"sphinx",
160+
"-b",
161+
builder,
162+
DOCS,
163+
tmpdir / builder,
164+
*argv,
165+
)
171166

172167

173168
@session(tags=["docs", "style"], name="docs(style)")

0 commit comments

Comments
 (0)