Skip to content

ENH: Respect tags with .postN in pep440-pre style#261

Merged
effigies merged 2 commits intopython-versioneer:masterfrom
nightlark:pep440-pre_no-duplicate-post-segment
Oct 11, 2021
Merged

ENH: Respect tags with .postN in pep440-pre style#261
effigies merged 2 commits intopython-versioneer:masterfrom
nightlark:pep440-pre_no-duplicate-post-segment

Conversation

@nightlark
Copy link
Copy Markdown
Contributor

@nightlark nightlark commented Aug 22, 2021

tl;dr - pep440-pre doesn't check if the closest tag already contains a post release segment, resulting in a version string that PyPI rejects because there are multiple post release segments. The proposed change detects if a post release segment is present in the tag, and makes versioneer create dev releases for the next postN version instead of always post0.


For a number of projects (e.g. cmake, ninja), the main release segment of the version string matches the version number of the tool being packaged, and the post-release segment is used to indicate updates that just change the pip package but not the underlying tool.

Picking a style to use with versioneer that fits the tag/version workflow is tricky because none of the ones that append a +<local version> string can be uploaded to PyPI. The closest match to this versioning scheme is pep440-pre, but because new releases use tags in the form vX.Y.Z.postN, versioneer decides the version will be in the form vX.Y.Z.postN.post0.devN, which PyPI rejects because there are multiple post-release segments.

In addition, if the last release was vX.Y.Z.post0, the next post release would be vX.Y.Z.post1, so versioneer dev versions should be in the form vX.Y.Z.post1.devN. (This has the downside of if the next release won't be a post release -- but that same downside is true of the current implementation of the pep440-pre style.)

I've modified the pep440-pre style to check if a post release segment exists in the tag, and if so to increment the postN part of the rendered version to the appropriate value for the "next" post release. I think this handles the cases described above better than the existing pep440-pre implementation without breaking backwards compatibility. The one downside with what I have right now is it expects that tag to be the "normalized" form of the tag in that it doesn't handle synonyms like rev, r, or the alternative -, _, no segment separator, or - only variations of specifying a post release.

Any thoughts on making these changes to the existing style, or adding a new pep440-pre-noduplicatepost style? I think there are a few other of the pep440 styles that could also be updated to better handle a closest version tag that already includes pre/post/dev release segments.

Comment thread src/render.py Outdated
post-release version number (or -1 if no post-release segment is present).
"""
vc = str.split(ver, ".post")
return vc[0], int(vc[1] or 0) if len(vc) == 2 else -1
Copy link
Copy Markdown
Contributor Author

@nightlark nightlark Aug 22, 2021

Choose a reason for hiding this comment

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

It might be better if the else case returned None instead.

@nightlark
Copy link
Copy Markdown
Contributor Author

nightlark commented Aug 27, 2021

@effigies is there anyone in particular I should ping to get their thoughts on this, desired changes, etc?

It would be nice to get the versions rendered with pep440-pre a bit closer to conforming to the PEP440 standard when the closest tag already has some release segments that are currently just assumed to never be present.

@effigies
Copy link
Copy Markdown
Contributor

effigies commented Aug 31, 2021

I think I'm the closest person right now. I'll try to have a look soonish.

@nightlark
Copy link
Copy Markdown
Contributor Author

nightlark commented Sep 9, 2021

There are a few packages I've been holding off sending PRs to that would use this modified version of the renderer -- if this PR seems like it is moving somewhere soon then I'll continue to hold off, since I'd much rather the changes get upstreamed to versioneer than maintaining my own fork.

(Of course if there's no chance it will get merged, I'd rather just hear sooner than later so I can figure out what alternative to go with.)

Copy link
Copy Markdown
Contributor

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Thanks for the bump. This looks entirely reasonable to me. I don't have a strong opinion about the -1 vs None issue. If you would prefer to change it, feel free. Otherwise I think this is good to merge.

@nightlark
Copy link
Copy Markdown
Contributor Author

Thanks! I'll update the docs to mention the new behavior. I think I'll make the None change too, since when looking at it again I realized that if the distance from the last tag is 0 it shouldn't increment the post release segment.

Comment thread src/render.py Outdated
@effigies
Copy link
Copy Markdown
Contributor

LGTM. Happy to merge if you're ready.

@effigies effigies changed the title Prevent multiple post-release segments in pep440-pre style ENH: Respect tags with .postN in pep440-pre style Oct 11, 2021
@effigies effigies merged commit afbe914 into python-versioneer:master Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants