Commit 492fec24 by David Trowbridge

Merge branch 'master' into compiler-is_outdated

parents c4ff03e5 7198db4b
......@@ -35,12 +35,12 @@ class Compiler(object):
infile = self.storage.path(input_path)
except NotImplementedError:
infile = finders.find(input_path)
outfile = self.output_path(infile, compiler.output_extension)
outfile = compiler.output_path(infile, compiler.output_extension)
outdated = compiler.is_outdated(infile, outfile)
compiler.compile_file(infile, outfile,
outdated=outdated, force=force)
return self.output_path(input_path, compiler.output_extension)
return compiler.output_path(input_path, compiler.output_extension)
else:
return input_path
......@@ -53,10 +53,6 @@ class Compiler(object):
with futures.ThreadPoolExecutor(max_workers=multiprocessing.cpu_count()) as executor:
return list(executor.map(_compile, paths))
def output_path(self, path, extension):
path = os.path.splitext(path)
return '.'.join((path[0], extension))
class CompilerBase(object):
def __init__(self, verbose, storage):
......@@ -78,6 +74,10 @@ class CompilerBase(object):
file.close()
return content
def output_path(self, path, extension):
path = os.path.splitext(path)
return '.'.join((path[0], extension))
def is_outdated(self, infile, outfile):
if not self.storage.exists(outfile):
return True
......@@ -111,6 +111,7 @@ class SubProcessCompiler(CompilerBase):
else:
argument_list.extend(flattening_arg)
stdout = None
try:
# 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()
......@@ -135,7 +136,8 @@ class SubProcessCompiler(CompilerBase):
raise CompilerError(e)
finally:
# Decide what to do with captured stdout.
if stdout_captured:
os.rename(stdout.name, os.path.join(cwd or os.curdir, stdout_captured))
else:
os.remove(stdout.name)
if stdout:
if stdout_captured:
os.rename(stdout.name, os.path.join(cwd or os.curdir, stdout_captured))
else:
os.remove(stdout.name)
......@@ -81,7 +81,9 @@ class DummyCompilerTest(TestCase):
self.compiler = Compiler()
def test_output_path(self):
output_path = self.compiler.output_path("js/helpers.coffee", "js")
compiler_class = self.compiler.compilers[0]
compiler = compiler_class(verbose=self.compiler.verbose, storage=self.compiler.storage)
output_path = compiler.output_path("js/helpers.coffee", "js")
self.assertEqual(output_path, "js/helpers.js")
def test_compilers_class(self):
......@@ -107,7 +109,9 @@ class CompilerStdoutTest(TestCase):
self.compiler = Compiler()
def test_output_path(self):
output_path = self.compiler.output_path("js/helpers.coffee", "js")
compiler_class = self.compiler.compilers[0]
compiler = compiler_class(verbose=self.compiler.verbose, storage=self.compiler.storage)
output_path = compiler.output_path("js/helpers.coffee", "js")
self.assertEqual(output_path, "js/helpers.js")
def test_compile(self):
......@@ -126,7 +130,9 @@ class CompilerSelfWriterTest(TestCase):
self.compiler = Compiler()
def test_output_path(self):
output_path = self.compiler.output_path("js/helpers.coffee", "js")
compiler_class = self.compiler.compilers[0]
compiler = compiler_class(verbose=self.compiler.verbose, storage=self.compiler.storage)
output_path = compiler.output_path("js/helpers.coffee", "js")
self.assertEqual(output_path, "js/helpers.js")
def test_compile(self):
......
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