Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d868df6

Browse files
ksundenissamarabi
authored andcommitted
Switch to tempdirectory for windows support and autocleanup
1 parent 61ea244 commit d868df6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

tools/stubtest.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,25 @@ def visit_ClassDef(self, node):
5252
self.visit(child)
5353

5454

55-
with tempfile.NamedTemporaryFile("wt", delete=False) as f:
56-
for path in mpl.glob("**/*.py"):
57-
v = Visitor(path, f)
58-
tree = ast.parse(path.read_text())
55+
with tempfile.TemporaryDirectory() as d:
56+
p = pathlib.Path(d) / "allowlist.txt"
57+
with p.open("wt") as f:
58+
for path in mpl.glob("**/*.py"):
59+
v = Visitor(path, f)
60+
tree = ast.parse(path.read_text())
5961

60-
# Assign parents to tree so they can be backtraced
61-
for node in ast.walk(tree):
62-
for child in ast.iter_child_nodes(node):
63-
child.parent = node
62+
# Assign parents to tree so they can be backtraced
63+
for node in ast.walk(tree):
64+
for child in ast.iter_child_nodes(node):
65+
child.parent = node
6466

65-
v.visit(tree)
66-
f.flush()
67-
f.close()
67+
v.visit(tree)
6868
proc = subprocess.run(
6969
[
7070
"stubtest",
7171
"--mypy-config-file=pyproject.toml",
7272
"--allowlist=ci/mypy-stubtest-allowlist.txt",
73-
f"--allowlist={f.name}",
73+
f"--allowlist={p}",
7474
"matplotlib",
7575
],
7676
cwd=root,

0 commit comments

Comments
 (0)