当前位置: 首页>>代码示例>>Python>>正文


Python Compiler.compile方法代码示例

本文整理汇总了Python中pipeline.compilers.Compiler.compile方法的典型用法代码示例。如果您正苦于以下问题:Python Compiler.compile方法的具体用法?Python Compiler.compile怎么用?Python Compiler.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pipeline.compilers.Compiler的用法示例。


在下文中一共展示了Compiler.compile方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FailingCompilerTest

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
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()
开发者ID:chipx86,项目名称:django-pipeline,代码行数:17,代码来源:test_compiler.py

示例2: CompilerTest

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
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
开发者ID:Alexx-G,项目名称:django-pipeline,代码行数:27,代码来源:test_compiler.py

示例3: Packager

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
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
开发者ID:javiertejero,项目名称:django-pipeline,代码行数:62,代码来源:packager.py

示例4: InvalidCompilerTest

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
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()
开发者ID:chipx86,项目名称:django-pipeline,代码行数:20,代码来源:test_compiler.py

示例5: CompilerWithEmptyFirstArgTest

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
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()
开发者ID:chipx86,项目名称:django-pipeline,代码行数:14,代码来源:test_compiler.py

示例6: CompilerStdoutTest

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
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()
开发者ID:leonardoo,项目名称:django-pipeline,代码行数:17,代码来源:test_compiler.py

示例7: CompilerSelfWriterTest

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
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()
开发者ID:chipx86,项目名称:django-pipeline,代码行数:20,代码来源:test_compiler.py

示例8: CompilerTest

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
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
开发者ID:Xowap,项目名称:django-pipeline,代码行数:22,代码来源:test_compiler.py

示例9: Packager

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
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,
                         '/*# sourceMappingURL={} */',
                         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, source_mapping_template, **kwargs):
        output_filename = package.output_filename
        if self.verbose:
            print("Saving: %s" % output_filename)
        paths = self.compile(package.paths, force=True)
        content, source_map = compress(paths, **kwargs)
        if source_map is not None:
            source_map_output_filename = output_filename + '.map'
            self.save_file(source_map_output_filename, source_map)
            content = content + '\n' + source_mapping_template.format(
                os.path.basename(source_map_output_filename))
        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,
                         '//# sourceMappingURL={}',
                         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
开发者ID:aehlke,项目名称:django-pipeline,代码行数:72,代码来源:packager.py

示例10: Packager

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
class Packager(object):
    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),
        }

    def package_for(self, kind, package_name):
        try:
            return self.packages[kind][package_name].copy()
        except KeyError:
            raise PackageNotFound(
                "No corresponding package for %s package name : %s" % (
                    kind, package_name
                )
            )

    def individual_url(self, filename):
        relative_path = self.compressor.relative_path(filename)[1:]
        return urlparse.urljoin(settings.PIPELINE_URL,
            filepath_to_uri(relative_path))

    def pack_stylesheets(self, package, **kwargs):
        variant = package.get('variant', None)
        absolute_asset_paths = package.get('absolute_asset_paths', True)
        return self.pack(package, self.compressor.compress_css, css_compressed,
            variant=variant, absolute_asset_paths=absolute_asset_paths,
            **kwargs)

    def compile(self, paths):
        return self.compiler.compile(paths)

    def pack(self, package, compress, signal, sync=False, force=False, **kwargs):
        if settings.PIPELINE_AUTO or (force and sync):
            need_update, version = self.versioning.need_update(
                package['output'], package['paths'])
            if need_update or force:
                output_filename = self.versioning.output_filename(
                    package['output'],
                    version
                )
                self.versioning.cleanup(package['output'])
                if self.verbose:
                    print "Version: %s" % version
                    print "Saving: %s" % output_filename
                paths = self.compile(package['paths'])
                content = compress(paths,
                    asset_url=self.individual_url(output_filename), **kwargs)
                self.save_file(output_filename, content)
        else:
            filename_base, filename = os.path.split(package['output'])
            version = self.versioning.version_from_file(filename_base, filename, force=force)
        signal.send(sender=self, package=package, version=version, **kwargs)
        return self.versioning.output_filename(package['output'], version)

    def pack_javascripts(self, package, **kwargs):
        if 'externals' in package:
            return
        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 storage.save(path, ContentFile(smart_str(content)))

    def create_packages(self, config):
        packages = {}
        if not config:
            return packages
        for name in config:
            packages[name] = {}
            if 'external_urls' in config[name]:
                packages[name]['externals'] = config[name]['external_urls']
                continue
            paths = []
            for pattern in config[name]['source_filenames']:
                for path in glob(pattern):
                    if not path in paths:
                        paths.append(str(path))
            packages[name]['paths'] = [path for path in paths if not path.endswith(settings.PIPELINE_TEMPLATE_EXT)]
            packages[name]['templates'] = [path for path in paths if path.endswith(settings.PIPELINE_TEMPLATE_EXT)]
            packages[name]['output'] = config[name]['output_filename']
            packages[name]['context'] = {}
            packages[name]['manifest'] = True
            if 'absolute_asset_paths' in config[name]:
                packages[name]['absolute_asset_paths'] = \
                    config[name]['absolute_asset_paths']
            if 'extra_context' in config[name]:
                packages[name]['context'] = config[name]['extra_context']
            if 'template_name' in config[name]:
                packages[name]['template'] = config[name]['template_name']
