Commit d0d53a4e by David Trowbridge

Update to avoid merge conflicts with PR #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.
parent c0937f1a
...@@ -111,13 +111,11 @@ class SubProcessCompiler(CompilerBase): ...@@ -111,13 +111,11 @@ class SubProcessCompiler(CompilerBase):
else: else:
argument_list.extend(flattening_arg) argument_list.extend(flattening_arg)
stdout = None
try: try:
stdout_name = None
# We always catch stdout in a file, but we may not have a use for it. # We always catch stdout in a file, but we may not have a use for it.
temp_file_container = cwd or os.path.dirname(stdout_captured or "") or os.getcwd() temp_file_container = cwd or os.path.dirname(stdout_captured or "") or os.getcwd()
with NamedTemporaryFile(delete=False, dir=temp_file_container) as stdout: with NamedTemporaryFile(delete=False, dir=temp_file_container) as stdout:
stdout_name = stdout.name
compiling = subprocess.Popen(argument_list, cwd=cwd, compiling = subprocess.Popen(argument_list, cwd=cwd,
stdout=stdout, stdout=stdout,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
...@@ -138,8 +136,8 @@ class SubProcessCompiler(CompilerBase): ...@@ -138,8 +136,8 @@ class SubProcessCompiler(CompilerBase):
raise CompilerError(e) raise CompilerError(e)
finally: finally:
# Decide what to do with captured stdout. # Decide what to do with captured stdout.
if stdout_name: if stdout:
if stdout_captured: if stdout_captured:
os.rename(stdout_name, os.path.join(cwd or os.curdir, stdout_captured)) os.rename(stdout.name, os.path.join(cwd or os.curdir, stdout_captured))
else: else:
os.remove(stdout_name) os.remove(stdout.name)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment