Skip to content

Commit 156bbd7

Browse files
fix: pyproject.toml file error on get_version method
1 parent 3b29948 commit 156bbd7

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

musicai_sdk/utils.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,30 @@ def extract_file_extension_from_url(url):
1515

1616

1717
def get_version():
18-
package_path = Path(__file__).parent.parent / "pyproject.toml"
19-
with open(package_path, "r") as f:
20-
content = f.read()
21-
22-
for line in content.splitlines():
23-
if line.startswith("version = "):
24-
return line.split("=")[1].strip().strip("\"'")
25-
return "unknown"
18+
try:
19+
import importlib.metadata
20+
return importlib.metadata.version("musicai-sdk")
21+
except (ImportError, importlib.metadata.PackageNotFoundError):
22+
try:
23+
import os
24+
import musicai_sdk
25+
26+
package_dir = os.path.dirname(os.path.abspath(musicai_sdk.__file__))
27+
28+
pyproject_path = os.path.join(
29+
os.path.dirname(package_dir), "pyproject.toml"
30+
)
31+
32+
if os.path.exists(pyproject_path):
33+
with open(pyproject_path, "r") as f:
34+
for line in f:
35+
if line.strip().startswith("version"):
36+
version = line.split("=")[1].strip().strip("\"'")
37+
return version
38+
except Exception:
39+
pass
40+
41+
return "unknown"
2642

2743

2844
def get_user_agent(environment="SDK-Python", version=None):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "musicai-sdk"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
description = "Python SDK for Music.AI"
55
authors = ["Music.ai Support <support@music.ai>"]
66
license = "MIT"

0 commit comments

Comments
 (0)