Skip to content

Commit 22fe7f8

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 8800b86 commit 22fe7f8

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

noxfile.py

+20-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from pathlib import Path
2+
from tempfile import TemporaryDirectory
3+
import os
24

35
import nox
46

@@ -34,17 +36,10 @@ def audit(session):
3436

3537
@session(tags=["build"])
3638
def build(session):
37-
session.install("build")
38-
tmpdir = session.create_tmp()
39-
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
40-
41-
42-
@session(tags=["style"])
43-
def readme(session):
4439
session.install("build", "twine")
45-
tmpdir = session.create_tmp()
46-
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
47-
session.run("python", "-m", "twine", "check", tmpdir + "/*")
40+
with TemporaryDirectory() as tmpdir:
41+
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
42+
session.run("twine", "check", "--strict", tmpdir + "/*")
4843

4944

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

9389

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

0 commit comments

Comments
 (0)