Skip to content

Commit ac6eeb2

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 70beea9 commit ac6eeb2

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

noxfile.py

Lines changed: 19 additions & 24 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
@@ -57,17 +58,10 @@ def audit(session):
5758

5859
@session(tags=["build"])
5960
def build(session):
60-
session.install("build")
61-
tmpdir = session.create_tmp()
62-
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
63-
64-
65-
@session(tags=["style"])
66-
def readme(session):
6761
session.install("build", "twine")
68-
tmpdir = session.create_tmp()
69-
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
70-
session.run("python", "-m", "twine", "check", "--strict", tmpdir + "/*")
62+
with TemporaryDirectory() as tmpdir:
63+
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
64+
session.run("twine", "check", "--strict", tmpdir + "/*")
7165

7266

7367
@session(tags=["style"])
@@ -98,20 +92,21 @@ def typing(session):
9892
)
9993
def docs(session, builder):
10094
session.install("-r", DOCS / "requirements.txt")
101-
tmpdir = Path(session.create_tmp())
102-
argv = ["-n", "-T", "-W"]
103-
if builder != "spelling":
104-
argv += ["-q"]
105-
session.run(
106-
"python",
107-
"-m",
108-
"sphinx",
109-
"-b",
110-
builder,
111-
DOCS,
112-
tmpdir / builder,
113-
*argv,
114-
)
95+
with TemporaryDirectory() as tmpdir_str:
96+
tmpdir = Path(tmpdir_str)
97+
argv = ["-n", "-T", "-W"]
98+
if builder != "spelling":
99+
argv += ["-q"]
100+
session.run(
101+
"python",
102+
"-m",
103+
"sphinx",
104+
"-b",
105+
builder,
106+
DOCS,
107+
tmpdir / builder,
108+
*argv,
109+
)
115110

116111

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

0 commit comments

Comments
 (0)