From c021fae8662e69e509b14029d5a177e78685a6bc Mon Sep 17 00:00:00 2001 From: Prateek Sachan Date: Sun, 23 Jul 2023 22:42:48 +0530 Subject: [PATCH 1/5] packaging using pyproject.toml --- LICENSE | 21 ++++++++++++++++++ README.md | 2 +- pyproject.toml | 54 ++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 14 ------------ tracereq/client.py | 2 +- 5 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 LICENSE create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d6912d9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 TraceReq + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index ffc58ee..db0c64a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This is the Python SDK for [TraceReq](http://tracereq.com/) ## Installation ```bash -pip install --upgrade tracereq +pip install --upgrade tracereq-sdk ``` ## Usage with Flask diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4ec3111 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,54 @@ +# pyproject.toml + +[build-system] +requires = ["setuptools>=61.0.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "tracereq-sdk" +version = "1.0.0" +description = "Python client for TraceReq (https://tracereq.com)" +readme = "README.md" +authors = [ + { name = "Prateek Sachan", email = "ps@prateeksachan.com" } +] +license = { file = "LICENSE" } +classifiers = [ + "License :: OSI Approved :: MIT License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", +] +keywords = ["flask", "trace", "api"] +dependencies = [ +] +requires-python = ">=3.6" + +[project.optional-dependencies] +dev = ["pip-tools"] + +[project.urls] +Homepage = "https://github.com/tracereq/python-tracereq-sdk" + +[tool.bumpver] +current_version = "1.0.0" +version_pattern = "MAJOR.MINOR.PATCH" +commit_message = "bump version {old_version} -> {new_version}" +tag_message = "{new_version}" +tag_scope = "default" +commit = true +tag = true +push = false + +[tool.bumpver.file_patterns] +"pyproject.toml" = [ + 'current_version = "{version}"', +] +"setup.py" = [ + "{version}", + "{pep440_version}", +] +"README.md" = [ + "{version}", + "{pep440_version}", +] + diff --git a/setup.py b/setup.py deleted file mode 100644 index db3fd67..0000000 --- a/setup.py +++ /dev/null @@ -1,14 +0,0 @@ -from setuptools import find_packages, setup - -setup( - name='tracereq', - setup_requires=['wheel'], - packages=['tracereq'], - include_package_data=True, - version='1.0.0', - author='Prateek Sachan', - author_email="ps@prateeksachan.com", - license='MIT', - python_requires=">=3.6", - install_requires=['urllib3>=1.26.11; python_version >="3.6"'] -) diff --git a/tracereq/client.py b/tracereq/client.py index 7f50100..0682a96 100644 --- a/tracereq/client.py +++ b/tracereq/client.py @@ -5,7 +5,7 @@ class Client(object): def __init__( self, - api_key: str = '', + api_key, *args, **kwargs ): From 4e4cb0a0e6f53b16dd95ae868f88a1c25fe637d7 Mon Sep 17 00:00:00 2001 From: Prateek Sachan Date: Sun, 23 Jul 2023 22:48:14 +0530 Subject: [PATCH 2/5] changing structure on integrations dir --- tracereq/__init__.py | 50 ++----------------------- tracereq/integrations/__init__.py | 48 ++++++++++++++++++++++++ tracereq/{ => integrations}/flasklib.py | 0 3 files changed, 52 insertions(+), 46 deletions(-) create mode 100644 tracereq/integrations/__init__.py rename tracereq/{ => integrations}/flasklib.py (100%) diff --git a/tracereq/__init__.py b/tracereq/__init__.py index 7631bad..6aeb3ae 100644 --- a/tracereq/__init__.py +++ b/tracereq/__init__.py @@ -1,48 +1,6 @@ -from threading import Lock +from tracereq.api import * -_installer_lock = Lock() -_installed_integrations = {} - -def get_core_integrations(): - from .customlib import CustomlibIntegration - yield CustomlibIntegration() - - -def get_custom_integrations(**kwargs): - if kwargs.get('flask_app'): - from .flasklib import FlasklibIntegration - yield FlasklibIntegration(kwargs.get('flask_app')) - - -def setup_integrations(*args, **kwargs): - integrations = list() - - core_integrations = get_core_integrations() - custom_integrations = get_custom_integrations(**kwargs) - for instance in core_integrations: - if not any(isinstance(x, type(instance)) for x in integrations): - integrations.append(instance) - - for instance in custom_integrations: - if not any(isinstance(x, type(instance)) for x in integrations): - integrations.append(instance) - - for integration in integrations: - integration() - - -class Integration(object): - integration_key = None - - def install(self): - raise NotImplementedError() - - def __call__(self, environ=None, start_response=None): - assert self.integration_key - with _installer_lock: - if self.integration_key in _installed_integrations: - return - - self.install() - _installed_integrations[self.integration_key] = self +__all__ = [ + "init" +] diff --git a/tracereq/integrations/__init__.py b/tracereq/integrations/__init__.py new file mode 100644 index 0000000..7631bad --- /dev/null +++ b/tracereq/integrations/__init__.py @@ -0,0 +1,48 @@ +from threading import Lock + +_installer_lock = Lock() +_installed_integrations = {} + + +def get_core_integrations(): + from .customlib import CustomlibIntegration + yield CustomlibIntegration() + + +def get_custom_integrations(**kwargs): + if kwargs.get('flask_app'): + from .flasklib import FlasklibIntegration + yield FlasklibIntegration(kwargs.get('flask_app')) + + +def setup_integrations(*args, **kwargs): + integrations = list() + + core_integrations = get_core_integrations() + custom_integrations = get_custom_integrations(**kwargs) + for instance in core_integrations: + if not any(isinstance(x, type(instance)) for x in integrations): + integrations.append(instance) + + for instance in custom_integrations: + if not any(isinstance(x, type(instance)) for x in integrations): + integrations.append(instance) + + for integration in integrations: + integration() + + +class Integration(object): + integration_key = None + + def install(self): + raise NotImplementedError() + + def __call__(self, environ=None, start_response=None): + assert self.integration_key + with _installer_lock: + if self.integration_key in _installed_integrations: + return + + self.install() + _installed_integrations[self.integration_key] = self diff --git a/tracereq/flasklib.py b/tracereq/integrations/flasklib.py similarity index 100% rename from tracereq/flasklib.py rename to tracereq/integrations/flasklib.py From 94827ba6d00054326b204e541746bcef0c3d0659 Mon Sep 17 00:00:00 2001 From: Prateek Sachan Date: Sun, 23 Jul 2023 22:50:47 +0530 Subject: [PATCH 3/5] changing structure on integrations dir --- tracereq/api.py | 2 +- tracereq/customlib.py | 2 +- tracereq/integrations/__init__.py | 2 +- tracereq/integrations/flasklib.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tracereq/api.py b/tracereq/api.py index 93fbaba..6a37fa8 100644 --- a/tracereq/api.py +++ b/tracereq/api.py @@ -1,6 +1,6 @@ from .engine import Engine from .client import Client -from . import setup_integrations +from .integrations import setup_integrations __all__ = ['Engine', 'Client'] diff --git a/tracereq/customlib.py b/tracereq/customlib.py index 98b7122..ad0f903 100644 --- a/tracereq/customlib.py +++ b/tracereq/customlib.py @@ -1,4 +1,4 @@ -from . import Integration +from .integrations import Integration from .engine import Engine from .constants import HEADER_NAME, DESTINATION_URL from urllib.parse import urlsplit diff --git a/tracereq/integrations/__init__.py b/tracereq/integrations/__init__.py index 7631bad..2e2e29e 100644 --- a/tracereq/integrations/__init__.py +++ b/tracereq/integrations/__init__.py @@ -5,7 +5,7 @@ def get_core_integrations(): - from .customlib import CustomlibIntegration + from tracereq.customlib import CustomlibIntegration yield CustomlibIntegration() diff --git a/tracereq/integrations/flasklib.py b/tracereq/integrations/flasklib.py index 574a7b9..b3e8f16 100644 --- a/tracereq/integrations/flasklib.py +++ b/tracereq/integrations/flasklib.py @@ -1,8 +1,8 @@ from flask import Flask, _request_ctx_stack from flask.signals import request_started, request_finished from . import Integration -from .engine import Engine -from .tracing import generate_trace_event, Trace, generalize_request +from tracereq.engine import Engine +from tracereq.tracing import generate_trace_event, Trace, generalize_request class FlasklibIntegration(Integration): From aeeb4f6b9d853cfe2b7667b3c630471db1445258 Mon Sep 17 00:00:00 2001 From: Prateek Sachan Date: Sun, 23 Jul 2023 22:56:37 +0530 Subject: [PATCH 4/5] aqdd lib dependencies --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 4ec3111..4d90e67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ classifiers = [ ] keywords = ["flask", "trace", "api"] dependencies = [ + "urllib3" ] requires-python = ">=3.6" From f8a383a1a2c3b7c0b472f4bc750eedfae903953a Mon Sep 17 00:00:00 2001 From: Prateek Sachan Date: Sun, 23 Jul 2023 22:57:37 +0530 Subject: [PATCH 5/5] add lib dependencies --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4d90e67..7cb18ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ classifiers = [ ] keywords = ["flask", "trace", "api"] dependencies = [ - "urllib3" + 'urllib3>=1.26.16; python_version >="3.6"' ] requires-python = ">=3.6"