17
17
from cleo .ui .progress_indicator import ProgressIndicator
18
18
from poetry .core .constraints .version import EmptyConstraint
19
19
from poetry .core .constraints .version import Version
20
+ from poetry .core .packages .utils .link import Link
20
21
from poetry .core .packages .utils .utils import get_python_constraint_from_marker
21
22
from poetry .core .version .markers import AnyMarker
22
23
from poetry .core .version .markers import EmptyMarker
56
57
from poetry .core .version .markers import BaseMarker
57
58
58
59
from poetry .repositories import RepositoryPool
60
+ from poetry .utils .cache import ArtifactCache
59
61
from poetry .utils .env import Env
60
62
61
63
@@ -439,7 +441,7 @@ def get_package_from_directory(cls, directory: Path) -> Package:
439
441
return PackageInfo .from_directory (path = directory ).to_package (root_dir = directory )
440
442
441
443
def _search_for_url (self , dependency : URLDependency ) -> Package :
442
- package = self .get_package_from_url (dependency .url )
444
+ package = self .get_package_from_url (dependency .url , self . _pool . artifact_cache )
443
445
444
446
self .validate_package_for_dependency (dependency = dependency , package = package )
445
447
@@ -454,15 +456,33 @@ def _search_for_url(self, dependency: URLDependency) -> Package:
454
456
return package
455
457
456
458
@classmethod
457
- def get_package_from_url (cls , url : str ) -> Package :
459
+ def get_package_from_url (
460
+ cls , url : str , artifact_cache : ArtifactCache | None = None
461
+ ) -> Package :
458
462
file_name = os .path .basename (urllib .parse .urlparse (url ).path )
459
- with tempfile .TemporaryDirectory () as temp_dir :
460
- dest = Path (temp_dir ) / file_name
461
- download_file (url , dest )
462
- package = cls .get_package_from_file (dest )
463
+ link = Link (url )
464
+ artifact = (
465
+ artifact_cache .get_cached_archive_for_link (Link (url ), strict = True )
466
+ if artifact_cache
467
+ else None
468
+ )
469
+
470
+ with tempfile .TemporaryDirectory () as tmp_dir :
471
+ if not artifact :
472
+ if artifact_cache :
473
+ artifact = (
474
+ artifact_cache .get_cache_directory_for_link (link ) / file_name
475
+ )
476
+ artifact .parent .mkdir (parents = True , exist_ok = True )
477
+ else :
478
+ artifact = Path (tmp_dir ) / file_name
479
+
480
+ download_file (url , artifact )
481
+
482
+ package = cls .get_package_from_file (artifact )
463
483
464
484
package .files = [
465
- {"file" : file_name , "hash" : "sha256:" + get_file_hash (dest )}
485
+ {"file" : file_name , "hash" : "sha256:" + get_file_hash (artifact )}
466
486
]
467
487
468
488
package ._source_type = "url"
0 commit comments