Skip to content

Commit

Permalink
Merge pull request #540 from davidt/compiler-paths
Browse files Browse the repository at this point in the history
Allow compilers to override output_path.
  • Loading branch information
davidt committed Feb 22, 2016
2 parents 76da062 + 2899300 commit 7198db4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions pipeline/compilers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def _compile(input_path):
for compiler in self.compilers:
compiler = compiler(verbose=self.verbose, storage=self.storage)
if compiler.match_file(input_path):
output_path = self.output_path(input_path, compiler.output_extension)
output_path = compiler.output_path(input_path, compiler.output_extension)
try:
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(input_path, output_path)
compiler.compile_file(infile, outfile,
outdated=outdated, force=force)
Expand All @@ -53,10 +53,6 @@ def _compile(input_path):
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):
Expand All @@ -78,6 +74,10 @@ def read_file(self, path):
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
Expand Down
12 changes: 9 additions & 3 deletions tests/tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def setUp(self):
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):
Expand All @@ -107,7 +109,9 @@ def setUp(self):
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):
Expand All @@ -126,7 +130,9 @@ def setUp(self):
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):
Expand Down

0 comments on commit 7198db4

Please sign in to comment.