Beispiel #1
0
 def input(self, in_, out, source_path, **kw):
     # Set working directory to the source file so that includes are found
     args = [self.binary or 'postcss']
     if self.extra_args:
         args.extend(self.extra_args)
     with working_directory(filename=source_path):
         self.subprocess(args, out, in_)
Beispiel #2
0
    def input(self, _in, out, **kw):
        """Like the original sass filter, this also needs to work as
        an input filter, so that relative @imports can be properly
        resolved.
        """

        source_path = kw['source_path']

        # Because PyScss always puts the current working dir at first
        # place of the load path, this is what we need to use to make
        # relative references work.
        with working_directory(os.path.dirname(source_path)):

            scss = self.scss.Scss(
                scss_opts={
                    'compress':
                    False,
                    'debug_info': (self.env.debug if self.debug_info is None
                                   else self.debug_info),
                },
                # This is rather nice. We can pass along the filename,
                # but also give it already preprocessed content.
                scss_files={source_path: _in.read()})

            # Compile
            # Note: This will not throw an error when certain things
            # are wrong, like an include file missing. It merely outputs
            # to stdout, via logging. We might have to do something about
            # this, and evaluate such problems to an exception.
            out.write(scss.compile())
Beispiel #3
0
    def input(self, _in, out, **kw):
        """Like the original sass filter, this also needs to work as
        an input filter, so that relative @imports can be properly
        resolved.
        """

        source_path = kw['source_path']

        # Because PyScss always puts the current working dir at first
        # place of the load path, this is what we need to use to make
        # relative references work.
        with working_directory(os.path.dirname(source_path)):

            scss = self.scss.Scss(
                scss_opts={
                    'compress': False,
                    'debug_info': (
                        self.env.debug if self.debug_info is None else self.debug_info),
                },
                # This is rather nice. We can pass along the filename,
                # but also give it already preprocessed content.
                scss_files={source_path: _in.read()})

            # Compile
            # Note: This will not throw an error when certain things
            # are wrong, like an include file missing. It merely outputs
            # to stdout, via logging. We might have to do something about
            # this, and evaluate such problems to an exception.
            out.write(scss.compile())
Beispiel #4
0
 def input(self, in_, out, source_path, **kw):
     # Set working directory to the source file so that includes are found
     with working_directory(filename=source_path):
         cmd = [self.less or 'lessc', '-']
         if self.line_numbers:
             cmd.insert(-1, '--line-numbers=%s' % self.line_numbers)
         self.subprocess(cmd, out, in_)
Beispiel #5
0
 def input(self, in_, out, source_path, **kw):
     # Set working directory to the source file so that includes are found
     args = [self.less or 'lessc']
     if self.line_numbers:
         args.append('--line-numbers=%s' % self.line_numbers)
     if self.extra_args:
         args.extend(self.extra_args)
     args.append('-')
     with working_directory(filename=source_path):
         self.subprocess(args, out, in_)
Beispiel #6
0
 def input(self, in_, out, source_path, **kw):
     # Set working directory to the source file so that includes are found
     args = self.parse_binary(self.less or 'lessc')
     if self.line_numbers:
         args.append('--line-numbers=%s' % self.line_numbers)
     if self.extra_args:
         args.extend(self.extra_args)
     args.append('-')
     with working_directory(filename=source_path):
         self.subprocess(args, out, in_)
Beispiel #7
0
 def input(self, in_, out, source_path, **kw):
     # Set working directory to the source file so that includes are found
     args = [self.autoprefixer or 'autoprefixer']
     if self.browsers:
         if isinstance(self.browsers, (list, tuple)):
             self.browsers = u','.join(self.browsers)
         args.extend(['--browsers', self.browsers])
     if self.extra_args:
         args.extend(self.extra_args)
     with working_directory(filename=source_path):
         self.subprocess(args, out, in_)
Beispiel #8
0
 def input(self, in_, out, source_path, **kw):
     # Set working directory to the source file so that includes are found
     args = [self.autoprefixer or 'autoprefixer']
     if self.browsers:
         if isinstance(self.browsers, (list, tuple)):
             self.browsers = u','.join(self.browsers)
         args.extend(['--browsers', self.browsers])
     if self.extra_args:
         args.extend(self.extra_args)
     with working_directory(filename=source_path):
         self.subprocess(args, out, in_)
