11from pathlib import Path
2- from typing import Iterable
2+ from typing import Iterable , Optional
33
44from pip ._vendor import tomli_w
55from pip ._vendor .packaging .version import Version
2020
2121
2222def _pylock_package_from_install_requirement (
23- ireq : InstallRequirement , base_dir : Path
23+ ireq : InstallRequirement , base_dir : Optional [ Path ]
2424) -> Package :
25- base_dir = base_dir .resolve ()
25+ if base_dir is not None :
26+ base_dir = base_dir .resolve ()
2627 dist = ireq .get_dist ()
2728 download_info = ireq .download_info
2829 assert download_info
@@ -45,10 +46,14 @@ def _pylock_package_from_install_requirement(
4546 elif isinstance (download_info .info , DirInfo ):
4647 package_directory = PackageDirectory (
4748 path = (
48- Path (url_to_path (download_info .url ))
49- .resolve ()
50- .relative_to (base_dir )
51- .as_posix ()
49+ (
50+ Path (url_to_path (download_info .url ))
51+ .resolve ()
52+ .relative_to (base_dir )
53+ .as_posix ()
54+ )
55+ if base_dir is not None
56+ else url_to_path (download_info .url )
5257 ),
5358 editable = (
5459 download_info .info .editable if download_info .info .editable else None
@@ -102,7 +107,7 @@ def _pylock_package_from_install_requirement(
102107
103108
104109def pylock_from_install_requirements (
105- install_requirements : Iterable [InstallRequirement ], base_dir : Path
110+ install_requirements : Iterable [InstallRequirement ], base_dir : Optional [ Path ]
106111) -> Pylock :
107112 return Pylock (
108113 lock_version = Version ("1.0" ),
0 commit comments