From cff83a2e5db6c08d963d95645cda4a1c6297559c Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:34:13 +0530 Subject: [PATCH] build: add client header --- setup.py | 22 +++++++++++----------- videodb/__about__.py | 8 ++++++++ videodb/__init__.py | 1 + videodb/_utils/_http_client.py | 8 +++++++- videodb/client.py | 4 ++-- videodb/video.py | 1 - 6 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 videodb/__about__.py diff --git a/setup.py b/setup.py index bdb8b05..b97aad2 100644 --- a/setup.py +++ b/setup.py @@ -2,16 +2,16 @@ import os from setuptools import setup, find_packages -ROOT = os.path.dirname(__file__) +ROOT = os.path.dirname(os.path.abspath(__file__)) # Read in the package version per recommendations from: # https://packaging.python.org/guides/single-sourcing-package-version/ -def get_version(): - with open(os.path.join(ROOT, "videodb", "__init__.py")) as f: - for line in f.readlines(): - if line.startswith("__version__"): - return line.split("=")[1].strip().strip('''"''') + +about_path = os.path.join(ROOT, "videodb", "__about__.py") +about = {} +with open(about_path) as fp: + exec(fp.read(), about) # read the contents of README file @@ -19,14 +19,14 @@ def get_version(): setup( - name="videodb", - version=get_version(), - author="videodb", - author_email="contact@videodb.io", + name=about["__title__"], + version=about["__version__"], + author=about["__author__"], + author_email=about["__email__"], description="VideoDB Python SDK", long_description=long_description, long_description_content_type="text/markdown", - url="https://github.com/video-db/videodb-python", + url=about["__url__"], packages=find_packages(exclude=["tests", "tests.*"]), python_requires=">=3.8", install_requires=[ diff --git a/videodb/__about__.py b/videodb/__about__.py new file mode 100644 index 0000000..d71b052 --- /dev/null +++ b/videodb/__about__.py @@ -0,0 +1,8 @@ +""" About information for videodb sdk""" + + +__version__ = "0.2.0" +__title__ = "videodb" +__author__ = "videodb" +__email__ = "contact@videodb.io" +__url__ = "https://github.com/video-db/videodb-python" diff --git a/videodb/__init__.py b/videodb/__init__.py index 22fbad6..82e2500 100644 --- a/videodb/__init__.py +++ b/videodb/__init__.py @@ -4,6 +4,7 @@ import logging from typing import Optional +from videodb.__about__ import __version__ from videodb._utils._video import play_stream from videodb._constants import ( VIDEO_DB_API, diff --git a/videodb/_utils/_http_client.py b/videodb/_utils/_http_client.py index 0b4ae80..8633ebb 100644 --- a/videodb/_utils/_http_client.py +++ b/videodb/_utils/_http_client.py @@ -32,6 +32,7 @@ def __init__( self, api_key: str, base_url: str, + version: str, max_retries: Optional[int] = HttpClientDefaultValues.max_retries, ) -> None: """Create a new http client instance @@ -50,8 +51,13 @@ def __init__( adapter = HTTPAdapter(max_retries=retries) self.session.mount("http://", adapter) self.session.mount("https://", adapter) + self.version = version self.session.headers.update( - {"x-access-token": api_key, "Content-Type": "application/json"} + { + "x-access-token": api_key, + "x-videodb-client": f"videodb-python/{self.version}", + "Content-Type": "application/json", + } ) self.base_url = base_url self.show_progress = False diff --git a/videodb/client.py b/videodb/client.py index 39bf38b..19d9c1d 100644 --- a/videodb/client.py +++ b/videodb/client.py @@ -5,7 +5,7 @@ Union, List, ) - +from videodb import __version__ from videodb._constants import ( ApiPath, ) @@ -28,7 +28,7 @@ def __init__(self, api_key: str, base_url: str) -> None: self.api_key = api_key self.base_url = base_url self.collection_id = "default" - super().__init__(api_key, base_url) + super().__init__(api_key=api_key, base_url=base_url, version=__version__) def get_collection(self, collection_id: Optional[str] = "default") -> Collection: collection_data = self.get(path=f"{ApiPath.collection}/{collection_id}") diff --git a/videodb/video.py b/videodb/video.py index 0b277c7..845e32d 100644 --- a/videodb/video.py +++ b/videodb/video.py @@ -276,7 +276,6 @@ def list_scene_index(self) -> List: index_data = self._connection.get( path=f"{ApiPath.video}/{self.id}/{ApiPath.index}/{ApiPath.scene}" ) - return index_data.get("scene_indexes", []) def get_scene_index(self, scene_index_id: str) -> Optional[List]: