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

Clarify version split/join usage #725

Merged
merged 1 commit into from
Oct 3, 2023
Merged
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
25 changes: 15 additions & 10 deletions src/packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,17 @@ def filter(


def _version_split(version: str) -> List[str]:
result: List[str] = []
"""Split version into components.

epoch, sep, rest = version.rpartition("!")
The split components are intended for version comparison. The logic does
not attempt to retain the original version string, so joining the
components back with :func:`_version_join` may not produce the original
version string.
"""
result: List[str] = []

if sep:
result.append(epoch)
else:
result.append("0")
epoch, _, rest = version.rpartition("!")
result.append(epoch or "0")

for item in rest.split("."):
match = _prefix_regex.search(item)
Expand All @@ -663,12 +666,14 @@ def _version_split(version: str) -> List[str]:


def _version_join(components: List[str]) -> str:
# This function only works with numeric components.
assert all(c.isdigit() for c in components)
"""Join split version components into a version string.

This function assumes the input came from :func:`_version_split`, where the
first component must be the epoch (either empty or numeric), and all other
components numeric.
"""
epoch, *rest = components

return epoch + "!" + ".".join(rest)
return f"{epoch}!{'.'.join(rest)}"


def _is_not_suffix(segment: str) -> bool:
Expand Down