Open kitchoi opened 4 years ago
sounds like https://docs.python.org/3/library/sys.html#sys.version and https://docs.python.org/3/library/sys.html#sys.version_info. Additionally, __version_info__
can be a named tuple (major, minor, micro)
instead of needing to index into the tuple to get information.
Note that sys.version_info
is a tuple of length 5 - where the last two elements represent releaselevel
and serial
. I'm not sure what serial
refers to and I don't see much use for releaselevel
at the moment.
We have had release-candidate releases of Traits - the releaselevel
would be useful for that.
We'd also ideally want the dev
stuff to go into the version_info
somewhere, for development releases.
Having said that, version comparison becomes very messy if you want to include the releaselevel
component, so we probably just stick to using the first 3 entries for version comparison. If we really need to do version comparison right reliably, covering all the various edge cases, the right way is to let pkg_resources
or packaging
handle it rather than try to do it ourselves.
I'd drop the serial
part, though.
The other part of this is that where possible we should do direct tests for the thing we care about rather than using version numbers as a proxy. For example, prefer a try / except ImportError
around a from traitsui.api import ThingThatMightNotBeThere
, rather than a version check.
ETS packages have
__version__
as a string, e.g."4.5.0"
. That is fine and is an expected format.But sometimes we want to use the version information for things like skipping a test for a specific version range (e.g. https://github.com/enthought/pyface/pull/656), then we have to resort to parsing the version string. It is not hard to do, but it would have been easier if a
version_info
or__version_info__
as a tuple of int is provided by the package already along with__version__
.e.g.
A similar topic was discussed a long time ago: https://github.com/enthought/distributed-array-protocol/issues/16