From 15225ab7e250fd24e35a27e5f988c5824e6e2cb8 Mon Sep 17 00:00:00 2001 From: Roman Kalyakin Date: Fri, 11 Oct 2024 10:17:52 +0200 Subject: [PATCH] single source for "version" --- impresso/__init__.py | 4 ++-- impresso/client.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/impresso/__init__.py b/impresso/__init__.py index c77d158..ac35e71 100644 --- a/impresso/__init__.py +++ b/impresso/__init__.py @@ -1,4 +1,4 @@ -from impresso.client import connect # noqa +from impresso.client import connect, version # noqa from impresso.api_models import * # noqa from impresso.structures import ( # noqa TermSet, @@ -11,4 +11,4 @@ Partial, ) -__version__ = "0.9.0" +__version__ = version diff --git a/impresso/client.py b/impresso/client.py index 97e5343..5fa0b9c 100644 --- a/impresso/client.py +++ b/impresso/client.py @@ -1,6 +1,7 @@ """Impresso Python client library.""" import getpass +import importlib.metadata import logging import os from urllib.parse import urlparse @@ -14,6 +15,8 @@ logger = logging.getLogger(__name__) +version = importlib.metadata.version("impresso") + def _is_localhost_netloc(netloc: str) -> bool: return netloc.startswith("localhost") or netloc.startswith("127.0.0.1") @@ -45,7 +48,7 @@ def __init__(self, api_url: str, api_bearer_token: str): token=self._api_bearer_token, headers={ "Accept": "application/json", - "User-Agent": "impresso-py/0.1.0", + "User-Agent": f"impresso-py/${version}", }, raise_on_unexpected_status=True, httpx_args={