def _regenerate(self, debug=False): path = find_file(self.module) mtime = os.path.getmtime(path) if mtime == self._mtime: return source = read_text_file(path) self._compiled = self._compile(source, debug=debug) self._compiled_hash = sha1(smart_str(self._compiled)).hexdigest() self._mtime = mtime
def _regenerate(self, dev_mode=False): # This function is only called in only_dependencies mode if self._compiled: for module_name, (mtime, content, hash) in self._compiled.items(): if module_name not in self._collected or \ not os.path.exists(self._collected[module_name]) or \ os.path.getmtime(self._collected[module_name]) != mtime: # Just recompile everything # TODO: track dependencies and changes and recompile only # what's necessary self._compiled = {} break else: # No changes return modules = [self.main_module, 'pyjslib'] while True: if not modules: break module_name = modules.pop() path = self._collected[module_name] mtime = os.path.getmtime(path) source = read_text_file(path) try: content, py_deps, js_deps = self._compile(module_name, source, dev_mode=dev_mode) except: self._compiled = {} raise hash = sha1(smart_str(content)).hexdigest() self._compiled[module_name] = (mtime, content, hash) for name in py_deps: if name not in self._collected: if '.' in name and name.rsplit('.', 1)[0] in self._collected: name = name.rsplit('.', 1)[0] else: raise ImportError('The pyjs module %s could not find ' 'the dependency %s' % (module_name, name)) if name not in self._compiled: modules.append(name)
def get_dev_output(self, name, variation): self._collect_all_modules() name = name.split('/', 1)[-1] if name == '._pyjs.js': return self._compile_init() elif name == '.main.js': return self._compile_main(dev_mode=True) if self.only_dependencies: self._regenerate(dev_mode=True) return self._compiled[name][1] else: source = read_text_file(self._collected[name]) return self._compile(name, source, dev_mode=True)[0]
def get_output(self, variation): self._collect_all_modules() if not self.exclude_main_libs: yield self._compile_init() if self.only_dependencies: self._regenerate(dev_mode=False) for name in sorted(self._compiled.keys()): yield self._compiled[name][1] else: for name in sorted(self._collected.keys()): source = read_text_file(self._collected[name]) yield self._compile(name, source, dev_mode=False)[0] yield self._compile_main(dev_mode=False)
def _regenerate(self, debug=False): if self._dependencies: for name, mtime in self._dependencies.items(): path = self._find_file(name) if not path or os.path.getmtime(path) != mtime: # Just recompile everything self._dependencies = {} break else: # No changes return modules = [self.main_module] # get all the transitive dependencies of this module while True: if not modules: break module_name = modules.pop() path = self._find_file(module_name) assert path, 'Could not find the Less module {}'.format( module_name) mtime = os.path.getmtime(path) self._dependencies[module_name] = mtime source = read_text_file(path) dependencies = self._get_dependencies(source) for name in dependencies: # Try relative import, first transformed = posixpath.join(posixpath.dirname(module_name), name) path = self._find_file(transformed) if path: name = transformed else: path = self._find_file(name) assert path, 'The Less module {} could not find the dependency {}'.format( module_name, name) if name not in self._dependencies: modules.append(name) main_module_path = self._find_file(self.main_module) self._compiled = self._compile(main_module_path, debug=debug) self._compiled_hash = sha1(smart_str(self._compiled)).hexdigest()
def _regenerate(self, debug=False): if self._dependencies: for name, mtime in self._dependencies.items(): path = self._find_file(name) if not path or os.path.getmtime(path) != mtime: # Just recompile everything self._dependencies = {} break else: # No changes return modules = [self.main_module] # get all the transitive dependencies of this module while True: if not modules: break module_name = modules.pop() path = self._find_file(module_name) assert path, 'Could not find the Less module %s' % module_name mtime = os.path.getmtime(path) self._dependencies[module_name] = mtime source = read_text_file(path) dependencies = self._get_dependencies(source) for name in dependencies: # Try relative import, first transformed = posixpath.join(posixpath.dirname(module_name), name) path = self._find_file(transformed) if path: name = transformed else: path = self._find_file(name) assert path, ('The Less module %s could not find the ' 'dependency %s' % (module_name, name)) if name not in self._dependencies: modules.append(name) main_module_path = self._find_file(self.main_module) self._compiled = self._compile(main_module_path, debug=debug) self._compiled_hash = sha1(smart_str(self._compiled)).hexdigest()
def get_dev_output(self, name, variation): self.name = name return read_text_file(self._get_path())
def _compile_init(self): return INIT_CODE + read_text_file(PYJS_INIT_LIB_PATH)
def _get_contents(self, language): filename = self._get_filename(language) path = find_file(filename) assert path, "File name '%s' doesn't exist." % filename return read_text_file(path)
def get_dev_output(self, name, variation): assert name == self.name, ( f'''File name "{name}" doesn't match the one in GENERATE_MEDIA ("{self.name}")''') return read_text_file(self.path)
def get_dev_output(self, name, variation): assert name == self.name, ( '''File name "%s" doesn't match the one in GENERATE_MEDIA ("%s")''' % (name, self.name)) return read_text_file(self.path)
def get_dev_output(self, name, variation): assert name == self.name, """File name "%s" doesn't match the one in GENERATE_MEDIA ("%s")""" % ( name, self.name, ) return read_text_file(self._get_path())
def get_dev_output(self, name, variation): assert name == self.name, ( '''File name "{}" doesn't match the one in GENERATE_MEDIA ("{}")''' .format(name, self.name)) return read_text_file(self._get_path())