Skip to content

Commit d0d53a4

Browse files
committed
Update to avoid merge conflicts with PR jazzband#531.
Pull request 531, among many other things, includes a similar fix for the use of `stdout` before it's been assigned. That implementation is a nicer read, so I've switched over to it.
1 parent c0937f1 commit d0d53a4

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

pipeline/compilers/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,11 @@ def execute_command(self, command, cwd=None, stdout_captured=None):
111111
else:
112112
argument_list.extend(flattening_arg)
113113

114+
stdout = None
114115
try:
115-
stdout_name = None
116-
117116
# We always catch stdout in a file, but we may not have a use for it.
118117
temp_file_container = cwd or os.path.dirname(stdout_captured or "") or os.getcwd()
119118
with NamedTemporaryFile(delete=False, dir=temp_file_container) as stdout:
120-
stdout_name = stdout.name
121119
compiling = subprocess.Popen(argument_list, cwd=cwd,
122120
stdout=stdout,
123121
stderr=subprocess.PIPE)
@@ -138,8 +136,8 @@ def execute_command(self, command, cwd=None, stdout_captured=None):
138136
raise CompilerError(e)
139137
finally:
140138
# Decide what to do with captured stdout.
141-
if stdout_name:
139+
if stdout:
142140
if stdout_captured:
143-
os.rename(stdout_name, os.path.join(cwd or os.curdir, stdout_captured))
141+
os.rename(stdout.name, os.path.join(cwd or os.curdir, stdout_captured))
144142
else:
145-
os.remove(stdout_name)
143+
os.remove(stdout.name)

0 commit comments

Comments
 (0)