Beispiel #9
0
 def input(self, in_, out, source_path, **kw):
     # Set working directory to the source file so that includes are found
     args = [self.less or 'lessc']
     if self.line_numbers:
         args.append('--line-numbers=%s' % self.line_numbers)
     if self.paths:
         paths = [path if isabs(path) else self.env.resolver.resolve_source(path) for path in self.paths]
         args.append('--include-path={0}'.format(os.pathsep.join(paths)))
     if self.extra_args:
         args.extend(self.extra_args)
     args.append('-')
     with working_directory(filename=source_path):
         self.subprocess([self.less or 'lessc', '--verbose', '-'], out, in_)
Beispiel #10
0
    def _apply_less(self, in_, out, output_path, output, **kw):
        # Set working directory to the source file so that includes are found
        args = [self.less or "lessc"]
        if self.line_numbers:
            args.append(f"--line-numbers={self.line_numbers}")

        if self.paths:
            paths = [
                path if isabs(path) else self.ctx.resolver.resolve_source(path)
                for path in self.pathsep
            ]
            args.append(f"--include-path={os.pathsep.join(paths)}")

        #
        # Commented out since this doesn't work with the current lessc compiler.
        # (See also just below)
        #
        # source_map = self.source_map_file and self.ctx.debug
        # if source_map:
        #     source_map_dest = os.path.join(self.ctx.directory,
        #                                    self.source_map_file)
        #     self.logger.debug('Generate source map to "%s"', source_map_dest)
        #     args.append('--source-map={}'.format(source_map_dest))
        #     args.append('--source-map-url={}'.format(self.source_map_file))

        if self.extra_args:
            args.extend(self.extra_args)

        args.append("-")
        buf = StringIO()
        with working_directory(filename=output_path):
            self.subprocess(args, buf, in_)

        # if source_map:
        #     self.fix_source_map_urls(source_map_dest)

        # rewrite css url()
        replace_url = partial(self.fix_url, os.path.dirname(output_path))
        buf.seek(0)
        url_rewriter = get_filter("cssrewrite", replace=replace_url)
        url_rewriter.set_context(self.ctx)
        url_rewriter.setup()
        url_rewriter.input(
            buf,
            out,
            source=output,
            source_path=output_path,
            output=output,
            output_path=output_path,
        )
Beispiel #11
0
    def test_manifest(self):
        """Test the custom manifest option."""
        self.create_files(['media/sub/a'])
        a = Bundle('a', output='out')
        self.assets_env.register('a', a)

        # Use direct filepath - this will be relative to the cwd,
        # not the media directory.
        self.env.directory = self.path('media/sub')
        with working_directory(self.tempdir):
            self.cmd_env.build(manifest='bla')
            assert self.exists('bla')

        # Use prefix syntax
        self.cmd_env.build(manifest='file:miau')
        assert self.exists('media/sub/miau')
Beispiel #12
0
 def input(self, in_, out, source_path, **kw):
     # Set working directory to the source file so that includes are found
     args = [self.less or 'lessc']
     if self.line_numbers:
         args.append('--line-numbers=%s' % self.line_numbers)
     if self.paths:
         paths = [
             path if isabs(path) else self.env.resolver.resolve_source(path)
             for path in self.paths
         ]
         args.append('--include-path={0}'.format(os.pathsep.join(paths)))
     if self.extra_args:
         args.extend(self.extra_args)
     args.append('-')
     with working_directory(filename=source_path):
         self.subprocess(args, out, in_)
Beispiel #13
0
    def test_manifest(self):
        """Test the custom manifest option."""
        self.create_files(["media/sub/a"])
        a = Bundle("a", output="out")
        self.assets_env.register("a", a)

        # Use direct filepath - this will be relative to the cwd,
        # not the media directory.
        self.env.directory = self.path("media/sub")
        with working_directory(self.tempdir):
            self.cmd_env.build(manifest="bla")
            assert self.exists("bla")

        # Use prefix syntax
        self.cmd_env.build(manifest="file:miau")
        assert self.exists("media/sub/miau")
