Skip to content

Commit

Permalink
Conditional __version__
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw committed Aug 13, 2023
1 parent 55aedb4 commit 7f68675
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions fastapi_restful/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import importlib.metadata
import os
import warnings

from .cbv_base import Api, Resource, set_responses, take_init_parameters

try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError as e:
warnings.warn(f"Could not determine version of {__name__}", stacklevel=1)
warnings.warn(str(e), stacklevel=1)
__version__ = "unknown"
if os.python.version < "3.8":
import pkg_resources
try:
__version__ = pkg_resources.get_distribution(__name__).version
except pkg_resources.DistributionNotFound as e:
warnings.warn(f"Could not determine version of {__name__}", stacklevel=1)
warnings.warn(str(e), stacklevel=1)
__version__ = "unknown"
else:
import importlib.metadata
try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError as e:
warnings.warn(f"Could not determine version of {__name__}", stacklevel=1)
warnings.warn(str(e), stacklevel=1)
__version__ = "unknown"


__all__ = [
Expand Down

0 comments on commit 7f68675

Please sign in to comment.