Skip to content

Instantly share code, notes, and snippets.

@tony
Created September 5, 2022 16:47
Embed
What would you like to do?
sphinx.ext.doctest issue with is_allowed_version
from packaging.specifiers import InvalidSpecifier, SpecifierSet
from packaging.version import Version
def is_allowed_version(spec: str, version: str) -> bool:
"""Check `spec` satisfies `version` or not.
This obeys PEP-440 specifiers:
https://peps.python.org/pep-0440/#version-specifiers
Some examples:
>>> is_allowed_version('3.3', '<=3.5')
True
>>> is_allowed_version('3.3', '<=3.2')
False
>>> is_allowed_version('3.3', '>3.2, <4.0')
True
"""
return Version(version) in SpecifierSet(spec)
Run `python -m doctest example.py`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment