|
8 | 8 | NamedTuple, |
9 | 9 | Optional, |
10 | 10 | Set, |
11 | | - Tuple, |
12 | 11 | Type, |
13 | 12 | ) |
14 | 13 |
|
|
27 | 26 | from ..package import ( |
28 | 27 | GitSource, |
29 | 28 | LocalSource, |
| 29 | + NamedGitSource, |
30 | 30 | Package, |
31 | 31 | PackageSource, |
32 | 32 | PackageURLSource, |
@@ -85,12 +85,11 @@ def _process_packages_v1( |
85 | 85 | integrity = Integrity.parse(info['integrity']) |
86 | 86 |
|
87 | 87 | if 'resolved' in info: |
88 | | - if info['resolved'].startswith('git+'): |
89 | | - source = self.parse_git_source(info['resolved']) |
| 88 | + resolved = info['resolved'] |
| 89 | + if resolved.startswith('git+'): |
| 90 | + source = self.parse_git_source(resolved) |
90 | 91 | else: |
91 | | - source = ResolvedSource( |
92 | | - resolved=info['resolved'], integrity=integrity |
93 | | - ) |
| 92 | + source = ResolvedSource(resolved=resolved, integrity=integrity) |
94 | 93 | elif version_url.scheme in {'http', 'https'}: |
95 | 94 | source = PackageURLSource(resolved=version, integrity=integrity) |
96 | 95 | else: |
@@ -204,9 +203,10 @@ def __init__( |
204 | 203 | ] = {} |
205 | 204 | self.index_entries: Dict[Path, str] = {} |
206 | 205 | self.all_lockfiles: Set[Path] = set() |
207 | | - # Mapping of lockfiles to a dict of the Git source target paths and GitSource objects. |
| 206 | + # Mapping of lockfiles to a dict of the Git source target paths and |
| 207 | + # NamedGitSource objects (package name + GitSource) |
208 | 208 | self.git_sources: DefaultDict[ |
209 | | - Path, Dict[Path, Tuple[str, GitSource]] |
| 209 | + Path, Dict[Path, NamedGitSource] |
210 | 210 | ] = collections.defaultdict(lambda: {}) |
211 | 211 | # FIXME better pass the same provider object we created in main |
212 | 212 | self.rcfile_provider = NpmRCFileProvider() |
@@ -367,34 +367,36 @@ async def generate_package(self, package: Package) -> None: |
367 | 367 | # Get a unique name to use for the Git repository folder. |
368 | 368 | name = f'{package.name}-{source.commit}' |
369 | 369 | path = self.gen.data_root / 'git-packages' / name |
370 | | - self.git_sources[package.lockfile][path] = (package.name, source) |
| 370 | + self.git_sources[package.lockfile][path] = NamedGitSource( |
| 371 | + package.name, source |
| 372 | + ) |
371 | 373 | self.gen.add_git_source(source.url, source.commit, path) |
372 | 374 |
|
| 375 | + git_suffix = re.compile(r'\.git$') |
373 | 376 | url = urllib.parse.urlparse(source.url) |
374 | | - if url. netloc == '[email protected]' or url. netloc == 'github.com': |
| 377 | + |
| 378 | + if url.hostname == 'github.com': |
375 | 379 | url = url._replace( |
376 | | - netloc='codeload.github.com', path=re.sub('.git$', '', url.path) |
377 | | - ) |
378 | | - tarball_url = url._replace( |
379 | | - path=re.sub('$', f'/tar.gz/{source.commit}', url.path) |
| 380 | + netloc='codeload.github.com', path=git_suffix.sub('', url.path) |
380 | 381 | ) |
| 382 | + tarball_url = url._replace(path=url.path + f'/tar.gz/{source.commit}') |
381 | 383 | index_url = tarball_url.geturl() |
382 | | - elif url. netloc == '[email protected]' or url.netloc == 'gitlab.com': |
| 384 | + elif url.hostname == 'gitlab.com': |
383 | 385 | url = url._replace( |
384 | | - netloc='gitlab.com', path=re.sub('.git$', '', url.path) |
| 386 | + netloc='gitlab.com', path=git_suffix.sub('', url.path) |
385 | 387 | ) |
386 | 388 | tarball_url = url._replace( |
387 | | - path=re.sub( |
388 | | - '$', |
389 | | - f'/-/archive/{source.commit}/{package.name}-{source.commit}.tar.gz', |
390 | | - url.path, |
391 | | - ) |
| 389 | + path=url.path |
| 390 | + + f'/-/archive/{source.commit}/{package.name}-{source.commit}.tar.gz' |
392 | 391 | ) |
393 | 392 | index_url = url._replace( |
394 | | - path=re.sub( |
395 | | - '$', f'/repository/archive.tar.gz?ref={source.commit}', url.path |
396 | | - ) |
| 393 | + path=url.path + f'/repository/archive.tar.gz?ref={source.commit}' |
397 | 394 | ).geturl() |
| 395 | + else: |
| 396 | + raise NotImplementedError( |
| 397 | + f"Don't know how to handle git source with url {url.geturl()}" |
| 398 | + ) |
| 399 | + |
398 | 400 | metadata = await RemoteUrlMetadata.get( |
399 | 401 | tarball_url.geturl(), cachable=True, integrity_algorithm='sha512' |
400 | 402 | ) |
@@ -501,16 +503,23 @@ def _finalize(self) -> None: |
501 | 503 | lockfile_v1 = json.load(fp)['lockfileVersion'] == 1 |
502 | 504 |
|
503 | 505 | if lockfile_v1: |
504 | | - for path, name_source in sources.items(): |
| 506 | + for path, named_git_source in sources.items(): |
505 | 507 | GIT_URL_PREFIX = 'git+' |
506 | | - name, source = name_source |
507 | | - new_version = f'{path}#{source.commit}' |
508 | | - data['package.json'][name] = new_version |
509 | | - data['package-lock.json'][source.original] = new_version |
510 | | - |
511 | | - if source.original.startswith(GIT_URL_PREFIX): |
| 508 | + new_version = f'{path}#{named_git_source.git_source.commit}' |
| 509 | + data['package.json'][ |
| 510 | + named_git_source.package_name |
| 511 | + ] = new_version |
| 512 | + data['package-lock.json'][ |
| 513 | + named_git_source.git_source.original |
| 514 | + ] = new_version |
| 515 | + |
| 516 | + if named_git_source.git_source.original.startswith( |
| 517 | + GIT_URL_PREFIX |
| 518 | + ): |
512 | 519 | data['package-lock.json'][ |
513 | | - source.original[len(GIT_URL_PREFIX) :] |
| 520 | + named_git_source.git_source.original[ |
| 521 | + len(GIT_URL_PREFIX) : |
| 522 | + ] |
514 | 523 | ] = new_version |
515 | 524 |
|
516 | 525 | for filename, script in scripts.items(): |
@@ -547,7 +556,9 @@ def _finalize(self) -> None: |
547 | 556 |
|
548 | 557 | if not self.no_autopatch: |
549 | 558 | # FLATPAK_BUILDER_BUILDDIR isn't defined yet for script sources. |
550 | | - self.gen.add_command(f'FLATPAK_BUILDER_BUILDDIR="$PWD" {patch_all_dest}') |
| 559 | + self.gen.add_command( |
| 560 | + f'FLATPAK_BUILDER_BUILDDIR="$PWD" {patch_all_dest}' |
| 561 | + ) |
551 | 562 |
|
552 | 563 | if self.index_entries: |
553 | 564 | for path, entry in self.index_entries.items(): |
|
0 commit comments