Skip to content

Instantly share code, notes, and snippets.

@tony
Created September 5, 2022 16:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tony/05c66199c003aaf712a39b5dbc103eba to your computer and use it in GitHub Desktop.
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