Skip to content

Commit 61b33e5

Browse files
committed
MUCH faster version check
1 parent 7c23aa6 commit 61b33e5

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/rich_click/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
customisation required.
77
"""
88

9-
__version__ = "1.8.0dev6"
9+
__version__ = "1.8.0dev7"
1010

1111
# Import the entire click API here.
1212
# We need to manually import these instead of `from click import *` to force

src/rich_click/_compat_click.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
try:
2-
from importlib import metadata # type: ignore[import,unused-ignore]
3-
except ImportError:
4-
# Python < 3.8
5-
import importlib_metadata as metadata # type: ignore[no-redef,import-not-found,unused-ignore]
6-
1+
import click
72

8-
click_version = metadata.version("click")
9-
_major = int(click_version.split(".")[0])
10-
_minor = int(click_version.split(".")[1])
113

4+
try:
5+
click_version = click.__version__
6+
except NameError:
7+
# Click 9+ deprecated __version__, so all these checks must necessarily be False if __version__ doesn't exist.
8+
CLICK_IS_BEFORE_VERSION_8X = False
9+
CLICK_IS_BEFORE_VERSION_9X = False
10+
CLICK_IS_VERSION_80 = False
11+
else:
12+
_major = int(click_version.split(".")[0])
13+
_minor = int(click_version.split(".")[1])
1214

13-
CLICK_IS_BEFORE_VERSION_8X = _major < 8
14-
CLICK_IS_BEFORE_VERSION_9X = _major < 9
15-
CLICK_IS_VERSION_80 = _major == 8 and _minor == 0
15+
CLICK_IS_BEFORE_VERSION_8X = _major < 8
16+
CLICK_IS_BEFORE_VERSION_9X = _major < 9
17+
CLICK_IS_VERSION_80 = _major == 8 and _minor == 0
1618

1719

1820
if CLICK_IS_BEFORE_VERSION_8X:

0 commit comments

Comments
 (0)