Skip to content

Commit

Permalink
Extract __version__ lookup to _version helper
Browse files Browse the repository at this point in the history
  • Loading branch information
EliahKagan committed Apr 1, 2024
1 parent e8535b9 commit 6734950
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@
raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc


def _version() -> str:
if sys.version_info >= (3, 8):
from importlib.metadata import version
else:
from importlib_metadata import version

return version("GitPython")


def _warned_import(message: str, fullname: str) -> "ModuleType":
import importlib

Expand All @@ -195,12 +204,7 @@ def _warned_import(message: str, fullname: str) -> "ModuleType":

def _getattr(name: str) -> Any:
if name == "__version__":
if sys.version_info >= (3, 8):
from importlib.metadata import version
else:
from importlib_metadata import version

return version("GitPython")
return _version()

if name == "util":
return _warned_import(
Expand Down

0 comments on commit 6734950

Please sign in to comment.