Skip to content

Commit 5e97b3c

Browse files
Merge pull request #4 from tracereq/pip-publish
Pip publish
2 parents 4f16798 + f8a383a commit 5e97b3c

File tree

10 files changed

+134
-66
lines changed

10 files changed

+134
-66
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 TraceReq
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is the Python SDK for [TraceReq](http://tracereq.com/)
77
## Installation
88

99
```bash
10-
pip install --upgrade tracereq
10+
pip install --upgrade tracereq-sdk
1111
```
1212

1313
## Usage with Flask

pyproject.toml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# pyproject.toml
2+
3+
[build-system]
4+
requires = ["setuptools>=61.0.0", "wheel"]
5+
build-backend = "setuptools.build_meta"
6+
7+
[project]
8+
name = "tracereq-sdk"
9+
version = "1.0.0"
10+
description = "Python client for TraceReq (https://tracereq.com)"
11+
readme = "README.md"
12+
authors = [
13+
{ name = "Prateek Sachan", email = "ps@prateeksachan.com" }
14+
]
15+
license = { file = "LICENSE" }
16+
classifiers = [
17+
"License :: OSI Approved :: MIT License",
18+
"Programming Language :: Python",
19+
"Programming Language :: Python :: 3",
20+
]
21+
keywords = ["flask", "trace", "api"]
22+
dependencies = [
23+
'urllib3>=1.26.16; python_version >="3.6"'
24+
]
25+
requires-python = ">=3.6"
26+
27+
[project.optional-dependencies]
28+
dev = ["pip-tools"]
29+
30+
[project.urls]
31+
Homepage = "https://github.com/tracereq/python-tracereq-sdk"
32+
33+
[tool.bumpver]
34+
current_version = "1.0.0"
35+
version_pattern = "MAJOR.MINOR.PATCH"
36+
commit_message = "bump version {old_version} -> {new_version}"
37+
tag_message = "{new_version}"
38+
tag_scope = "default"
39+
commit = true
40+
tag = true
41+
push = false
42+
43+
[tool.bumpver.file_patterns]
44+
"pyproject.toml" = [
45+
'current_version = "{version}"',
46+
]
47+
"setup.py" = [
48+
"{version}",
49+
"{pep440_version}",
50+
]
51+
"README.md" = [
52+
"{version}",
53+
"{pep440_version}",
54+
]
55+

setup.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

tracereq/__init__.py

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,6 @@
1-
from threading import Lock
1+
from tracereq.api import *
22

3-
_installer_lock = Lock()
4-
_installed_integrations = {}
53

6-
7-
def get_core_integrations():
8-
from .customlib import CustomlibIntegration
9-
yield CustomlibIntegration()
10-
11-
12-
def get_custom_integrations(**kwargs):
13-
if kwargs.get('flask_app'):
14-
from .flasklib import FlasklibIntegration
15-
yield FlasklibIntegration(kwargs.get('flask_app'))
16-
17-
18-
def setup_integrations(*args, **kwargs):
19-
integrations = list()
20-
21-
core_integrations = get_core_integrations()
22-
custom_integrations = get_custom_integrations(**kwargs)
23-
for instance in core_integrations:
24-
if not any(isinstance(x, type(instance)) for x in integrations):
25-
integrations.append(instance)
26-
27-
for instance in custom_integrations:
28-
if not any(isinstance(x, type(instance)) for x in integrations):
29-
integrations.append(instance)
30-
31-
for integration in integrations:
32-
integration()
33-
34-
35-
class Integration(object):
36-
integration_key = None
37-
38-
def install(self):
39-
raise NotImplementedError()
40-
41-
def __call__(self, environ=None, start_response=None):
42-
assert self.integration_key
43-
with _installer_lock:
44-
if self.integration_key in _installed_integrations:
45-
return
46-
47-
self.install()
48-
_installed_integrations[self.integration_key] = self
4+
__all__ = [
5+
"init"
6+
]

tracereq/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .engine import Engine
22
from .client import Client
3-
from . import setup_integrations
3+
from .integrations import setup_integrations
44

55
__all__ = ['Engine', 'Client']
66

tracereq/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class Client(object):
66
def __init__(
77
self,
8-
api_key: str = '',
8+
api_key,
99
*args,
1010
**kwargs
1111
):

tracereq/customlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from . import Integration
1+
from .integrations import Integration
22
from .engine import Engine
33
from .constants import HEADER_NAME, DESTINATION_URL
44
from urllib.parse import urlsplit

tracereq/integrations/__init__.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from threading import Lock
2+
3+
_installer_lock = Lock()
4+
_installed_integrations = {}
5+
6+
7+
def get_core_integrations():
8+
from tracereq.customlib import CustomlibIntegration
9+
yield CustomlibIntegration()
10+
11+
12+
def get_custom_integrations(**kwargs):
13+
if kwargs.get('flask_app'):
14+
from .flasklib import FlasklibIntegration
15+
yield FlasklibIntegration(kwargs.get('flask_app'))
16+
17+
18+
def setup_integrations(*args, **kwargs):
19+
integrations = list()
20+
21+
core_integrations = get_core_integrations()
22+
custom_integrations = get_custom_integrations(**kwargs)
23+
for instance in core_integrations:
24+
if not any(isinstance(x, type(instance)) for x in integrations):
25+
integrations.append(instance)
26+
27+
for instance in custom_integrations:
28+
if not any(isinstance(x, type(instance)) for x in integrations):
29+
integrations.append(instance)
30+
31+
for integration in integrations:
32+
integration()
33+
34+
35+
class Integration(object):
36+
integration_key = None
37+
38+
def install(self):
39+
raise NotImplementedError()
40+
41+
def __call__(self, environ=None, start_response=None):
42+
assert self.integration_key
43+
with _installer_lock:
44+
if self.integration_key in _installed_integrations:
45+
return
46+
47+
self.install()
48+
_installed_integrations[self.integration_key] = self

tracereq/flasklib.py renamed to tracereq/integrations/flasklib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from flask import Flask, _request_ctx_stack
22
from flask.signals import request_started, request_finished
33
from . import Integration
4-
from .engine import Engine
5-
from .tracing import generate_trace_event, Trace, generalize_request
4+
from tracereq.engine import Engine
5+
from tracereq.tracing import generate_trace_event, Trace, generalize_request
66

77

88
class FlasklibIntegration(Integration):

0 commit comments

Comments
 (0)