Skip to content

Add __version_info__ as a tuple-based version identifier #18869

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

Merged
merged 1 commit into from
Jul 20, 2021

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Nov 1, 2020

PR Summary

Closes #18312. See there for general background and discussion.

This implementation truncates the version to (major, minor, micro). GitHub post-tag number and commit are left out: The commit ID must be left out because it is not ordered, and the tuple is specifically intended to be compared. One could leave the post-tag number. However, this is non-standard. Moreover git post-tag numbers only appear in development versions and and I doubt there's a use-case for checking only that. So let's keep it simple and to the (major, minor, micro) tuple.

One can always expand later with additional parameters or switching to a namedtuple. if there is need.

@timhoffm timhoffm force-pushed the version_info branch 2 times, most recently from f60a16c to 6827ff8 Compare November 1, 2020 23:36
@timhoffm timhoffm added this to the v3.4.0 milestone Nov 1, 2020
@timhoffm timhoffm force-pushed the version_info branch 4 times, most recently from 15c8a0e to a916604 Compare November 2, 2020 20:37
@dopplershift
Copy link
Contributor

Outcome of today's call was that this should go ahead and mimic all the fields in sys.version_info to handle our release candidates.

@timhoffm
Copy link
Member Author

Waiting for #18971 before moving on.

@timhoffm timhoffm marked this pull request as draft November 18, 2020 21:42
@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 27, 2021
@timhoffm
Copy link
Member Author

timhoffm commented May 25, 2021

Waiting on #19419 (in particular #19419 (comment)).

Notes to self:

  • setuptools_scm uses packaging.version.parse https://github.com/pypa/setuptools_scm/pull/558/files but only in dump_version() (and this only creates a plain tuple, not a named tuple like sys.version_info). There seems no get_version() equivalent for tuples, i.e. some programmatic get_version_info() is missing. We'll have to implement this ourselves.
  • I don't think we can detect the releaselevel ('alpha', 'beta', 'candidate', or 'final'), so let's stick with 'final' if there is no dev/pre/post part and choose one of 'alpha', 'beta', 'candiate' for all others.

@timhoffm timhoffm force-pushed the version_info branch 2 times, most recently from 4310f23 to f564e4a Compare July 8, 2021 21:21
@timhoffm timhoffm marked this pull request as ready for review July 8, 2021 21:23
@jklymak
Copy link
Member

jklymak commented Jul 8, 2021

Does this need a what's new or API note?

@timhoffm
Copy link
Member Author

timhoffm commented Jul 9, 2021

Yes, I think "What's new" would be appropriate. I noticed that the switch to release-branch-semver does not have one either. Will do a combined one.

@timhoffm
Copy link
Member Author

timhoffm commented Jul 9, 2021

"What's new" added.

This is a named tuple modelled after sys.version_info.
__version__ = _get_version()
global __version__info__ # cache it.
__version_info__ = _parse_to_version_info(__version__)
return __version__ if name == "__version__" else __version_info__
Copy link
Contributor

Choose a reason for hiding this comment

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

I would do return globals()[name] as that seems more robust if we ever want to add more entries to the module-level __getattr__, but I'm not going to block over that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll leave this as is because explicit is better and still simple enough for two cases. We can (and should) switch to your proposal if we add more entries.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Please address my comment above or explicitly reject it; then this can be self-merged.

@timhoffm timhoffm merged commit c328fbc into matplotlib:master Jul 20, 2021
@timhoffm timhoffm deleted the version_info branch July 20, 2021 21:47
@ericpre ericpre mentioned this pull request Aug 25, 2021
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add easily comparable version info to toplevel
5 participants