Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

** Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement! **

Version Handling

<Version('1.0a5')>
<Version('1.0')>
True
0
(1, 0)
('a', 5)
True
False
---------------------------------------------------------------------------
InvalidVersion                            Traceback (most recent call last)
<ipython-input-10-6e617289b19c> in <module>
----> 1 Version("french toast")

/usr/local/lib/python3.8/site-packages/packaging/version.py in __init__(self, version)
    275         match = self._regex.search(version)
    276         if not match:
--> 277             raise InvalidVersion("Invalid version: '{0}'".format(version))
    278 
    279         # Store the parsed out pieces of the version

InvalidVersion: Invalid version: 'french toast'
False
0
True
<SpecifierSet('')>
True
<SpecifierSet('==1.0')>
<SpecifierSet('~=1.0')>
<SpecifierSet('>=1.0')>
<SpecifierSet('>=1.0,~=1.0')>

Combine specifiers.

<SpecifierSet('>=1.0,~=1.0')>

The combination of spec1 (~=1.0) and spec2 (>=1.0) is the same as spec3 (~=1.0,>=1.0).

True

Implicitly combine a string specifier.

<SpecifierSet('!=1.1,>=1.0,~=1.0')>

Create a few versions to check for contains.

<Version('1.0a5')>
<Version('1.0')>

Check a version object to see if it falls within a specifier.

False
True

You can doo the same with a string based version.

True
[<Version('1.0')>, '1.4']

References

packaging