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
import tomli_w
@@ -80,7 +81,7 @@ class Package:
80
81
# (not supported) tool
81
82
82
83
@classmethod
83
- def from_install_requirement (cls , ireq : InstallRequirement ) -> Self :
84
+ def from_install_requirement (cls , ireq : InstallRequirement , base_dir : Path ) -> Self :
84
85
assert ireq .name
85
86
dist = ireq .get_dist ()
86
87
download_info = ireq .download_info
@@ -98,7 +99,11 @@ def from_install_requirement(cls, ireq: InstallRequirement) -> Self:
98
99
)
99
100
elif isinstance (download_info .info , DirInfo ):
100
101
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
+ ),
102
107
editable = (
103
108
download_info .info .editable
104
109
if download_info .info .editable
@@ -157,12 +162,12 @@ def as_toml(self) -> str:
157
162
158
163
@classmethod
159
164
def from_install_requirements (
160
- cls , install_requirements : Iterable [InstallRequirement ]
165
+ cls , install_requirements : Iterable [InstallRequirement ], base_dir : Path
161
166
) -> Self :
162
167
return cls (
163
168
packages = sorted (
164
169
(
165
- Package .from_install_requirement (ireq )
170
+ Package .from_install_requirement (ireq , base_dir )
166
171
for ireq in install_requirements
167
172
),
168
173
key = lambda p : p .name ,
0 commit comments