Iterate over the list of package pairs as generated by `generator`. These package pairs are usually combinations/product of a list of packages A given `method` is then applied to package pair that acts as a filter, usually a levenshtein distance or similar metric
(
generator: Generator[Tuple[str, str], None, None],
method: Callable[[str, str], int],
extended: bool = False,
)
| 189 | |
| 190 | |
| 191 | def enumerator( |
| 192 | generator: Generator[Tuple[str, str], None, None], |
| 193 | method: Callable[[str, str], int], |
| 194 | extended: bool = False, |
| 195 | ) -> Generator[Tuple[str, str], None, None]: |
| 196 | """ |
| 197 | Iterate over the list of package pairs as generated by `generator`. |
| 198 | These package pairs are usually combinations/product of a list of packages |
| 199 | A given `method` is then applied to package pair that acts as a filter, usually a levenshtein distance or similar metric |
| 200 | """ |
| 201 | |
| 202 | pkg_cache = {} |
| 203 | pkg_score_cache = {} |
| 204 | |
| 205 | for (orig, typo) in generator: |
| 206 | res = method(orig, typo) |
| 207 | if res and res < 2: |
| 208 | if orig not in pkg_cache: |
| 209 | orig_pkg = package.PypiPackage.from_cached(orig) |
| 210 | pkg_cache[orig] = orig_pkg |
| 211 | else: |
| 212 | orig_pkg = pkg_cache[orig] |
| 213 | |
| 214 | if orig not in pkg_score_cache: |
| 215 | orig_score = package.PackageScore(orig, orig_pkg, fetch_github=extended) |
| 216 | pkg_score_cache[orig] = orig_score |
| 217 | else: |
| 218 | orig_score = pkg_score_cache[orig] |
| 219 | |
| 220 | if typo not in pkg_cache: |
| 221 | typo_pkg = package.PypiPackage.from_cached(typo) |
| 222 | pkg_cache[typo] = typo_pkg |
| 223 | else: |
| 224 | typo_pkg = pkg_cache[typo] |
| 225 | |
| 226 | if typo not in pkg_score_cache: |
| 227 | typo_score = package.PackageScore(typo, typo_pkg, fetch_github=extended) |
| 228 | pkg_score_cache[typo] = typo_score |
| 229 | else: |
| 230 | typo_score = pkg_score_cache[typo] |
| 231 | |
| 232 | data = { |
| 233 | "original": orig, |
| 234 | "typo": typo, |
| 235 | "orig_pkg": orig_pkg, |
| 236 | "orig_score": orig_score, |
| 237 | "typo_pkg": typo_pkg, |
| 238 | "typo_score": typo_score, |
| 239 | } |
| 240 | |
| 241 | yield data |
| 242 | |
| 243 | |
| 244 | def check_name(name: str, full_list: bool=False, download_threshold: Optional[int]=None) -> List[str]: |
nothing calls this directly
no test coverage detected