Skip to content

Comments

Fix python version parsing for deadsnakes python versions#7462

Closed
GeorgeSaussy wants to merge 2 commits intopython-poetry:mainfrom
GeorgeSaussy:master
Closed

Fix python version parsing for deadsnakes python versions#7462
GeorgeSaussy wants to merge 2 commits intopython-poetry:mainfrom
GeorgeSaussy:master

Conversation

@GeorgeSaussy
Copy link

This PR will allows poetry to a single trailing "+" character at the end of a PEP 440 compatible Python version string. This will allow Poetry to handle the nightly builds from CPython.

Note: The version string must be either exactly compatible with PEP 440 or it must be compatible except for a trailing "+" character while also not having a local version segment.

Resolves: #233

Comment on lines +1691 to +1701
primary_version_regex = "\\d+\\.([a-zA-Z\\d]+(\\.[a-zA-Z\\d]+)*)"
local_segment_regex = "(\\+([a-zA-Z\\d]+(\\.[a-zA-Z\\d]+)*)?)?$"
pep_440_and_deadsnakes_regex = f"^{primary_version_regex}{local_segment_regex}$"
match = re.compile(pep_440_and_deadsnakes_regex).match(
platform.python_version()
)
if match is None:
raise ValueError("Python version must be PEP 440 compatible.")
clean_python_version = match.group()
clean_python_version = clean_python_version.rstrip("+")

Copy link
Member

@radoering radoering Feb 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That feels a little over the top to me. I'd keep it simple and just strip the trailing plus. Afterwards, validation can be done via poetry.core.constraints.version.Version.parse() instead of the regexes.

I'm a bit torn if it's even necessary to validate the version here, since we parse it later anyway and already fail with a quite good message as can be seen in #6925 (comment). Of course, the message could be improved to say that the invalid version is the python version.

@lazka
Copy link
Contributor

lazka commented May 31, 2023

drive by comment: This makes it sound like it is specific to deadsnakes, but it's the normal version scheme used for Python built from git, and not deadsnakes specific.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't use private repository in poetry add

3 participants