#.........这里部分代码省略.........
开发者ID:UniIsland,项目名称:django-pipeline,代码行数:103,代码来源:packager.py

示例11: Packager

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
class Packager(object):
    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),
        }

    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, compiler_options={}, force=False):
        return self.compiler.compile(
            paths,
            compiler_options=compiler_options,
            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,
            compiler_options=package.compiler_options,
            force=True,
        )
        output_path = self.storage.path(output_filename)
        output_mtime = self.storage.get_modified_time(output_path)
        if any([self.storage.get_modified_time(self.storage.path(path)) >=
                output_mtime for path in 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_bytes(content)))

    def create_packages(self, config):
        packages = {}
        if not config:
            return packages
        for name in config:
            packages[name] = Package(config[name])
        return packages
开发者ID:sassanh,项目名称:django-pipeline,代码行数:78,代码来源:packager.py

示例12: Packager

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
class Packager(object):
    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.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):
        paths = self.compiler.compile(paths, force=force)
        for path in paths:
            if not self.storage.exists(path):
                if self.verbose:
                    print("Compiled file '%s' cannot be found with packager's storage. Locating it." % path)

                source_storage = self.find_source_storage(path)
                if source_storage is not None:
                    with source_storage.open(path) as source_file:
                        if self.verbose:
                            print("Saving: %s" % path)
                        self.storage.save(path, source_file)
                else:
                    raise IOError("File does not exist: %s" % path)
        return 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, 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):
        return self.compressor.compile_templates(package.templates)

    def save_file(self, path, content):
        return self.storage.save(path, ContentFile(smart_bytes(content)))

    def find_source_storage(self, path):
        for finder in get_finders():
            for short_path, storage in finder.list(''):
                if short_path == path:
                    if self.verbose:
                        print("Found storage: %s" % str(self.storage))
                    return storage
        return None

    def create_packages(self, config):
        packages = {}
        if not config:
            return packages
        for name in config:
            packages[name] = Package(config[name])
        return packages
开发者ID:beedesk,项目名称:django-pipeline,代码行数:89,代码来源:packager.py

示例13: Packager

# 需要导入模块: from pipeline.compilers import Compiler [as 别名]
# 或者: from pipeline.compilers.Compiler import compile [as 别名]
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
开发者ID:dydek,项目名称:django-pipeline,代码行数:77,代码来源:packager.py


注:本文中的pipeline.compilers.Compiler.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。