def locked_repository(
        self, with_dev_reqs=False
    ):  # type: (bool) -> poetry.repositories.Repository
        """
        Searches and returns a repository of locked packages.
        """
        if not self.is_locked():
            return poetry.repositories.Repository()

        lock_data = self.lock_data
        packages = poetry.repositories.Repository()

        if with_dev_reqs:
            locked_packages = lock_data["package"]
        else:
            locked_packages = [
                p for p in lock_data["package"] if p["category"] == "main"
            ]

        if not locked_packages:
            return packages

        for info in locked_packages:
            package = poetry.packages.Package(
                info["name"], info["version"], info["version"]
            )
            package.description = info.get("description", "")
            package.category = info["category"]
            package.optional = info["optional"]
            package.hashes = lock_data["metadata"]["hashes"][info["name"]]
            package.python_versions = info["python-versions"]

            if "marker" in info:
                package.marker = parse_marker(info["marker"])
            else:
                # Compatibility for old locks
                if "requirements" in info:
                    dep = poetry.packages.Dependency("foo", "0.0.0")
                    for name, value in info["requirements"].items():
                        if name == "python":
                            dep.python_versions = value
                        elif name == "platform":
                            dep.platform = value

                    split_dep = dep.to_pep_508(False).split(";")
                    if len(split_dep) > 1:
                        package.marker = parse_marker(split_dep[1].strip())

            for dep_name, constraint in info.get("dependencies", {}).items():
                if isinstance(constraint, list):
                    for c in constraint:
                        package.add_dependency(dep_name, c)

                    continue

                package.add_dependency(dep_name, constraint)

            if "source" in info:
                package.source_type = info["source"]["type"]
                package.source_url = info["source"]["url"]
                package.source_reference = info["source"]["reference"]

            packages.add_package(package)

        return packages
def locked_repository ( self , with_dev_reqs = False ) : if not self . is_locked ( ) : return poetry . repositories . Repository ( ) lock_data = self . lock_data packages = poetry . repositories . Repository ( ) if with_dev_reqs : locked_packages = lock_data [ "package" ] else : locked_packages = [ p for p in lock_data [ "package" ] if p [ "category" ] == "main" ] if not locked_packages : return packages for info in locked_packages : package = poetry . packages . Package ( info [ "name" ] , info [ "version" ] , info [ "version" ] ) package . description = info . get ( "description" , "" ) package . category = info [ "category" ] package . optional = info [ "optional" ] package . hashes = lock_data [ "metadata" ] [ "hashes" ] [ info [ "name" ] ] package . python_versions = info [ "python-versions" ] if "marker" in info : package . marker = parse_marker ( info [ "marker" ] ) else : if "requirements" in info : dep = poetry . packages . Dependency ( "foo" , "0.0.0" ) for name , value in info [ "requirements" ] . items ( ) : if name == "python" : dep . python_versions = value elif name == "platform" : dep . platform = value split_dep = dep . to_pep_508 ( False ) . split ( ";" ) if len ( split_dep ) > 1 : package . marker = parse_marker ( split_dep [ 1 ] . strip ( ) ) for dep_name , constraint in info . get ( "dependencies" , { } ) . items ( ) : if isinstance ( constraint , list ) : for c in constraint : package . add_dependency ( dep_name , c ) continue package . add_dependency ( dep_name , constraint ) if "source" in info : package . source_type = info [ "source" ] [ "type" ] package . source_url = info [ "source" ] [ "url" ] package . source_reference = info [ "source" ] [ "reference" ] packages . add_package ( package ) return packages
Searches and returns a repository of locked packages.