Skip to content

Commit 4b4f84a

Browse files
committed
lock: use relativate paths for directories
1 parent 33e5712 commit 4b4f84a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/pip/_internal/commands/lock.py

Lines changed: 2 additions & 1 deletion
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

src/pip/_internal/models/pylock.py

Lines changed: 9 additions & 4 deletions
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
from pip._vendor import tomli_w
@@ -79,7 +80,7 @@ class Package:
7980
# (not supported) tool
8081

8182
@classmethod
82-
def from_install_requirement(cls, ireq: InstallRequirement) -> Self:
83+
def from_install_requirement(cls, ireq: InstallRequirement, base_dir: Path) -> Self:
8384
assert ireq.name
8485
dist = ireq.get_dist()
8586
download_info = ireq.download_info
@@ -97,7 +98,11 @@ def from_install_requirement(cls, ireq: InstallRequirement) -> Self:
9798
)
9899
elif isinstance(download_info.info, DirInfo):
99100
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+
),
101106
editable=(
102107
download_info.info.editable
103108
if download_info.info.editable
@@ -156,12 +161,12 @@ def as_toml(self) -> str:
156161

157162
@classmethod
158163
def from_install_requirements(
159-
cls, install_requirements: Iterable[InstallRequirement]
164+
cls, install_requirements: Iterable[InstallRequirement], base_dir: Path
160165
) -> Self:
161166
return cls(
162167
packages=sorted(
163168
(
164-
Package.from_install_requirement(ireq)
169+
Package.from_install_requirement(ireq, base_dir)
165170
for ireq in install_requirements
166171
),
167172
key=lambda p: p.name,

0 commit comments

Comments
 (0)