Skip to content

Commit

Permalink
Merge branch 'master' into feature/#173-client-name
Browse files Browse the repository at this point in the history
  • Loading branch information
erichare authored Feb 2, 2024
2 parents 5f70276 + 49998ab commit 469d098
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
39 changes: 23 additions & 16 deletions astrapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,35 @@

import toml
import os
import importlib.metadata

from typing import Any


def get_version() -> Any:
# Get the path to the pyproject.toml file
dir_path = os.path.dirname(os.path.realpath(__file__))
pyproject_path = os.path.join(dir_path, "..", "pyproject.toml")

# Read the pyproject.toml file and get the version from the poetry section
try:
with open(pyproject_path, encoding="utf-8") as pyproject:
# Load the pyproject.toml file as a dictionary
file_contents = pyproject.read()
pyproject_data = toml.loads(file_contents)

# Return the version from the poetry section
return pyproject_data["tool"]["poetry"]["version"]

# If the pyproject.toml file does not exist or the version is not found, return unknown
except (FileNotFoundError, KeyError):
return "unknown"
# Poetry will create a __version__ attribute in the package's __init__.py file
return importlib.metadata.version(__package__)

# If the package is not installed, we can still get the version from the pyproject.toml file
except importlib.metadata.PackageNotFoundError:
# Get the path to the pyproject.toml file
dir_path = os.path.dirname(os.path.realpath(__file__))
pyproject_path = os.path.join(dir_path, "..", "pyproject.toml")

# Read the pyproject.toml file and get the version from the poetry section
try:
with open(pyproject_path, encoding="utf-8") as pyproject:
# Load the pyproject.toml file as a dictionary
file_contents = pyproject.read()
pyproject_data = toml.loads(file_contents)

# Return the version from the poetry section
return pyproject_data["tool"]["poetry"]["version"]

# If the pyproject.toml file does not exist or the version is not found, return unknown
except (FileNotFoundError, KeyError):
return "unknown"


__version__ = get_version()
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "astrapy"
version = "0.7.1"
version = "0.7.3"
description = "AstraPy is a Pythonic SDK for DataStax Astra"
authors = [
"Kirsten Hunter <kirsten.hunter@datastax.com>"
Expand Down Expand Up @@ -28,12 +28,12 @@ classifiers = [
[tool.poetry.dependencies]
python = "^3.8.0"
cassio = "~0.1.3"
deprecation = "~2.1.0"
toml = "^0.10.2"
httpx = { version="~0.25.1", extras=["http2"] }

[tool.poetry.group.dev.dependencies]
black = "~23.11.0"
deprecation = "~2.1.0"
faker = "~20.0.0"
mypy = "~1.7.0"
pre-commit = "~3.5.0"
Expand Down

0 comments on commit 469d098

Please sign in to comment.