Skip to content

Commit 605f3b3

Browse files
committed
lock: use relativate paths for directories
1 parent deb2713 commit 605f3b3

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, Optional, Tuple
45

56
from pip._vendor import tomli_w
@@ -79,7 +80,7 @@ class Package:
7980
# (not supported) tool: Optional[Dict[str, Any]]
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
dist = ireq.get_dist()
8485
download_info = ireq.download_info
8586
assert download_info
@@ -96,7 +97,11 @@ def from_install_requirement(cls, ireq: InstallRequirement) -> Self:
9697
)
9798
elif isinstance(download_info.info, DirInfo):
9899
package.directory = PackageDirectory(
99-
path=url_to_path(download_info.url),
100+
path=(
101+
Path(url_to_path(download_info.url))
102+
.relative_to(base_dir, walk_up=True)
103+
.as_posix()
104+
),
100105
editable=(
101106
download_info.info.editable
102107
if download_info.info.editable
@@ -155,12 +160,12 @@ def as_toml(self) -> str:
155160

156161
@classmethod
157162
def from_install_requirements(
158-
cls, install_requirements: Iterable[InstallRequirement]
163+
cls, install_requirements: Iterable[InstallRequirement], base_dir: Path
159164
) -> Self:
160165
return cls(
161166
packages=sorted(
162167
(
163-
Package.from_install_requirement(ireq)
168+
Package.from_install_requirement(ireq, base_dir)
164169
for ireq in install_requirements
165170
),
166171
key=lambda p: p.name,

0 commit comments

Comments
 (0)