Skip to content

Commit d124afc

Browse files
committed
lock: use relativate paths for directories
1 parent 89a029f commit d124afc

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Diff for: src/pip/_internal/commands/lock.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from optparse import Values
3+
from pathlib import Path
34
from typing import List
45

56
from pip._internal.cache import WheelCache
@@ -131,7 +132,7 @@ def run(self, options: Values, args: List[str]) -> int:
131132
requirement_set = resolver.resolve(reqs, check_supported_wheels=True)
132133

133134
pyproject_lock = Pylock.from_install_requirements(
134-
requirement_set.requirements.values()
135+
requirement_set.requirements.values(), base_dir=Path.cwd()
135136
)
136137
sys.stdout.write(pyproject_lock.as_toml())
137138

Diff for: src/pip/_internal/models/pylock.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import dataclasses
22
from dataclasses import dataclass
3+
from pathlib import Path
34
from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple
45

56
import 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

Comments
 (0)