11import dataclasses
22from dataclasses import dataclass
3+ from pathlib import Path
34from typing import Any , Dict , Iterable , List , Literal , Self , Tuple
45
56import tomli_w
@@ -80,7 +81,7 @@ class Package:
8081 # (not supported) tool
8182
8283 @classmethod
83- def from_install_requirement (cls , ireq : InstallRequirement ) -> Self :
84+ def from_install_requirement (cls , ireq : InstallRequirement , base_dir : Path ) -> Self :
8485 assert ireq .name
8586 dist = ireq .get_dist ()
8687 download_info = ireq .download_info
@@ -98,7 +99,11 @@ def from_install_requirement(cls, ireq: InstallRequirement) -> Self:
9899 )
99100 elif isinstance (download_info .info , DirInfo ):
100101 package .directory = PackageDirectory (
101- path = url_to_path (download_info .url ),
102+ path = (
103+ Path (url_to_path (download_info .url ))
104+ .relative_to (base_dir , walk_up = True )
105+ .as_posix ()
106+ ),
102107 editable = (
103108 download_info .info .editable
104109 if download_info .info .editable
@@ -157,12 +162,12 @@ def as_toml(self) -> str:
157162
158163 @classmethod
159164 def from_install_requirements (
160- cls , install_requirements : Iterable [InstallRequirement ]
165+ cls , install_requirements : Iterable [InstallRequirement ], base_dir : Path
161166 ) -> Self :
162167 return cls (
163168 packages = sorted (
164169 (
165- Package .from_install_requirement (ireq )
170+ Package .from_install_requirement (ireq , base_dir )
166171 for ireq in install_requirements
167172 ),
168173 key = lambda p : p .name ,
0 commit comments