Created
September 5, 2022 16:47
-
-
Save tony/05c66199c003aaf712a39b5dbc103eba to your computer and use it in GitHub Desktop.
Revisions
-
tony created this gist
Sep 5, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ Run `python -m doctest example.py` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ 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)