Beispiel #14
0
    def _apply_less(self, in_, out, output_path, output, **kw):
        # Set working directory to the source file so that includes are found
        args = [self.less or 'lessc']
        if self.line_numbers:
            args.append('--line-numbers=%s' % self.line_numbers)

        if self.paths:
            paths = [
                path if isabs(path) else self.ctx.resolver.resolve_source(path)
                for path in self.pathsep
            ]
            args.append('--include-path={0}'.format(os.pathsep.join(paths)))

        source_map = self.source_map_file and self.ctx.debug
        if source_map:
            source_map_dest = os.path.join(self.ctx.directory,
                                           self.source_map_file)
            self.logger.debug('Generate source map to "%s"', source_map_dest)
            args.append('--source-map={}'.format(source_map_dest))
            args.append('--source-map-url={}'.format(self.source_map_file))

        if self.extra_args:
            args.extend(self.extra_args)

        args.append('-')
        buf = StringIO()
        with working_directory(filename=output_path):
            self.subprocess(args, buf, in_)

        if source_map:
            self.fix_source_map_urls(source_map_dest)

        # rewrite css url()
        replace_url = partial(self.fix_url, os.path.dirname(output_path))
        buf.seek(0)
        url_rewriter = get_filter('cssrewrite', replace=replace_url)
        url_rewriter.set_context(self.ctx)
        url_rewriter.setup()
        url_rewriter.input(buf,
                           out,
                           source=output,
                           source_path=output_path,
                           output=output,
                           output_path=output_path)
Beispiel #15
0
    def input(self, in_, out, source_path, **kw):
        # Set working directory to the source file so that includes are found
        with working_directory(filename=source_path):
            proc = subprocess.Popen(
                [self.less or 'lessc', '-'],
                stdout = subprocess.PIPE,
                stderr = subprocess.PIPE,
                stdin  = subprocess.PIPE
            )
            stdout, stderr = proc.communicate(in_.read())

            # At the moment (2011-12-09), there's a bug in the current version of
            # Less that always prints an error to stdout so the returncode is the
            # only way of determining if Less is actually having a compilation
            # error.
            if proc.returncode != 0:
                raise FilterError(('less: subprocess had error: stderr=%s, ' +
                                   'stdout=%s, returncode=%s') % (
                    stderr, stdout, proc.returncode))

            out.write(stdout)
Beispiel #16
0
  def _apply_less(self, in_, out, output_path, output, **kw):
    # Set working directory to the source file so that includes are found
    args = [self.less or 'lessc']
    if self.line_numbers:
      args.append('--line-numbers=%s' % self.line_numbers)

    if self.paths:
      paths = [path if isabs(path) else self.ctx.resolver.resolve_source(path)
               for path in self.pathsep]
      args.append('--include-path={0}'.format(os.pathsep.join(paths)))

    source_map = self.source_map_file and self.ctx.debug
    if source_map:
      source_map_dest = os.path.join(self.ctx.directory, self.source_map_file)
      self.logger.debug('Generate source map to "%s"', source_map_dest)
      args.append('--source-map={}'.format(source_map_dest))
      args.append('--source-map-url={}'.format(self.source_map_file))

    if self.extra_args:
      args.extend(self.extra_args)

    args.append('-')
    buf = StringIO()
    with working_directory(filename=output_path):
      self.subprocess(args, buf, in_)

    if source_map:
      self.fix_source_map_urls(source_map_dest)

    # rewrite css url()
    replace_url = partial(self.fix_url, os.path.dirname(output_path))
    buf.seek(0)
    url_rewriter = get_filter('cssrewrite', replace=replace_url)
    url_rewriter.set_context(self.ctx)
    url_rewriter.setup()
    url_rewriter.input(buf, out,
                       source=output, source_path=output_path,
                       output=output, output_path=output_path)
Beispiel #17
0
    def _apply_less(self, in_, out, source_path=None, **kw):
        # Set working directory to the source file so that includes are found
        args = self.parse_binary(self.less or 'lessc')
        if self.line_numbers:
            args.append('--line-numbers=%s' % self.line_numbers)

        if self.paths:
            paths = [
                path if os.path.isabs(path) else self.resolve_source(path)
                for path in self.paths
            ]
            args.append('--include-path={0}'.format(os.pathsep.join(paths)))

        if self.extra_args:
            args.extend(self.extra_args)

        args.append('-')

        if source_path:
            with working_directory(filename=source_path):
                self.subprocess(args, out, in_)
        else:
            self.subprocess(args, out, in_)
Beispiel #18
0
 def input(self, in_, out, source_path, **kw):
     # Set working directory to the source file so that includes are found
     with working_directory(filename=source_path):
         self.subprocess([self.less or 'lessc', '-'], out, in_)