本文整理汇总了Python中pipeline.compilers.Compiler类的典型用法代码示例。如果您正苦于以下问题:Python Compiler类的具体用法?Python Compiler怎么用?Python Compiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Compiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CompilerTest
class CompilerTest(TestCase):
def setUp(self):
default_collector.collect()
self.compiler = Compiler()
self.old_compilers = settings.PIPELINE_COMPILERS
settings.PIPELINE_COMPILERS = ['tests.tests.test_compiler.DummyCompiler']
def test_output_path(self):
output_path = self.compiler.output_path("js/helpers.coffee", "js")
self.assertEqual(output_path, "js/helpers.js")
def test_compilers_class(self):
compilers_class = self.compiler.compilers
self.assertEqual(compilers_class[0], DummyCompiler)
def test_compile(self):
paths = self.compiler.compile([
_('pipeline/js/dummy.coffee'),
_('pipeline/js/application.js'),
])
self.assertEqual([_('pipeline/js/dummy.js'), _('pipeline/js/application.js')], list(paths))
def tearDown(self):
default_collector.clear()
settings.PIPELINE_COMPILERS = self.old_compilers
示例2: FailingCompilerTest
class FailingCompilerTest(TestCase):
def setUp(self):
default_collector.collect()
self.compiler = Compiler()
def test_compile(self):
with self.assertRaises(CompilerError) as cm:
self.compiler.compile([_('pipeline/js/dummy.coffee')])
e = cm.exception
self.assertEqual(e.command, ['/usr/bin/env', 'false'])
self.assertEqual(e.error_output, '')
def tearDown(self):
default_collector.clear()
示例3: CompilerStdoutTest
class CompilerStdoutTest(TestCase):
def setUp(self):
default_collector.collect()
self.compiler = Compiler()
def test_output_path(self):
output_path = self.compiler.output_path("js/helpers.coffee", "js")
self.assertEqual(output_path, "js/helpers.js")
def test_compile(self):
paths = self.compiler.compile([_('pipeline/js/dummy.coffee')])
self.assertEqual([_('pipeline/js/dummy.junk')], list(paths))
def tearDown(self):
default_collector.clear()
示例4: Packager
class Packager(object):
def __init__(self, storage=default_storage, verbose=False, css_packages=None, js_packages=None):
self.storage = storage
self.verbose = verbose
self.compressor = Compressor(storage=storage, verbose=verbose)
self.compiler = Compiler(verbose=verbose)
if css_packages is None:
css_packages = settings.PIPELINE_CSS
if js_packages is None:
js_packages = settings.PIPELINE_JS
self.packages = {"css": self.create_packages(css_packages), "js": self.create_packages(js_packages)}
def package_for(self, kind, package_name):
try:
return self.packages[kind][package_name]
except KeyError:
raise PackageNotFound("No corresponding package for %s package name : %s" % (kind, package_name))
def individual_url(self, filename):
return self.storage.url(filename)
def pack_stylesheets(self, package, **kwargs):
return self.pack(
package,
self.compressor.compress_css,
css_compressed,
output_filename=package.output_filename,
variant=package.variant,
**kwargs
)
def compile(self, paths):
return self.compiler.compile(paths)
def pack(self, package, compress, signal, **kwargs):
output_filename = package.output_filename
if self.verbose:
print "Saving: %s" % output_filename
paths = self.compile(package.paths)
content = compress(paths, **kwargs)
self.save_file(output_filename, content)
signal.send(sender=self, package=package, **kwargs)
return output_filename
def pack_javascripts(self, package, **kwargs):
return self.pack(package, self.compressor.compress_js, js_compressed, templates=package.templates, **kwargs)
def pack_templates(self, package):
return self.compressor.compile_templates(package.templates)
def save_file(self, path, content):
return self.storage.save(path, ContentFile(smart_str(content)))
def create_packages(self, config):
packages = {}
if not config:
return packages
for name in config:
packages[name] = Package(config[name])
return packages
示例5: InvalidCompilerTest
class InvalidCompilerTest(TestCase):
def setUp(self):
default_collector.collect()
self.compiler = Compiler()
def test_compile(self):
with self.assertRaises(CompilerError) as cm:
self.compiler.compile([_('pipeline/js/dummy.coffee')])
e = cm.exception
self.assertEqual(
e.command,
['this-exists-nowhere-as-a-command-and-should-fail',
'pipeline/js/dummy.coffee',
'pipeline/js/dummy.junk'])
self.assertEqual(e.error_output, '')
def tearDown(self):
default_collector.clear()
示例6: __init__
def __init__(self, force=False, verbose=False):
self.force = force
self.verbose = verbose
self.compressor = Compressor(verbose)
self.versioning = Versioning(verbose)
self.compiler = Compiler(verbose)
self.packages = {
'css': self.create_packages(settings.PIPELINE_CSS),
'js': self.create_packages(settings.PIPELINE_JS),
}
示例7: __init__
def __init__(self, storage=default_storage, verbose=False, css_packages=None, js_packages=None):
self.storage = storage
self.verbose = verbose
self.compressor = Compressor(storage=storage, verbose=verbose)
self.compiler = Compiler(verbose=verbose)
if css_packages is None:
css_packages = settings.PIPELINE_CSS
if js_packages is None:
js_packages = settings.PIPELINE_JS
self.packages = {"css": self.create_packages(css_packages), "js": self.create_packages(js_packages)}
示例8: CompilerTest
class CompilerTest(TestCase):
def setUp(self):
self.compiler = Compiler()
self.old_compilers = settings.PIPELINE_COMPILERS
settings.PIPELINE_COMPILERS = ["tests.tests.test_compiler.DummyCompiler"]
def test_output_path(self):
output_path = self.compiler.output_path("js/helpers.coffee", "js")
self.assertEqual(output_path, "js/helpers.js")
def test_compilers_class(self):
compilers_class = self.compiler.compilers
self.assertEqual(compilers_class[0], DummyCompiler)
def test_compile(self):
paths = self.compiler.compile([_("pipeline/js/dummy.coffee"), _("pipeline/js/application.js")])
self.assertEqual([_("pipeline/js/dummy.js"), _("pipeline/js/application.js")], paths)
def tearDown(self):
settings.PIPELINE_COMPILERS = self.old_compilers
示例9: CompilerWithEmptyFirstArgTest
class CompilerWithEmptyFirstArgTest(TestCase):
def setUp(self):
default_collector.collect()
self.compiler = Compiler()
def test_compile(self):
paths = self.compiler.compile([_('pipeline/js/dummy.coffee')])
default_collector.collect()
self.assertEqual([_('pipeline/js/dummy.junk')], list(paths))
def tearDown(self):
default_collector.clear()
示例10: __init__
def __init__(self, verbose=False, css_packages=None, js_packages=None):
self.verbose = verbose
self.compressor = Compressor(verbose)
self.versioning = Versioning(verbose)
self.compiler = Compiler(verbose)
if css_packages is None:
css_packages = settings.PIPELINE_CSS
if js_packages is None:
js_packages = settings.PIPELINE_JS
self.packages = {
'css': self.create_packages(css_packages),
'js': self.create_packages(js_packages),
}
示例11: __init__
def __init__(self, storage=None, verbose=False, css_packages=None, js_packages=None):
if storage is None:
storage = staticfiles_storage
self.storage = storage
self.verbose = verbose
self.compressor = Compressor(storage=storage, verbose=verbose)
self.compiler = Compiler(storage=storage, verbose=verbose)
if css_packages is None:
css_packages = settings.STYLESHEETS
if js_packages is None:
js_packages = settings.JAVASCRIPT
self.packages = {
'css': self.create_packages(css_packages),
'js': self.create_packages(js_packages),
}
示例12: CompilerSelfWriterTest
class CompilerSelfWriterTest(TestCase):
def setUp(self):
default_collector.collect()
self.compiler = Compiler()
def test_output_path(self):
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):
paths = self.compiler.compile([_('pipeline/js/dummy.coffee')])
default_collector.collect()
self.assertEqual([_('pipeline/js/dummy.junk')], list(paths))
def tearDown(self):
default_collector.clear()
示例13: setUp
def setUp(self):
default_collector.collect()
self.compiler = Compiler()
self.old_compilers = settings.PIPELINE_COMPILERS
settings.PIPELINE_COMPILERS = ['tests.tests.test_compiler.DummyCompiler']
示例14: Packager
class Packager(object):
def __init__(self, storage=default_storage, verbose=False, css_packages=None, js_packages=None):
self.storage = storage
self.verbose = verbose
self.compressor = Compressor(storage=storage, verbose=verbose)
self.compiler = Compiler(verbose=verbose)
if css_packages is None:
css_packages = settings.PIPELINE_CSS
if js_packages is None:
js_packages = settings.PIPELINE_JS
self.packages = {
'css': self.create_packages(css_packages),
'js': self.create_packages(js_packages),
}
def package_for(self, kind, package_name):
try:
return self.packages[kind][package_name]
except KeyError:
raise PackageNotFound(
"No corresponding package for %s package name : %s" % (
kind, package_name
)
)
def individual_url(self, filename):
return self.storage.url(filename)
def pack_stylesheets(self, package, **kwargs):
return self.pack(package, self.compressor.compress_css, css_compressed,
output_filename=package.output_filename,
variant=package.variant, **kwargs)
def compile(self, paths, force=False):
return self.compiler.compile(paths, force=force)
def pack(self, package, compress, signal, **kwargs):
output_filename = package.output_filename
if self.verbose:
print "Saving: %s" % output_filename
paths = self.compile(package.paths, force=True)
content = compress(paths, **kwargs)
self.save_file(output_filename, content)
signal.send(sender=self, package=package, **kwargs)
return output_filename
def pack_javascripts(self, package, **kwargs):
return self.pack(package, self.compressor.compress_js, js_compressed, templates=package.templates, **kwargs)
def pack_templates(self, package):
if settings.PIPELINE_TEMPLATE_USE_CACHE and package.templates:
key_partial = hashlib.md5()
key_partial.update(str(package.templates))
cache_key = "%s_%s"%(key_partial.hexdigest(), translation.get_language())
default_cache = cache.get_cache('default')
cached_package = default_cache.get(cache_key)
if not cached_package:
cached_package = self.compressor.compile_templates(package.templates)
default_cache.set(cache_key, cached_package)
return cached_package
else:
if self.verbose:
print "Generating templates without using cache .."
return self.compressor.compile_templates(package.templates)
def save_file(self, path, content):
return self.storage.save(path, ContentFile(smart_str(content)))
def create_packages(self, config):
packages = {}
if not config:
return packages
for name in config:
packages[name] = Package(config[name])
return packages
示例15: setUp
def setUp(self):
self.compiler = Compiler()
self.old_compilers = settings.PIPELINE_COMPILERS
settings.PIPELINE_COMPILERS = ['tests.tests.compiler.DummyCompiler']