tracktolib 0.45.0__tar.gz → 0.46.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tracktolib-0.45.0 → tracktolib-0.46.1}/PKG-INFO +1 -1
- {tracktolib-0.45.0 → tracktolib-0.46.1}/pyproject.toml +2 -2
- {tracktolib-0.45.0 → tracktolib-0.46.1}/setup.py +1 -1
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/api.py +46 -9
- {tracktolib-0.45.0 → tracktolib-0.46.1}/LICENSE +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/README.md +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/__init__.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/http_utils.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/logs.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/pg/__init__.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/pg/query.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/pg/utils.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/pg_sync.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/pg_utils.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/s3/__init__.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/s3/minio.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/s3/s3.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/tests.py +0 -0
- {tracktolib-0.45.0 → tracktolib-0.46.1}/tracktolib/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "tracktolib"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.46.1"
|
|
4
4
|
description = "Utility library for python"
|
|
5
5
|
authors = ["Julien Brayere <julien.brayere@tracktor.fr>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -70,7 +70,7 @@ pythonPlatform = "Linux"
|
|
|
70
70
|
|
|
71
71
|
[tool.commitizen]
|
|
72
72
|
name = "cz_conventional_commits"
|
|
73
|
-
version = "0.
|
|
73
|
+
version = "0.46.1"
|
|
74
74
|
tag_format = "$version"
|
|
75
75
|
version_files = [
|
|
76
76
|
"pyproject.toml:version"
|
|
@@ -20,7 +20,7 @@ extras_require = \
|
|
|
20
20
|
|
|
21
21
|
setup_kwargs = {
|
|
22
22
|
'name': 'tracktolib',
|
|
23
|
-
'version': '0.
|
|
23
|
+
'version': '0.46.1',
|
|
24
24
|
'description': 'Utility library for python',
|
|
25
25
|
'long_description': "# Tracktolib\n\n[](https://pypi.python.org/pypi/tracktolib)\n[](https://pypi.python.org/pypi/tracktolib)\n[](https://app.circleci.com/pipelines/github/Tracktor/tracktolib?branch=master)\n\nUtility library for python\n\n# Installation\n\nYou can choose to not install all the dependencies by specifying\nthe [extra](https://python-poetry.org/docs/cli/#options-4) parameter such as:\n\n```bash\npoetry add tracktolib@latest -E pg-sync -E tests --group dev \n```\n\nHere we only install the utilities using `psycopg` (pg-sync) and `deepdiff` (tests) for the dev environment.\n\n# Utilities\n\n- **log**\n\nUtility functions for logging.\n\n```python\nimport logging\nfrom tracktolib.logs import init_logging\n\nlogger = logging.getLogger()\nformatter, stream_handler = init_logging(logger, 'json', version='0.0.1')\n```\n\n- **pg**\n\nUtility functions for [asyncpg](https://github.com/MagicStack/asyncpg)\n\n- **pg-sync**\n\nUtility functions based on psycopg such as `fetch_one`, `insert_many`, `fetch_count` ...\n\nTo use the functions, create a `Connection` using psycopg: `conn = psycopg2.connect()`\n\n*fetch_one*\n\n```python\nfrom pg.pg_sync import (\n insert_many, fetch_one, fetch_count, fetch_all\n)\n\ndata = [\n {'foo': 'bar', 'value': 1},\n {'foo': 'baz', 'value': 2}\n]\ninsert_many(conn, 'public.test', data) # Will insert the 2 dict\nquery = 'SELECT foo from public.test order by value asc'\nvalue = fetch_one(conn, query, required=True) # Will return {'foo': 'bar'}, raise an error is not found\nassert fetch_count(conn, 'public.test') == 2\nquery = 'SELECT * from public.test order by value asc'\nassert fetch_all(conn, query) == data\n\n```\n\n- **tests**\n\nUtility functions for testing\n\n- **s3-minio**\n\nUtility functions for [minio](https://min.io/docs/minio/linux/developers/python/API.html)\n\n- **s3**\n\nUtility functions for [aiobotocore](https://github.com/aio-libs/aiobotocore)\n\n- **logs**\n\nUtility functions to initialize the logging formatting and streams\n\n- **http**\n\nUtility functions using [httpx](https://www.python-httpx.org/)\n\n- **api**\n\nUtility functions using [fastapi](https://fastapi.tiangolo.com/)\n",
|
|
26
26
|
'author': 'Julien Brayere',
|
|
@@ -24,6 +24,7 @@ from .utils import json_serial
|
|
|
24
24
|
|
|
25
25
|
try:
|
|
26
26
|
from fastapi import params, APIRouter
|
|
27
|
+
from fastapi.routing import APIRoute
|
|
27
28
|
from fastapi.responses import JSONResponse
|
|
28
29
|
from pydantic.alias_generators import to_camel
|
|
29
30
|
from pydantic import BaseModel, ConfigDict
|
|
@@ -205,14 +206,56 @@ _NoneType = type(None)
|
|
|
205
206
|
|
|
206
207
|
class IgnoreConfig(BaseModel):
|
|
207
208
|
endpoints: dict[str, dict[Method, bool]]
|
|
208
|
-
|
|
209
|
+
ignore_missing: bool = True
|
|
209
210
|
|
|
210
211
|
|
|
211
|
-
def
|
|
212
|
+
def get_ignore_config() -> IgnoreConfig | None:
|
|
212
213
|
_config = os.getenv("IGNORE_CONFIG")
|
|
213
214
|
return IgnoreConfig.model_validate_json(_config) if _config else None
|
|
214
215
|
|
|
215
216
|
|
|
217
|
+
def set_ignore_config(config: str | IgnoreConfig):
|
|
218
|
+
if isinstance(config, str):
|
|
219
|
+
config = IgnoreConfig.model_validate_json(config)
|
|
220
|
+
os.environ["IGNORE_CONFIG"] = config.model_dump_json()
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _filter_route(route: APIRoute, ignored_route: dict[Method, bool], ignore_missing: bool) -> APIRoute | None:
|
|
224
|
+
# If no config is provided and default is to ignore missing, return the route
|
|
225
|
+
if ignored_route is None and not ignore_missing:
|
|
226
|
+
return route
|
|
227
|
+
|
|
228
|
+
has_methods = False
|
|
229
|
+
enabled_methods = {method for method, has_access in ignored_route.items() if has_access}
|
|
230
|
+
for method in list(route.methods):
|
|
231
|
+
# If the config is not specified, we remove the method if ignore_missing is True
|
|
232
|
+
if method not in ignored_route:
|
|
233
|
+
if ignore_missing:
|
|
234
|
+
route.methods -= {method}
|
|
235
|
+
continue
|
|
236
|
+
else:
|
|
237
|
+
has_methods = True
|
|
238
|
+
continue
|
|
239
|
+
elif method not in enabled_methods:
|
|
240
|
+
route.methods -= {method}
|
|
241
|
+
else:
|
|
242
|
+
has_methods = True
|
|
243
|
+
|
|
244
|
+
if not has_methods:
|
|
245
|
+
return None
|
|
246
|
+
return route
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def filter_routes(routes: list[APIRoute], ignore_config: IgnoreConfig) -> list[APIRoute]:
|
|
250
|
+
_routes = []
|
|
251
|
+
for route in routes:
|
|
252
|
+
_ignored_route = ignore_config.endpoints.get(route.path)
|
|
253
|
+
_route = _filter_route(route, _ignored_route or {}, ignore_missing=ignore_config.ignore_missing)
|
|
254
|
+
if _route is not None:
|
|
255
|
+
_routes.append(_route)
|
|
256
|
+
return _routes
|
|
257
|
+
|
|
258
|
+
|
|
216
259
|
def _get_return_type(fn):
|
|
217
260
|
return_type = get_type_hints(fn)["return"]
|
|
218
261
|
_args = get_args(return_type)
|
|
@@ -228,14 +271,8 @@ def add_endpoint(
|
|
|
228
271
|
*,
|
|
229
272
|
dependencies: Dependencies = None,
|
|
230
273
|
):
|
|
231
|
-
_ignore_config =
|
|
274
|
+
_ignore_config = get_ignore_config()
|
|
232
275
|
for _method, _meta in endpoint.methods.items():
|
|
233
|
-
# Do not add endpoint if it is not in the ignore config
|
|
234
|
-
if _ignore_config is not None:
|
|
235
|
-
_has_access = _ignore_config.endpoints.get(path, {}).get(_method, not _ignore_config.ignore_default)
|
|
236
|
-
if not _has_access:
|
|
237
|
-
continue
|
|
238
|
-
#
|
|
239
276
|
_fn = _meta["fn"]
|
|
240
277
|
_status_code = _meta["status_code"]
|
|
241
278
|
_dependencies = _meta["dependencies"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|