コード例 #1
0
    def compile_file(self, source_path):
        full_source_path = self.get_full_source_path(source_path)
        full_output_path = self.get_full_output_path(source_path)
        args = [
            self.executable,
        ]
        if self.is_sourcemap_enabled:
            args.append("-m")
        args.extend([
            full_source_path,
            "-o", os.path.dirname(full_output_path),
        ])

        full_output_dirname = os.path.dirname(full_output_path)
        if not os.path.exists(full_output_dirname):
            os.makedirs(full_output_dirname)

        # `cwd` is a directory containing `source_path`.
        # Ex: source_path = '1/2/3', full_source_path = '/abc/1/2/3' -> cwd = '/abc'
        cwd = os.path.normpath(os.path.join(full_source_path, *([".."] * len(source_path.split("/")))))
        out, errors = utils.run_command(args, cwd=cwd)

        if errors:
            raise exceptions.StaticCompilationError(errors)

        utils.convert_urls(full_output_path, source_path)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path, full_output_path)

        return self.get_output_path(source_path)
コード例 #2
0
    def compile_file(self, source_path):
        args = [
            self.executable,
        ] + self.get_extra_args()

        if self.is_sourcemap_enabled:
            args.append("-s")

        full_output_path = self.get_full_output_path(source_path)

        full_output_dirname = os.path.dirname(full_output_path)
        if not os.path.exists(full_output_dirname):
            os.makedirs(full_output_dirname)

        args.extend(["-o", full_output_path])
        args.append(self.get_full_source_path(source_path))

        return_code, out, errors = utils.run_command(args)
        if return_code:
            raise exceptions.StaticCompilationError(errors)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path, full_output_path)

        return self.get_output_path(source_path)
コード例 #3
0
    def compile_file(self, source_path):
        full_output_path = self.get_full_output_path(source_path)
        # LiveScript bug with source map if the folder isn't already present
        if not os.path.exists(os.path.dirname(full_output_path)):
            os.makedirs(os.path.dirname(full_output_path))
        args = [
            self.executable,
            "-c",
        ]
        if self.is_sourcemap_enabled:
            args.append("-m")
            args.append("linked")
        args.extend([
            "-o", os.path.dirname(full_output_path),
            self.get_full_source_path(source_path),
        ])
        return_code, out, errors = utils.run_command(args)

        if return_code:
            raise exceptions.StaticCompilationError(errors)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path, full_output_path)

        return self.get_output_path(source_path)
コード例 #4
0
    def compile_file(self, source_path):
        full_output_path = self.get_full_output_path(source_path)
        output_dir = os.path.dirname(full_output_path)

        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        template_extension = os.path.splitext(source_path)[1].lstrip(".")

        args = [
            self.executable,
            self.get_full_source_path(source_path),
            "-e",
            template_extension,
            "-f",
            full_output_path,
        ] + self.get_extra_args()

        if self.is_sourcemap_enabled:
            args += ["--map", full_output_path + ".map"]

        out, errors = utils.run_command(args)

        if errors:
            raise exceptions.StaticCompilationError(errors)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path,
                                full_output_path)

        return self.get_output_path(source_path)
コード例 #5
0
    def compile_file(self, source_path):
        full_source_path = self.get_full_source_path(source_path)
        full_output_path = self.get_full_output_path(source_path)
        args = [
            self.executable,
            "--sourcemap={}".format("auto" if self.is_sourcemap_enabled else "none"),
        ] + self.get_extra_args()

        args.extend([
            self.get_full_source_path(source_path),
            full_output_path,
        ])

        full_output_dirname = os.path.dirname(full_output_path)
        if not os.path.exists(full_output_dirname):
            os.makedirs(full_output_dirname)

        # `cwd` is a directory containing `source_path`.
        # Ex: source_path = '1/2/3', full_source_path = '/abc/1/2/3' -> cwd = '/abc'
        cwd = os.path.normpath(os.path.join(full_source_path, *([".."] * len(source_path.split("/")))))
        out, errors = utils.run_command(args, None, cwd=cwd)

        if errors:
            if os.path.exists(full_output_path):
                os.remove(full_output_path)
            raise exceptions.StaticCompilationError(errors)

        utils.convert_urls(full_output_path, source_path)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path, full_output_path)

        return self.get_output_path(source_path)
