def load(cls: Type[Leaf], package: Package) -> Leaf: """ load leaf from package with dependencies :param package: package properties :return: loaded class """ clone_dir = Path(tempfile.mkdtemp()) try: Task.fetch(clone_dir, package.git_url) dependencies = Package.dependencies(clone_dir) finally: shutil.rmtree(clone_dir, ignore_errors=True) return cls(package, dependencies)
def test_fetch_existing(mocker: MockerFixture) -> None: """ must fetch new package via clone command """ mocker.patch("pathlib.Path.is_dir", return_value=True) check_output_mock = mocker.patch("ahriman.core.build_tools.task.Task._check_output") local = Path("local") Task.fetch(local, "remote", "master") check_output_mock.assert_has_calls([ mock.call("git", "fetch", "origin", "master", exception=pytest.helpers.anyvar(int), cwd=local, logger=pytest.helpers.anyvar(int)), mock.call("git", "checkout", "--force", "master", exception=pytest.helpers.anyvar(int), cwd=local, logger=pytest.helpers.anyvar(int)), mock.call("git", "reset", "--hard", "origin/master", exception=pytest.helpers.anyvar(int), cwd=local, logger=pytest.helpers.anyvar(int)) ])
def actual_version(self, paths: RepositoryPaths) -> str: """ additional method to handle VCS package versions :param paths: repository paths instance :return: package version if package is not VCS and current version according to VCS otherwise """ if not self.is_vcs: return self.version from ahriman.core.build_tools.task import Task clone_dir = paths.cache / self.base logger = logging.getLogger("build_details") Task.fetch(clone_dir, self.git_url) try: # update pkgver first Package._check_output("makepkg", "--nodeps", "--nobuild", exception=None, cwd=clone_dir, logger=logger) # generate new .SRCINFO and put it to parser srcinfo_source = Package._check_output("makepkg", "--printsrcinfo", exception=None, cwd=clone_dir, logger=logger) srcinfo, errors = parse_srcinfo(srcinfo_source) if errors: raise InvalidPackageInfo(errors) return self.full_version(srcinfo.get("epoch"), srcinfo["pkgver"], srcinfo["pkgrel"]) except Exception: logger.exception( "cannot determine version of VCS package, make sure that you have VCS tools installed" ) return self.version
def add_manual(src: str) -> Path: package = Package.load(src, self.repository.pacman, self.configuration.get("alpm", "aur_url")) path = self.repository.paths.manual / package.base Task.fetch(path, package.git_url) return path