Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "reya-python-sdk"
version = "2.2.1.0"
version = "2.2.1.2"
description = "SDK for interacting with Reya Labs APIs"
authors = [
{name = "Reya Labs"}
Expand Down
23 changes: 16 additions & 7 deletions sdk/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path

try:
Expand All @@ -7,15 +8,23 @@


def _get_version() -> str:
current_file = Path(__file__)
pyproject_path = current_file.parent.parent / "pyproject.toml"
"""Return the installed SDK version.

Prefer distribution metadata so the version resolves when the SDK is installed
as a wheel or in editable mode, where pyproject.toml is not shipped next to the
package. Fall back to reading pyproject.toml when running from a source checkout
that is not installed as a distribution, and finally to "unknown".
"""
try:
with open(pyproject_path, "rb") as f:
pyproject_data = tomllib.load(f)
return str(pyproject_data["project"]["version"])
except (FileNotFoundError, KeyError, Exception):
raise ValueError("Failed to read version from pyproject.toml")
return version("reya-python-sdk")
except PackageNotFoundError:
pyproject_path = Path(__file__).parent.parent / "pyproject.toml"
try:
with open(pyproject_path, "rb") as f:
pyproject_data = tomllib.load(f)
return str(pyproject_data["project"]["version"])
except (OSError, KeyError, tomllib.TOMLDecodeError):
return "unknown"
Comment thread
0xZenus marked this conversation as resolved.


SDK_VERSION = _get_version()