コード例 #6
0
ファイル: stylus.py プロジェクト: trb116/pythonanalyzer
    def compile_file(self, source_path):
        full_source_path = self.get_full_source_path(source_path)
        full_output_path = self.get_full_output_path(source_path)
        args = [
            self.executable,
        ]
        if self.is_sourcemap_enabled:
            args.append("-m")
        args.extend([
            full_source_path,
            "-o",
            os.path.dirname(full_output_path),
        ])

        full_output_dirname = os.path.dirname(full_output_path)
        if not os.path.exists(full_output_dirname):
            os.makedirs(full_output_dirname)

        # `cwd` is a directory containing `source_path`.
        # Ex: source_path = '1/2/3', full_source_path = '/abc/1/2/3' -> cwd = '/abc'
        cwd = os.path.normpath(
            os.path.join(full_source_path,
                         *([".."] * len(source_path.split("/")))))
        out, errors = utils.run_command(args, cwd=cwd)

        if errors:
            raise exceptions.StaticCompilationError(errors)

        utils.convert_urls(full_output_path, source_path)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path,
                                full_output_path)

        return self.get_output_path(source_path)
コード例 #7
0
    def compile_file(self, source_path):
        args = [
            self.executable,
        ] + self.get_extra_args()

        if self.is_sourcemap_enabled:
            args.append("-s")

        full_output_path = self.get_full_output_path(source_path)

        full_output_dirname = os.path.dirname(full_output_path)
        if not os.path.exists(full_output_dirname):
            os.makedirs(full_output_dirname)

        args.extend(["-o", full_output_path])
        args.append(self.get_full_source_path(source_path))

        out, errors = utils.run_command(args)
        if errors:
            raise exceptions.StaticCompilationError(errors)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path, full_output_path)

        return self.get_output_path(source_path)
コード例 #8
0
    def compile_file(self, source_path):
        full_source_path = self.get_full_source_path(source_path)
        full_output_path = self.get_full_output_path(source_path)
        args = [
            self.executable,
            "--sourcemap={}".format("auto" if self.is_sourcemap_enabled else "none"),
        ] + self.get_extra_args()

        args.extend([
            self.get_full_source_path(source_path),
            full_output_path,
        ])

        full_output_dirname = os.path.dirname(full_output_path)
        if not os.path.exists(full_output_dirname):
            os.makedirs(full_output_dirname)

        # `cwd` is a directory containing `source_path`.
        # Ex: source_path = '1/2/3', full_source_path = '/abc/1/2/3' -> cwd = '/abc'
        cwd = os.path.normpath(os.path.join(full_source_path, *([".."] * len(source_path.split("/")))))
        return_code, out, errors = utils.run_command(args, None, cwd=cwd)

        if return_code:
            if os.path.exists(full_output_path):
                os.remove(full_output_path)
            raise exceptions.StaticCompilationError(errors)

        utils.convert_urls(full_output_path, source_path)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path, full_output_path)

        return self.get_output_path(source_path)
コード例 #9
0
    def compile_file(self, source_path):
        full_source_path = self.get_full_source_path(source_path)
        full_output_path = self.get_full_output_path(source_path)

        # `cwd` is a directory containing `source_path`.
        # Ex: source_path = '1/2/3', full_source_path = '/abc/1/2/3' -> cwd = '/abc'
        cwd = os.path.normpath(os.path.join(full_source_path, *([".."] * len(source_path.split("/")))))

        args = [self.executable]
        if self.is_sourcemap_enabled:
            args.extend(["--source-map"])
        if self.global_vars:
            for variable_name, variable_value in self.global_vars.items():
                args.extend(["--global-var={}={}".format(variable_name, variable_value)])

        args.extend([self.get_full_source_path(source_path), full_output_path])
        out, errors = utils.run_command(args, cwd=cwd)

        if errors:
            raise exceptions.StaticCompilationError(errors)

        utils.convert_urls(full_output_path, source_path)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path, full_output_path)

        return self.get_output_path(source_path)
コード例 #10
0
    def compile_file(self, source_path):
        full_output_path = self.get_full_output_path(source_path)
        output_dir = os.path.dirname(full_output_path)

        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        template_extension = os.path.splitext(source_path)[1].lstrip(".")

        args = [
            self.executable,
            self.get_full_source_path(source_path),
            "-e", template_extension,
            "-f", full_output_path,
        ] + self.get_extra_args()

        if self.is_sourcemap_enabled:
            args += ["--map", full_output_path + ".map"]

        return_code, out, errors = utils.run_command(args)

        if return_code:
            raise exceptions.StaticCompilationError(errors)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path, full_output_path)

        return self.get_output_path(source_path)
