Skip to content

Commit 391ca93

Browse files
committed
Replace pyproject toml version fetch with util
1 parent e0e0e9f commit 391ca93

File tree

4 files changed

+6
-31
lines changed

4 files changed

+6
-31
lines changed

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 = "telq"
3-
version = "1.3.0"
3+
version = "1.3.1"
44
description = "Python SDK for TelQ Telecom API"
55
authors = ["Tuvshinbayar Davaa <[email protected]>"]
66

telq/authentication/__init__.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import toml
55
import requests
66
import telq.endpoints as endpoints
7+
from telq.util.version import SDK_VERSION
78

89

910
@dataclass
@@ -42,26 +43,12 @@ def __post_init__(self) -> None:
4243
self.headers = {
4344
"accept": "application/json",
4445
"Content-Type": "application/json",
45-
"User-Agent": f"python-sdk/{self.__get_sdk_version__()}"
46+
"User-Agent": f"python-sdk/{SDK_VERSION}"
4647
}
4748
self.data = {"appId": self.api_id, "appKey": self.api_key, "baseUrl": self.base_url}
4849
self._validate_api_version()
4950
self._authenticate_user()
5051

51-
def __get_sdk_version__(self):
52-
pyproject_toml_path = os.path.abspath(
53-
os.path.join(os.path.dirname(__file__), "..", "..", "pyproject.toml")
54-
)
55-
with open(pyproject_toml_path, "r") as file:
56-
content = file.read()
57-
58-
# Parse the content using the toml library
59-
data = toml.loads(content)
60-
61-
# Extract the version (assuming it's under [tool.poetry])
62-
version = data["tool"]["poetry"]["version"]
63-
return version
64-
6552
def _validate_api_version(self) -> None:
6653
_deprecated_versions = ["v1.0", "v1.1", "v1.2", "v1.3", "v1.4"]
6754
_currently_supported_versions = ["v1.5", "v2.1", "v3"]

telq/util/rest.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,18 @@
77
from requests.exceptions import JSONDecodeError
88

99
from telq.authentication import Authentication
10+
from telq.util.version import SDK_VERSION
1011

1112
class TelQRest(ABC):
1213
def __init__(self, authentcation: Optional[Authentication] = None):
1314
self._authentication = authentcation
14-
self.sdk_version = self.__get_sdk_version__()
1515

16-
def __get_sdk_version__(self):
17-
pyproject_toml_path = os.path.abspath(
18-
os.path.join(os.path.dirname(__file__), "..", "..", "pyproject.toml")
19-
)
20-
with open(pyproject_toml_path, "r") as file:
21-
content = file.read()
22-
23-
# Parse the content using the toml library
24-
data = toml.loads(content)
25-
26-
# Extract the version (assuming it's under [tool.poetry])
27-
version = data["tool"]["poetry"]["version"]
28-
return version
2916

3017
def request(self, url: str, method: str, data: Optional[dict] = None, extra_headers: Optional[dict] = None) -> dict:
3118
headers = {
3219
"accept": "*/*",
3320
"Content-Type": "application/json",
34-
"User-Agent": f"python-sdk/{self.sdk_version}"
21+
"User-Agent": f"python-sdk/{SDK_VERSION}"
3522
}
3623
if self._authentication:
3724
headers["Authorization"] = self._authentication._bearer_token

telq/util/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SDK_VERSION="1.3.1"

0 commit comments

Comments
 (0)