Skip to content

Commit 14863ae

Browse files
Carreaujonathanslenders
authored andcommitted
Make VERSION tuple numeric.
Note that by being numeric we drop the rc/a/b/dev suffix. I'm also adding the pep440 regular expression to make sure the version number match the spec. The pep 440 spec is a bit annoying with the fact that a/b/rc don't have dots, but .dev do. There are some issues if you don't follow the spec and publish both whl/tgz, as pip will mix-up the values, and think the tgz are actually a more recent version than the whl. It may be fixed in setuptools/pip, but better be safe. Ii did not go the route of setting VERSION and having __version__ be a '.'.join() as setup.py use regex to extract version number. Maye docs/conf.py could also use the same trick as setup.py to avoid having to update the version number in multiple places ? Closes #1707
1 parent 4b4c56d commit 14863ae

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/prompt_toolkit/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@
1313
Probably, to get started, you might also want to have a look at
1414
`prompt_toolkit.shortcuts.prompt`.
1515
"""
16+
import re
17+
18+
# note: this is a bit more lax than the actual pep 440 to allow for a/b/rc/dev without a number
19+
pep440 = re.compile(
20+
r"^([1-9]\d*!)?(0|[1-9]\d*)(\.(0|[1-9]\d*))*((a|b|rc)(0|[1-9]\d*)?)?(\.post(0|[1-9]\d*))?(\.dev(0|[1-9]\d*)?)?$",
21+
re.UNICODE,
22+
)
1623
from .application import Application
1724
from .formatted_text import ANSI, HTML
1825
from .shortcuts import PromptSession, print_formatted_text, prompt
1926

2027
# Don't forget to update in `docs/conf.py`!
2128
__version__ = "3.0.36"
2229

30+
assert pep440.match(__version__)
31+
2332
# Version tuple.
24-
VERSION = tuple(__version__.split("."))
33+
VERSION = tuple(int(v.rstrip("abrc")) for v in __version__.split(".")[:3])
2534

2635

2736
__all__ = [

0 commit comments

Comments
 (0)