Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally use resolved references in to_pep_508 #603

Merged
merged 5 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ def base_pep_508_name(self) -> str:

return requirement

@property
def base_pep_508_name_resolved(self) -> str:
return self.base_pep_508_name
radoering marked this conversation as resolved.
Show resolved Hide resolved

def allows_prereleases(self) -> bool:
return self._allows_prereleases

Expand All @@ -279,10 +283,13 @@ def is_directory(self) -> bool:
def is_url(self) -> bool:
return False

def to_pep_508(self, with_extras: bool = True) -> str:
def to_pep_508(self, with_extras: bool = True, *, resolved: bool = False) -> str:
from poetry.core.packages.utils.utils import convert_markers

requirement = self.base_pep_508_name
if resolved:
requirement = self.base_pep_508_name_resolved
else:
requirement = self.base_pep_508_name
radoering marked this conversation as resolved.
Show resolved Hide resolved

markers = []
has_extras = False
Expand Down
17 changes: 14 additions & 3 deletions src/poetry/core/packages/vcs_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ def pretty_constraint(self) -> str:

return f"{what} {version}"

@property
def base_pep_508_name(self) -> str:
def _base_pep_508_name(self, *, resolved: bool = False) -> str:
from poetry.core.vcs import git

requirement = self.pretty_name
Expand All @@ -117,13 +116,25 @@ def base_pep_508_name(self) -> str:
else:
requirement += f" @ {self._vcs}+ssh://{parsed_url.format()}"

if self.reference:
if resolved and self.source_resolved_reference:
requirement += f"@{self.source_resolved_reference}"
elif self.reference:
requirement += f"@{self.reference}"

if self._directory:
requirement += f"#subdirectory={self._directory}"

return requirement

@property
def base_pep_508_name(self) -> str:
requirement = self._base_pep_508_name()
return requirement

@property
def base_pep_508_name_resolved(self) -> str:
requirement = self._base_pep_508_name(resolved=True)
return requirement

def is_vcs(self) -> bool:
return True
1 change: 1 addition & 0 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def test_to_pep_508_with_patch_python_version(
expected = f"Django (>=1.23,<2.0) ; {marker}"

assert dependency.to_pep_508() == expected
assert dependency.to_pep_508(resolved=True) == expected
assert str(dependency.marker) == marker


Expand Down
53 changes: 53 additions & 0 deletions tests/packages/test_vcs_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
{"extras": ["foo", "bar"]},
"poetry[bar,foo] @ git+https://github.com/python-poetry/poetry.git",
),
(
{"extras": ["foo", "bar"], "branch": "main"},
"poetry[bar,foo] @ git+https://github.com/python-poetry/poetry.git@main",
),
(
{"branch": "main"},
"poetry @ git+https://github.com/python-poetry/poetry.git@main",
Expand Down Expand Up @@ -54,6 +58,55 @@ def test_to_pep_508(kwargs: dict[str, Any], expected: str) -> None:
assert dependency.to_pep_508() == expected


@pytest.mark.parametrize(
"kwargs, expected",
[
({}, "poetry @ git+https://github.com/python-poetry/poetry.git"),
(
{"extras": ["foo"]},
"poetry[foo] @ git+https://github.com/python-poetry/poetry.git",
),
(
{"extras": ["foo", "bar"]},
"poetry[bar,foo] @ git+https://github.com/python-poetry/poetry.git",
),
radoering marked this conversation as resolved.
Show resolved Hide resolved
(
{"extras": ["foo", "bar"], "branch": "main", "resolved_rev": "aaaa"},
"poetry[bar,foo] @ git+https://github.com/python-poetry/poetry.git@aaaa",
),
(
{"branch": "main", "resolved_rev": "aaaa"},
"poetry @ git+https://github.com/python-poetry/poetry.git@aaaa",
),
(
{"tag": "1.0", "resolved_rev": "aaaa"},
"poetry @ git+https://github.com/python-poetry/poetry.git@aaaa",
),
(
{"rev": "12345", "resolved_rev": "aaaa"},
"poetry @ git+https://github.com/python-poetry/poetry.git@aaaa",
),
(
{"directory": "sub"},
"poetry @ git+https://github.com/python-poetry/poetry.git#subdirectory=sub",
),
(
{"branch": "main", "directory": "sub", "resolved_rev": "aaaa"},
(
"poetry @ git+https://github.com/python-poetry/poetry.git"
"@aaaa#subdirectory=sub"
),
),
],
)
def test_to_pep_508_resolved(kwargs: dict[str, Any], expected: str) -> None:
dependency = VCSDependency(
"poetry", "git", "https://github.com/python-poetry/poetry.git", **kwargs
)

assert dependency.to_pep_508(resolved=True) == expected


def test_to_pep_508_ssh() -> None:
dependency = VCSDependency("poetry", "git", "git@github.com:sdispater/poetry.git")

Expand Down