Skip to content

Commit ac4d976

Browse files
committed
set the version depending on the toml
1 parent c0f0bbc commit ac4d976

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "PyTrilium"
7-
version = "1.1.0"
7+
version = "1.1.1"
88
authors = [
99
{ name="perfectra1n", email="[email protected]" },
1010
]

pytrilium/PyTriliumClient.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import requests
2+
import toml
23
from requests.adapters import HTTPAdapter, Retry
34

45
# Local import
@@ -45,7 +46,9 @@ def __init__(self, url: str, token: str, debug: bool = False) -> None:
4546
def make_requests_session(self) -> None:
4647
"""Creates a requests session with the token and user agent header."""
4748
self.session = requests.Session()
48-
self.session.headers.update({"User-Agent": "PyTriliumClient/1.0.6"})
49+
50+
# Version here
51+
self.session.headers.update({"User-Agent": f"pytrilium/{self.get_version()}"})
4952
#self.session.headers.update({"Content-Type": "application/json"})
5053

5154
# Set up retry logic
@@ -134,4 +137,20 @@ def get_app_info(self) -> dict:
134137
dict
135138
The app info from the Trilium API.
136139
"""
137-
return self.make_request("/app-info").json()
140+
return self.make_request("/app-info").json()
141+
142+
def get_pyproject_toml(self) -> dict:
143+
"""Load the pyproject.toml file. This should not be called manually."""
144+
import toml
145+
with open("pyproject.toml", "r") as f:
146+
return toml.load(f)
147+
148+
def get_version(self) -> str:
149+
"""Gets the version of the PyTriliumClient.
150+
151+
Returns
152+
-------
153+
str
154+
The version of the PyTriliumClient.
155+
"""
156+
return self.get_pyproject_toml()["project"]["version"]

0 commit comments

Comments
 (0)