1
1
import dataclasses
2
2
from dataclasses import dataclass
3
+ from pathlib import Path
3
4
from typing import Any , Dict , Iterable , List , Literal , Optional , Tuple
4
5
5
6
from pip ._vendor import tomli_w
@@ -79,7 +80,7 @@ class Package:
79
80
# (not supported) tool
80
81
81
82
@classmethod
82
- def from_install_requirement (cls , ireq : InstallRequirement ) -> Self :
83
+ def from_install_requirement (cls , ireq : InstallRequirement , base_dir : Path ) -> Self :
83
84
assert ireq .name
84
85
dist = ireq .get_dist ()
85
86
download_info = ireq .download_info
@@ -97,7 +98,11 @@ def from_install_requirement(cls, ireq: InstallRequirement) -> Self:
97
98
)
98
99
elif isinstance (download_info .info , DirInfo ):
99
100
package .directory = PackageDirectory (
100
- path = url_to_path (download_info .url ),
101
+ path = (
102
+ Path (url_to_path (download_info .url ))
103
+ .relative_to (base_dir , walk_up = True )
104
+ .as_posix ()
105
+ ),
101
106
editable = (
102
107
download_info .info .editable
103
108
if download_info .info .editable
@@ -156,12 +161,12 @@ def as_toml(self) -> str:
156
161
157
162
@classmethod
158
163
def from_install_requirements (
159
- cls , install_requirements : Iterable [InstallRequirement ]
164
+ cls , install_requirements : Iterable [InstallRequirement ], base_dir : Path
160
165
) -> Self :
161
166
return cls (
162
167
packages = sorted (
163
168
(
164
- Package .from_install_requirement (ireq )
169
+ Package .from_install_requirement (ireq , base_dir )
165
170
for ireq in install_requirements
166
171
),
167
172
key = lambda p : p .name ,
0 commit comments