示例#1
0
    def load(self, fetch=True, **kwargs):
        """Retrieves and stubs project requirements."""
        self.pkg_path.mkdir(exist_ok=True)
        if self.path.exists():
            packages = utils.iter_requirements(self.path)
            for p in packages:
                pkg = create_dependency_source(p.line).package
                self.packages.update({pkg.name: pkg.pretty_specs})
                self.parent.config.set(f'{self.name}.{pkg.name}',
                                       pkg.pretty_specs)
        pkg_keys = set(self.packages.keys())
        pkg_cache = self.parent._get_cache(self.name)
        new_pkgs = pkg_keys.copy()
        if pkg_cache:
            new_pkgs = new_pkgs - set(pkg_cache)
        new_pkgs = [
            f"{name}{s if s != '*' else ''}"
            for name, s in self.packages.items() if name in new_pkgs
        ]
        if fetch:
            if new_pkgs:
                self.log.title("Fetching Requirements")
            for req in new_pkgs:

                def format_desc(p):
                    return "".join(self.log.iter_formatted(f"$B[{p}]"))

                source = create_dependency_source(
                    req,
                    format_desc=lambda p:
                    f"{self.log.get_service()} {format_desc(p)}")
                self.install_package(source)
        self.update()
        self.parent._set_cache(self.name, list(pkg_keys))
示例#2
0
 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))
示例#3
0
def test_iter_requirements(mocker, tmp_path):
    """should iter requirements"""
    tmp_file = tmp_path / "tmp_reqs.txt"
    tmp_file.touch()
    tmp_file.write_text("micropy-cli==1.0.0")
    result = next(utils.iter_requirements(tmp_file))
    assert result.name == "micropy-cli"
    assert result.specs == [("==", "1.0.0")]
示例#4
0
    def add_from_file(self, path=None, dev=False, **kwargs):
        """Loads all requirements from file.

        Args:
            path (str): Path to file. Defaults to self.path.
            dev (bool, optional): If dev requirements should be loaded.
                Defaults to False.

        """
        reqs = utils.iter_requirements(self.path)
        for req in reqs:
            self.add_package(req, fetch=True)
        return reqs
示例#5
0
    def _add_pkgs_from_file(self, path, **kwargs):
        """Add packages listed in a file

        Args:
            path (str): path to file

        Returns:
            list of added reqs
        """
        if not path.exists():
            return []
        reqs = list(utils.iter_requirements(path))
        for req in reqs:
            self.add_package(req.line, **kwargs)
        return reqs
示例#6
0
    def add_from_file(self, path: Optional[Path] = None, dev: bool = False, **kwargs: Any) -> dict:
        """Loads all requirements from file.

        Args:
            path: Path to file. Defaults to self.path.
            dev: If dev requirements should be loaded.
                Defaults to False.

        """
        path = path or self.path
        reqs = utils.iter_requirements(path)
        self.log.debug(f"loading requirements from: {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)
        return self.packages