Skip to content

Commit

Permalink
MUCH faster version check
Browse files Browse the repository at this point in the history
  • Loading branch information
dwreeves committed Apr 24, 2024
1 parent 7c23aa6 commit 61b33e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/rich_click/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
customisation required.
"""

__version__ = "1.8.0dev6"
__version__ = "1.8.0dev7"

# Import the entire click API here.
# We need to manually import these instead of `from click import *` to force
Expand Down
26 changes: 14 additions & 12 deletions src/rich_click/_compat_click.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
try:
from importlib import metadata # type: ignore[import,unused-ignore]
except ImportError:
# Python < 3.8
import importlib_metadata as metadata # type: ignore[no-redef,import-not-found,unused-ignore]

import click

click_version = metadata.version("click")
_major = int(click_version.split(".")[0])
_minor = int(click_version.split(".")[1])

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

CLICK_IS_BEFORE_VERSION_8X = _major < 8
CLICK_IS_BEFORE_VERSION_9X = _major < 9
CLICK_IS_VERSION_80 = _major == 8 and _minor == 0
CLICK_IS_BEFORE_VERSION_8X = _major < 8
CLICK_IS_BEFORE_VERSION_9X = _major < 9
CLICK_IS_VERSION_80 = _major == 8 and _minor == 0


if CLICK_IS_BEFORE_VERSION_8X:
Expand Down

0 comments on commit 61b33e5

Please sign in to comment.