def load_python(self, path): if isinstance(path, loader.Path): pth = path else: pth = loader.Path(os.path.join(self.repository.basepath, path), self.repository) self.debug(1, 'loading python {}'.format(pth.repo_rel_path)) self.current_file = pth self.get_file_context(pth) self.current_file = None
def load_all_python(self): for b in self.bases: sdir = os.path.join(b, self.subdir) if os.path.isdir(sdir): for p in os.listdir(sdir): if not p.endswith('.py') or len(p) <= 3 and \ p[:-3].strip('0123456789abcdefghijklmnopqrstuvwxyz_') != '': continue path = loader.Path(os.path.join(sdir, p), base=b) ctx = self.get_file_context(path) for symname in ctx.get_symnames(): # Note we take last-match here so we can sub-class properly # ordering is left as an exercise to the reader if symname.startswith('__'): continue sym = ctx.get_symbol(symname) if sym is not None: self.symbols[symname] = sym
def _rec_add(path): d_ents = os.listdir( os.path.join(self.repository.basepath, basepath, path, '.')) for d_ent in sorted(d_ents): if d_ent.startswith('.'): continue if os.path.exists( os.path.join(self.repository.basepath, basepath, path, d_ent, '.')): if path == '.': _rec_add(d_ent) else: _rec_add(os.path.join(path, d_ent)) continue paths.append( loader.Path( os.path.join(self.repository.basepath, basepath, path, d_ent), self.repository))
def import_relative(self, py_context, name_path, name, exports, **kwargs): new_context = None b = py_context.path.base pth = os.path.join(b, self.subdir, name_path) if os.path.exists(pth): path = loader.Path(pth, base=b) basename = name if 'import_as' in kwargs and kwargs['import_as'] is not None: basename = kwargs['import_as'] if 'import_as' in kwargs: del kwargs['import_as'] self.add_dep(self.current_context[-1], path) new_context = self.get_file_context(path) self.import_symbols(name, new_context.path, py_context.path, basename, new_context, py_context._current_module, exports, **kwargs) return new_context.get_module() return new_context
def get_path(self, path): return loader.Path(os.path.join(repo.basepath, 'test/test/data', path), repo)