コード例 #11
0
ファイル: less.py プロジェクト: wd5/django-static-precompiler
    def compile_file(self, source_path):
        full_source_path = self.get_full_source_path(source_path)
        full_output_path = self.get_full_output_path(source_path)

        # `cwd` is a directory containing `source_path`.
        # Ex: source_path = '1/2/3', full_source_path = '/abc/1/2/3' -> cwd = '/abc'
        cwd = os.path.normpath(
            os.path.join(full_source_path,
                         *([".."] * len(source_path.split("/")))))

        args = [self.executable]
        if self.is_sourcemap_enabled:
            args.extend(["--source-map"])
        if self.global_vars:
            for variable_name, variable_value in self.global_vars.items():
                args.extend([
                    "--global-var={}={}".format(variable_name, variable_value),
                ])

        args.extend([
            self.get_full_source_path(source_path),
            full_output_path,
        ])
        return_code, out, errors = utils.run_command(args, cwd=cwd)

        if return_code:
            raise exceptions.StaticCompilationError(errors)

        utils.convert_urls(full_output_path, source_path)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path,
                                full_output_path)

        return self.get_output_path(source_path)
コード例 #12
0
    def compile_file(self, source_path):
        full_output_path = self.get_full_output_path(source_path)
        # LiveScript bug with source map if the folder isn't already present
        if not os.path.exists(os.path.dirname(full_output_path)):
            os.makedirs(os.path.dirname(full_output_path))
        args = [
            self.executable,
            "-c",
        ]
        if self.is_sourcemap_enabled:
            args.append("-m")
            args.append("linked")
        args.extend([
            "-o",
            os.path.dirname(full_output_path),
            self.get_full_source_path(source_path),
        ])
        return_code, out, errors = utils.run_command(args)

        if return_code:
            raise exceptions.StaticCompilationError(errors)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(full_output_path + ".map", source_path,
                                full_output_path)

        return self.get_output_path(source_path)
コード例 #13
0
    def compile_file(self, source_path):
        full_output_path = self.get_full_output_path(source_path)
        args = [
            self.executable,
            "-c",
        ]
        if self.is_sourcemap_enabled:
            args.append("-m")
        if self.transpile:
            args.append("-t")
        if not self.header:
            args.append("--no-header")
        args.extend([
            "-o",
            os.path.dirname(full_output_path),
            self.get_full_source_path(source_path),
        ])
        return_code, out, errors = utils.run_command(args)

        if return_code:
            raise exceptions.StaticCompilationError(errors)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(
                os.path.splitext(full_output_path)[0] + ".map", source_path,
                full_output_path)

        return self.get_output_path(source_path)
コード例 #14
0
ファイル: libsass.py プロジェクト: tfgg/dc_base_theme
    def compile_file(self, source_path):
        full_source_path = self.get_full_source_path(source_path)
        full_output_path = self.get_full_output_path(source_path)

        full_output_dirname = os.path.dirname(full_output_path)
        if not os.path.exists(full_output_dirname):
            os.makedirs(full_output_dirname)

        sourcemap_path = full_output_path + ".map"
        sourcemap = ""

        try:
            if self.is_sourcemap_enabled:
                compiled, sourcemap = sass.compile(
                    filename=full_source_path,
                    source_map_filename=sourcemap_path,
                    include_paths=self.load_paths
                )
            else:
                compile_kwargs = {}
                if self.load_paths:
                    compile_kwargs["include_paths"] = self.load_paths
                if self.precision:
                    compile_kwargs["precision"] = self.precision
                if self.output_style:
                    compile_kwargs["output_style"] = self.output_style
                compiled = sass.compile(filename=full_source_path, **compile_kwargs)
        except sass.CompileError as e:
            raise exceptions.StaticCompilationError(encoding.force_str(e))

        compiled = encoding.force_str(compiled)
        sourcemap = encoding.force_str(sourcemap)

        with open(full_output_path, "w+") as output_file:
            output_file.write(compiled)

        utils.convert_urls(full_output_path, source_path)

        if self.is_sourcemap_enabled:
            with open(sourcemap_path, "w+") as output_file:
                output_file.write(sourcemap)

            utils.fix_sourcemap(sourcemap_path, source_path, full_output_path)

        return self.get_output_path(source_path)
コード例 #15
0
    def compile_file(self, source_path):
        full_output_path = self.get_full_output_path(source_path)
        args = [
            self.executable,
            "-c",
        ]
        if self.is_sourcemap_enabled:
            args.append("-m")
        args.extend([
            "-o", os.path.dirname(full_output_path),
            self.get_full_source_path(source_path),
        ])
        return_code, out, errors = utils.run_command(args)

        if return_code:
            raise exceptions.StaticCompilationError(errors)

        if self.is_sourcemap_enabled:
            utils.fix_sourcemap(os.path.splitext(full_output_path)[0] + ".map", source_path, full_output_path)

        return self.get_output_path(source_path)