|
23 | 23 | from pip._vendor.packaging.specifiers import SpecifierSet |
24 | 24 | from pip._vendor.packaging.version import Version |
25 | 25 |
|
26 | | -from pip._internal.models.direct_url import ArchiveInfo, DirInfo, VcsInfo |
27 | | -from pip._internal.models.link import Link |
28 | | -from pip._internal.req.req_install import InstallRequirement |
29 | | -from pip._internal.utils.urls import url_to_path |
30 | | - |
31 | 26 | if TYPE_CHECKING: |
32 | 27 | if sys.version_info >= (3, 11): |
33 | 28 | from typing import Self |
@@ -381,97 +376,6 @@ def from_dict(cls, d: Dict[str, Any]) -> "Self": |
381 | 376 | ) |
382 | 377 | return package |
383 | 378 |
|
384 | | - @classmethod |
385 | | - def from_install_requirement( |
386 | | - cls, ireq: InstallRequirement, base_dir: Path |
387 | | - ) -> "Self": |
388 | | - base_dir = base_dir.resolve() |
389 | | - dist = ireq.get_dist() |
390 | | - download_info = ireq.download_info |
391 | | - assert download_info |
392 | | - package_version = None |
393 | | - package_vcs = None |
394 | | - package_directory = None |
395 | | - package_archive = None |
396 | | - package_sdist = None |
397 | | - package_wheels = None |
398 | | - if ireq.is_direct: |
399 | | - if isinstance(download_info.info, VcsInfo): |
400 | | - package_vcs = PackageVcs( |
401 | | - type=download_info.info.vcs, |
402 | | - url=download_info.url, |
403 | | - path=None, |
404 | | - requested_revision=download_info.info.requested_revision, |
405 | | - commit_id=download_info.info.commit_id, |
406 | | - subdirectory=download_info.subdirectory, |
407 | | - ) |
408 | | - elif isinstance(download_info.info, DirInfo): |
409 | | - package_directory = PackageDirectory( |
410 | | - path=( |
411 | | - Path(url_to_path(download_info.url)) |
412 | | - .resolve() |
413 | | - .relative_to(base_dir) |
414 | | - .as_posix() |
415 | | - ), |
416 | | - editable=( |
417 | | - download_info.info.editable |
418 | | - if download_info.info.editable |
419 | | - else None |
420 | | - ), |
421 | | - subdirectory=download_info.subdirectory, |
422 | | - ) |
423 | | - elif isinstance(download_info.info, ArchiveInfo): |
424 | | - if not download_info.info.hashes: |
425 | | - raise NotImplementedError() |
426 | | - package_archive = PackageArchive( |
427 | | - url=download_info.url, |
428 | | - path=None, |
429 | | - size=None, # not supported |
430 | | - hashes=download_info.info.hashes, |
431 | | - subdirectory=download_info.subdirectory, |
432 | | - ) |
433 | | - else: |
434 | | - # should never happen |
435 | | - raise NotImplementedError() |
436 | | - else: |
437 | | - package_version = dist.version |
438 | | - if isinstance(download_info.info, ArchiveInfo): |
439 | | - if not download_info.info.hashes: |
440 | | - raise NotImplementedError() |
441 | | - link = Link(download_info.url) |
442 | | - if link.is_wheel: |
443 | | - package_wheels = [ |
444 | | - PackageWheel( |
445 | | - name=link.filename, |
446 | | - url=download_info.url, |
447 | | - path=None, |
448 | | - size=None, # not supported |
449 | | - hashes=download_info.info.hashes, |
450 | | - ) |
451 | | - ] |
452 | | - else: |
453 | | - package_sdist = PackageSdist( |
454 | | - name=link.filename, |
455 | | - url=download_info.url, |
456 | | - path=None, |
457 | | - size=None, # not supported |
458 | | - hashes=download_info.info.hashes, |
459 | | - ) |
460 | | - else: |
461 | | - # should never happen |
462 | | - raise NotImplementedError() |
463 | | - return cls( |
464 | | - name=dist.canonical_name, |
465 | | - version=package_version, |
466 | | - marker=None, # not supported |
467 | | - requires_python=None, # not supported |
468 | | - vcs=package_vcs, |
469 | | - directory=package_directory, |
470 | | - archive=package_archive, |
471 | | - sdist=package_sdist, |
472 | | - wheels=package_wheels, |
473 | | - ) |
474 | | - |
475 | 379 |
|
476 | 380 | @dataclass |
477 | 381 | class Pylock: |
@@ -509,21 +413,3 @@ def from_dict(cls, d: Dict[str, Any]) -> "Self": |
509 | 413 | requires_python=_get_as(d, str, SpecifierSet, "requires-python"), |
510 | 414 | packages=_get_required_list_of_objects(d, Package, "packages"), |
511 | 415 | ) |
512 | | - |
513 | | - @classmethod |
514 | | - def from_install_requirements( |
515 | | - cls, install_requirements: Iterable[InstallRequirement], base_dir: Path |
516 | | - ) -> "Self": |
517 | | - return cls( |
518 | | - lock_version=Version("1.0"), |
519 | | - environments=None, # not supported |
520 | | - requires_python=None, # not supported |
521 | | - created_by="pip", |
522 | | - packages=sorted( |
523 | | - ( |
524 | | - Package.from_install_requirement(ireq, base_dir) |
525 | | - for ireq in install_requirements |
526 | | - ), |
527 | | - key=lambda p: p.name, |
528 | | - ), |
529 | | - ) |
0 commit comments