Skip to content

Commit

Permalink
fix to support newer python versions (#385)
Browse files Browse the repository at this point in the history
* fix to support newer python versions

* docstring

---------

Co-authored-by: spicy-sauce <[email protected]>
  • Loading branch information
zalmane and spicy-sauce authored Dec 24, 2024
1 parent 75effdb commit b122234
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cli/src/datayoga/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import jsonschema
from datayoga_core import prometheus, utils
from datayoga_core.connection import Connection
from pkg_resources import DistributionNotFound, get_distribution

from datayoga import cli_helpers

Expand All @@ -34,10 +33,24 @@


def get_dy_distribution() -> str:
"""Get the installed version of datayoga package.
Attempts to retrieve version using importlib.metadata (Python 3.8+),
falling back to pkg_resources for earlier versions. Returns '0.0.0'
if the package is not found.
Returns:
str: The version string of datayoga package, or '0.0.0' if not found.
"""
try:
return get_distribution("datayoga").version
except DistributionNotFound:
return "0.0.0"
from importlib import metadata
return metadata.version("datayoga")
except (ImportError, Exception):
try:
import pkg_resources
return pkg_resources.get_distribution("datayoga").version
except pkg_resources.DistributionNotFound:
return "0.0.0"


@click.group(name="datayoga", help="DataYoga command line tool")
Expand Down

0 comments on commit b122234

Please sign in to comment.