4343from macaron .config .defaults import defaults
4444from macaron .config .global_config import global_config
4545from macaron .errors import CloneError , RepoCheckOutError
46- from macaron .repo_finder import to_domain_from_known_purl_types
46+ from macaron .repo_finder import repo_finder_pypi , to_domain_from_known_purl_types
4747from macaron .repo_finder .commit_finder import find_commit , match_tags
4848from macaron .repo_finder .repo_finder_base import BaseRepoFinder
4949from macaron .repo_finder .repo_finder_deps_dev import DepsDevRepoFinder
6666 list_remote_references ,
6767 resolve_local_path ,
6868)
69+ from macaron .slsa_analyzer .specs .package_registry_spec import PackageRegistryInfo
6970
7071logger : logging .Logger = logging .getLogger (__name__ )
7172
7273
73- def find_repo (purl : PackageURL , check_latest_version : bool = True ) -> tuple [str , RepoFinderInfo ]:
74+ def find_repo (
75+ purl : PackageURL ,
76+ check_latest_version : bool = True ,
77+ package_registries_info : list [PackageRegistryInfo ] | None = None ,
78+ ) -> tuple [str , RepoFinderInfo ]:
7479 """Retrieve the repository URL that matches the given PURL.
7580
7681 Parameters
@@ -79,6 +84,9 @@ def find_repo(purl: PackageURL, check_latest_version: bool = True) -> tuple[str,
7984 The parsed PURL to convert to the repository path.
8085 check_latest_version: bool
8186 A flag that determines whether the latest version of the PURL is also checked.
87+ package_registries_info: list[PackageRegistryInfo] | None
88+ The list of package registry information if available.
89+ If no package registries are loaded, this can be set to None.
8290
8391 Returns
8492 -------
@@ -103,6 +111,9 @@ def find_repo(purl: PackageURL, check_latest_version: bool = True) -> tuple[str,
103111 logger .debug ("Analyzing %s with Repo Finder: %s" , purl , type (repo_finder ))
104112 found_repo , outcome = repo_finder .find_repo (purl )
105113
114+ if not found_repo :
115+ found_repo , outcome = find_repo_alternative (purl , outcome , package_registries_info )
116+
106117 if check_latest_version and not defaults .getboolean ("repofinder" , "try_latest_purl" , fallback = True ):
107118 check_latest_version = False
108119
@@ -117,13 +128,49 @@ def find_repo(purl: PackageURL, check_latest_version: bool = True) -> tuple[str,
117128 return "" , RepoFinderInfo .NO_NEWER_VERSION
118129
119130 found_repo , outcome = DepsDevRepoFinder ().find_repo (latest_version_purl )
131+ if found_repo :
132+ return found_repo , outcome
133+
134+ if not found_repo :
135+ found_repo , outcome = find_repo_alternative (latest_version_purl , outcome , package_registries_info )
136+
120137 if not found_repo :
121138 logger .debug ("Could not find repo from latest version of PURL: %s" , latest_version_purl )
122139 return "" , RepoFinderInfo .LATEST_VERSION_INVALID
123140
124141 return found_repo , outcome
125142
126143
144+ def find_repo_alternative (
145+ purl : PackageURL , outcome : RepoFinderInfo , package_registries_info : list [PackageRegistryInfo ] | None = None
146+ ) -> tuple [str , RepoFinderInfo ]:
147+ """Use PURL type specific methods to find the repository when the standard methods have failed.
148+
149+ Parameters
150+ ----------
151+ purl : PackageURL
152+ The parsed PURL to convert to the repository path.
153+ outcome: RepoFinderInfo
154+ A previous outcome to report if this method does nothing.
155+ package_registries_info: list[PackageRegistryInfo] | None
156+ The list of package registry information if available.
157+ If no package registries are loaded, this can be set to None.
158+
159+ Returns
160+ -------
161+ tuple[str, RepoFinderOutcome] :
162+ The repository URL for the passed package, if found, and the outcome to report.
163+ """
164+ found_repo = ""
165+ if purl .type == "pypi" :
166+ found_repo , outcome = repo_finder_pypi .find_repo (purl , package_registries_info )
167+
168+ if not found_repo :
169+ logger .debug ("Could not find repository using type specific (%s) methods for PURL: %s" , purl .type , purl )
170+
171+ return found_repo , outcome
172+
173+
127174def to_repo_path (purl : PackageURL , available_domains : list [str ]) -> str | None :
128175 """Return the repository path from the PURL string.
129176
0 commit comments