def find_dependencies(self, source_path): source = self.get_source(source_path) source_dir = posixpath.dirname(source_path) dependencies = set() imported_files = set() for import_path in self.find_imports(source): if import_path.endswith(".styl"): # @import "foo.styl" imported_files.add( self.locate_imported_file(source_dir, import_path)) elif import_path.endswith("/*"): # @import "foo/*" imported_dir = posixpath.join(source_dir, import_path[:-2]) try: imported_dir_full_path = self.get_full_source_path( imported_dir) except ValueError: raise StaticCompilationError( "Can't locate the imported directory: {0}".format( import_path)) if not os.path.isdir(imported_dir_full_path): raise StaticCompilationError( "Imported path is not a directory: {0}".format( import_path)) for filename in os.listdir(imported_dir_full_path): if filename.endswith(".styl"): imported_files.add( self.locate_imported_file(imported_dir, filename)) else: try: # @import "foo" -> @import "foo/index.styl" imported_dir = posixpath.join(source_dir, import_path) imported_dir_full_path = self.get_full_source_path( imported_dir) if os.path.isdir(imported_dir_full_path): imported_files.add( self.locate_imported_file(imported_dir, "index.styl")) except ValueError: # @import "foo" -> @import "foo.styl" imported_files.add( self.locate_imported_file(source_dir, import_path + ".styl")) dependencies.update(imported_files) for imported_file in imported_files: dependencies.update(self.find_dependencies(imported_file)) return sorted(dependencies)
def compile_source(self, source): out, errors = run_command( "{0} -c -s -p".format(COFFEESCRIPT_EXECUTABLE), source) if errors: raise StaticCompilationError(errors) return out
def compile_source(self, source): args = [self.executable] out, errors = run_command(args, source) if errors: raise StaticCompilationError(errors) return out
def locate_imported_file(self, source_dir, import_path): """ Locate the imported file in the source directory. Return the path to the imported file relative to STATIC_ROOT :param source_dir: source directory :type source_dir: str :param import_path: path to the imported file :type import_path: str :returns: str """ if not import_path.endswith(self.EXTENSION): import_path += self.EXTENSION path = os.path.normpath(os.path.join(source_dir, import_path)) if os.path.exists(os.path.join(STATIC_ROOT, path)): return path filename = os.path.basename(import_path) if filename[0] != "_": path = os.path.normpath( os.path.join( source_dir, os.path.dirname(import_path), "_" + filename, )) if os.path.exists(os.path.join(STATIC_ROOT, path)): return path raise StaticCompilationError( "Can't locate the imported file: {0}".format(import_path))
def compile_file(self, source_path): command = "{0} {1}".format(LESS_EXECUTABLE, self.get_full_source_path(source_path)) out, errors = run_command(command, None, STATIC_ROOT) if errors: raise StaticCompilationError(errors) return out
def compile_source(self, source): args = [ ES6_EXECUTABLE ] out, errors = run_command(args, source) if errors: raise StaticCompilationError(errors) return out
def compile_source(self, source): command = "{0} -".format(LESS_EXECUTABLE) out, errors = run_command(command, source, STATIC_ROOT) if errors: raise StaticCompilationError(errors) return out
def compile_source(self, source): command = "{0} -s --scss -C".format(SCSS_EXECUTABLE) if SCSS_USE_COMPASS: command += " --compass" out, errors = run_command(command, source, STATIC_ROOT) if errors: raise StaticCompilationError(errors) return out
def compile_file(self, source_path): command = "{0} -C {1}".format(SCSS_EXECUTABLE, self.get_full_source_path(source_path)) if SCSS_USE_COMPASS: command += " --compass" out, errors = run_command(command, None, STATIC_ROOT) if errors: raise StaticCompilationError(errors) return out
def compile_source(self, source): args = [ COFFEESCRIPT_EXECUTABLE, "-c", "-s", "-p", ] out, errors = run_command(args, source) if errors: raise StaticCompilationError(errors) return out
def compile_file(self, source_path): full_source_path = self.get_full_source_path(source_path) args = [ LESS_EXECUTABLE, full_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("/"))))) out, errors = run_command(args, None, cwd=cwd) if errors: raise StaticCompilationError(errors) return out
def compile_source(self, source): args = [ settings.SCSS_EXECUTABLE, "-s", "-C", ] if self.compass_enabled(): args.append("--compass") out, errors = run_command(args, source) if errors: raise StaticCompilationError(errors) return out
def compile_source(self, source): args = [ self.executable, "-" ] out, errors = run_command(args, source) if errors: raise StaticCompilationError(errors) if LESS_POST_COMPILE: out = LESS_POST_COMPILE(out) return out
def compile_source(self, source): args = [ self.executable, "-s", ] if self.executable.endswith("sass"): args.append("--scss") if self.is_compass_enabled: args.append("--compass") out, errors = run_command(args, source) if errors: raise StaticCompilationError(errors) return out
def locate_imported_file(self, source_dir, import_path): """ Locate the imported file in the source directory. Return the path to the imported file relative to STATIC_ROOT :param source_dir: source directory :type source_dir: str :param import_path: path to the imported file :type import_path: str :returns: str """ path = posixpath.normpath(posixpath.join(source_dir, import_path)) try: self.get_full_source_path(path) except ValueError: raise StaticCompilationError( "Can't locate the imported file: {0}".format(import_path)) return path
def locate_imported_file(self, source_dir, import_path): """ Locate the imported file in the source directory. Return the path to the imported file relative to STATIC_ROOT :param source_dir: source directory :type source_dir: str :param import_path: path to the imported file :type import_path: str :returns: str """ for extension in self.import_extensions: import_path_probe = import_path if not import_path_probe.endswith("." + extension): import_path_probe += "." + extension path = posixpath.normpath( posixpath.join(source_dir, import_path_probe)) try: self.get_full_source_path(path) return path except ValueError: pass filename = posixpath.basename(import_path_probe) if filename[0] != "_": path = posixpath.normpath( posixpath.join( source_dir, posixpath.dirname(import_path_probe), "_" + filename, )) try: self.get_full_source_path(path) return path except ValueError: pass raise StaticCompilationError( "Can't locate the imported file: {0}".format(import_path))
def compile_file(self, source_path): full_source_path = self.get_full_source_path(source_path) args = [ self.executable, full_source_path, ] if self.is_compass_enabled: args.append("--compass") # `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 = run_command(args, None, cwd=cwd) if errors: raise StaticCompilationError(errors) return out
def locate_imported_file(self, source_dir, import_path): """ Locate the imported file in the source directory. Return the relative path to the imported file in posix format. :param source_dir: source directory :type source_dir: str :param import_path: path to the imported file :type import_path: str :returns: str """ if not import_path.endswith(self.EXTENSION): import_path += self.EXTENSION path = posixpath.normpath(posixpath.join(source_dir, import_path)) try: self.get_full_source_path(path) return path except ValueError: pass filename = posixpath.basename(import_path) if filename[0] != "_": path = posixpath.normpath( posixpath.join( source_dir, posixpath.dirname(import_path), "_" + filename, )) try: self.get_full_source_path(path) return path except ValueError: pass raise StaticCompilationError( "Can't locate the imported file: {0}".format(import_path))