tracktolib 0.38.1__tar.gz → 0.39.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tracktolib
3
- Version: 0.38.1
3
+ Version: 0.39.1
4
4
  Summary: Utility library for python
5
5
  Home-page: https://github.com/tracktor/tracktolib
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "tracktolib"
3
- version = "0.38.1"
3
+ version = "0.39.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.38.1"
73
+ version = "0.39.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.38.1',
23
+ 'version': '0.39.1',
24
24
  'description': 'Utility library for python',
25
25
  'long_description': "# Tracktolib\n\n[![Python versions](https://img.shields.io/pypi/pyversions/tracktolib)](https://pypi.python.org/pypi/tracktolib)\n[![Latest PyPI version](https://img.shields.io/pypi/v/tracktolib?logo=pypi)](https://pypi.python.org/pypi/tracktolib)\n[![CircleCI](https://circleci.com/gh/Tracktor/tracktolib/tree/master.svg?style=shield)](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',
@@ -13,6 +13,7 @@ from .utils import json_serial, to_camel_case
13
13
  try:
14
14
  from fastapi import params, APIRouter
15
15
  from fastapi.responses import JSONResponse
16
+ import pydantic
16
17
  from pydantic import BaseModel
17
18
  import starlette.status
18
19
  except ImportError:
@@ -53,7 +54,7 @@ class MethodMeta(TypedDict):
53
54
  dependencies: Dependencies
54
55
  path: str | None
55
56
  response_model: Type[BaseModel | None | Sequence[BaseModel]] | None
56
-
57
+ openapi_extra: dict[str, Any] | None
57
58
 
58
59
  @dataclass
59
60
  class Endpoint:
@@ -67,52 +68,62 @@ class Endpoint:
67
68
  def get(self, status_code: StatusCode = None,
68
69
  dependencies: Dependencies = None,
69
70
  path: str | None = None,
70
- model: Type[B] | None = None):
71
+ model: Type[B] | None = None,
72
+ openapi_extra: dict[str, Any] | None = None):
71
73
  return _get_method_wrapper(cls=self, method='GET',
72
74
  status_code=status_code,
73
75
  dependencies=dependencies,
74
76
  path=path,
75
- model=model)
77
+ model=model,
78
+ openapi_extra=openapi_extra)
76
79
 
77
80
  def post(self, *, status_code: StatusCode = None,
78
81
  dependencies: Dependencies = None,
79
82
  path: str | None = None,
80
- model: Type[B] | None = None):
83
+ model: Type[B] | None = None,
84
+ openapi_extra: dict[str, Any] | None = None):
81
85
  return _get_method_wrapper(cls=self, method='POST',
82
86
  status_code=status_code,
83
87
  dependencies=dependencies,
84
88
  path=path,
85
- model=model)
89
+ model=model,
90
+ openapi_extra=openapi_extra)
86
91
 
87
92
  def put(self, status_code: StatusCode = None,
88
93
  dependencies: Dependencies = None,
89
94
  path: str | None = None,
90
- model: Type[B] | None = None):
95
+ model: Type[B] | None = None,
96
+ openapi_extra: dict[str, Any] | None = None):
91
97
  return _get_method_wrapper(cls=self, method='PUT',
92
98
  status_code=status_code,
93
99
  dependencies=dependencies,
94
100
  path=path,
95
- model=model)
101
+ model=model,
102
+ openapi_extra=openapi_extra)
96
103
 
97
104
  def delete(self, status_code: StatusCode = None,
98
105
  dependencies: Dependencies = None,
99
106
  path: str | None = None,
100
- model: Type[B] | None = None):
107
+ model: Type[B] | None = None,
108
+ openapi_extra: dict[str, Any] | None = None):
101
109
  return _get_method_wrapper(cls=self, method='DELETE',
102
110
  status_code=status_code,
103
111
  dependencies=dependencies,
104
112
  path=path,
105
- model=model)
113
+ model=model,
114
+ openapi_extra=openapi_extra)
106
115
 
107
116
  def patch(self, status_code: StatusCode = None,
108
117
  dependencies: Dependencies = None,
109
118
  path: str | None = None,
110
- model: Type[B] | None = None):
119
+ model: Type[B] | None = None,
120
+ openapi_extra: dict[str, Any] | None = None):
111
121
  return _get_method_wrapper(cls=self, method='PATCH',
112
122
  status_code=status_code,
113
123
  dependencies=dependencies,
114
124
  path=path,
115
- model=model)
125
+ model=model,
126
+ openapi_extra=openapi_extra)
116
127
 
117
128
 
118
129
  def _get_method_wrapper(cls: Endpoint, method: Method,
@@ -120,14 +131,16 @@ def _get_method_wrapper(cls: Endpoint, method: Method,
120
131
  status_code: StatusCode = None,
121
132
  dependencies: Dependencies = None,
122
133
  path: str | None = None,
123
- model: Type[B] | None = None):
134
+ model: Type[B] | None = None,
135
+ openapi_extra: dict[str, Any] | None = None):
124
136
  def _set_method_wrapper(func: EnpointFn):
125
137
  _meta: MethodMeta = {
126
138
  'fn': func,
127
139
  'status_code': status_code,
128
140
  'dependencies': dependencies,
129
141
  'path': path,
130
- 'response_model': model
142
+ 'response_model': model,
143
+ 'openapi_extra': openapi_extra
131
144
  }
132
145
  cls._methods[method] = _meta
133
146
 
@@ -169,7 +182,8 @@ def add_endpoint(path: str,
169
182
  name=getdoc(_fn),
170
183
  response_model=_response_model,
171
184
  status_code=_status_code,
172
- dependencies=[*(_dependencies or []), *(dependencies or [])])
185
+ dependencies=[*(_dependencies or []), *(dependencies or [])],
186
+ openapi_extra=_meta.get('openapi_extra'))
173
187
 
174
188
 
175
189
  @dataclass(init=False)
@@ -187,11 +201,15 @@ class JSONSerialResponse(JSONResponse):
187
201
  ).encode("utf-8")
188
202
 
189
203
 
190
- class CamelCaseModel(BaseModel):
191
- class Config:
192
- alias_generator = to_camel_case
193
- allow_population_by_field_name = True
194
-
204
+ if pydantic.__version__ < '2.0.0':
205
+ class CamelCaseModel(BaseModel): # type: ignore
206
+ class Config:
207
+ alias_generator = to_camel_case
208
+ allow_population_by_field_name = True
209
+ else:
210
+ class CamelCaseModel(BaseModel):
211
+ def __init__(self):
212
+ raise NotImplementedError('Please use pydantic < 2.0.0')
195
213
 
196
214
  def check_status(resp, status: int = starlette.status.HTTP_200_OK):
197
215
  assert resp.status_code == status, json.dumps(resp.json(), indent=4)
File without changes
File without changes