def load(self, fetch=True, **kwargs): """Retrieves and stubs project requirements.""" self.pkg_path.mkdir(parents=True, exist_ok=True) if self.path.exists(): self.add_from_file(self.path) pkg_keys = set(self.packages.keys()) pkg_cache = self.cache.get(self.name) new_pkgs = pkg_keys.copy() if pkg_cache: new_pkgs = new_pkgs - set(pkg_cache) new_packages = [ Package.from_text(name, spec) for name, spec in self.packages.items() if name in new_pkgs ] if fetch: if new_packages: self.log.title("Fetching Requirements") for req in new_packages: def format_desc(p): return "".join(self.log.iter_formatted(f"$B[{p}]")) source = create_dependency_source( str(req), name=req.name, format_desc=lambda p: f"{self.log.get_service()} {format_desc(p)}") self.install_package(source) self.update() self.cache.upsert(self.name, list(pkg_keys))
def load(self, fetch=True, **kwargs): """Retrieves and stubs project requirements.""" self.pkg_path.mkdir(parents=True, exist_ok=True) if self.path.exists(): reqs = utils.iter_requirements(self.path) for r in reqs: pkg = create_dependency_source(r.line).package if not self.packages.get(pkg.name): self.config.add(self.name + '/' + pkg.name, pkg.pretty_specs) if pkg.editable: self.context.extend('local_paths', [pkg.path], unique=True) pkg_keys = set(self.packages.keys()) pkg_cache = self.cache.get(self.name) new_pkgs = pkg_keys.copy() if pkg_cache: new_pkgs = new_pkgs - set(pkg_cache) new_packages = [Package.from_text(name, spec) for name, spec in self.packages.items() if name in new_pkgs] if fetch: if new_packages: self.log.title("Fetching Requirements") for req in new_packages: def format_desc(p): return "".join(self.log.iter_formatted(f"$B[{p}]")) source = create_dependency_source( str(req), name=req.name, format_desc=lambda p: f"{self.log.get_service()} {format_desc(p)}") self.install_package(source) self.update() self.cache.upsert(self.name, list(pkg_keys))
def update(self): """Dumps packages to file at path.""" if not self.path.exists(): self.path.touch() pkgs = [Package.from_text(name, spec) for name, spec in self.config.get(self.name).items()] self.log.debug(f"dumping to {self.path.name}") with self.path.open("r+") as f: content = [c.strip() for c in f.readlines() if c.strip() != ""] _lines = sorted(set(str(p) for p in pkgs) | set(content)) lines = [l + "\n" for l in _lines] self.log.debug(f"dumping: {lines}") f.seek(0) f.writelines(lines) local_paths = [p.path for p in pkgs if p.editable] if local_paths: self.context.add("local_paths", local_paths) self.context.extend("paths", [self.pkg_path], unique=True)