Skip to content

Commit c22c205

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 beda0e5 commit c22c205

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
@@ -36,17 +37,10 @@ def audit(session):
3637

3738
@session(tags=["build"])
3839
def build(session):
39-
session.install("build")
40-
tmpdir = session.create_tmp()
41-
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
42-
43-
44-
@session(tags=["style"])
45-
def readme(session):
4640
session.install("build", "twine")
47-
tmpdir = session.create_tmp()
48-
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
49-
session.run("python", "-m", "twine", "check", "--strict", tmpdir + "/*")
41+
with TemporaryDirectory() as tmpdir:
42+
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
43+
session.run("twine", "check", "--strict", tmpdir + "/*")
5044

5145

5246
@session(tags=["style"])
@@ -77,20 +71,21 @@ def typing(session):
7771
)
7872
def docs(session, builder):
7973
session.install("-r", DOCS / "requirements.txt")
80-
tmpdir = Path(session.create_tmp())
81-
argv = ["-n", "-T", "-W"]
82-
if builder != "spelling":
83-
argv += ["-q"]
84-
session.run(
85-
"python",
86-
"-m",
87-
"sphinx",
88-
"-b",
89-
builder,
90-
DOCS,
91-
tmpdir / builder,
92-
*argv,
93-
)
74+
with TemporaryDirectory() as tmpdir_str:
75+
tmpdir = Path(tmpdir_str)
76+
argv = ["-n", "-T", "-W"]
77+
if builder != "spelling":
78+
argv += ["-q"]
79+
session.run(
80+
"python",
81+
"-m",
82+
"sphinx",
83+
"-b",
84+
builder,
85+
DOCS,
86+
tmpdir / builder,
87+
*argv,
88+
)
9489

9590

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

0 commit comments

Comments
 (0)