Skip to content
This repository was archived by the owner on Nov 14, 2025. It is now read-only.

Commit 9049981

Browse files
committed
Fixed some linter errors
1 parent d452c35 commit 9049981

34 files changed

Lines changed: 417 additions & 434 deletions

poetry.lock

Lines changed: 62 additions & 142 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,11 @@ flake8-black = "^0.3.3"
3434
Sphinx = "^4.2.0"
3535
sphinx-autodoc-typehints = "^1.12.0"
3636
sphinx-rtd-theme = "^1.0.0"
37-
flakehell = "^0.9.0"
3837
pytest-httpx = "^0.21.0"
3938
pytest-asyncio = "^0.19.0"
4039
ipykernel = "^6.15.2"
4140
pydata-sphinx-theme = "0.9.0"
4241

43-
[tool.flakehell]
44-
exclude = ["README.md"]
45-
format = "colored"
46-
max_line_length = 90
47-
extended_default_ignore = []
48-
show_source = true
49-
5042
[build-system]
5143
requires = ["poetry-core>=1.0.0"]
5244
build-backend = "poetry.core.masonry.api"

src/ngsildclient/api/alt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, client: Client):
3737
def count(self, query: Union[dict, Path], ctx: str = None) -> int:
3838
if isinstance(query, Path):
3939
with open(query) as f:
40-
query = json.load(f)
40+
query = json.load(f)
4141
return self._client.entities._count_alt(query, ctx)
4242

4343
def query_head(self, query: Union[dict, Path], ctx: str = None, n: int = 5) -> List[Entity]:
@@ -68,7 +68,7 @@ def query_head(self, query: Union[dict, Path], ctx: str = None, n: int = 5) -> L
6868
"""
6969
if isinstance(query, Path):
7070
with open(query) as f:
71-
query = json.load(f)
71+
query = json.load(f)
7272
return self._client.entities._query_alt(query, ctx, limit=n)
7373

7474
def query(
@@ -105,7 +105,7 @@ def query(
105105
"""
106106
if isinstance(query, Path):
107107
with open(query) as f:
108-
query = json.load(f)
108+
query = json.load(f)
109109
entities: list[Entity] = []
110110
count = self.count(query, ctx=ctx)
111111
if count > max:
@@ -141,7 +141,7 @@ def query_generator(
141141
"""
142142
if isinstance(query, Path):
143143
with open(query) as f:
144-
query = json.load(f)
144+
query = json.load(f)
145145
count = self.count(query)
146146
for page in range(ceil(count / limit)):
147147
if batch:

src/ngsildclient/api/asyn/batch.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,18 @@
2626

2727
logger = logging.getLogger(__name__)
2828

29+
2930
class Batch:
30-
"""A wrapper for the NGSI-LD API batch endpoint."""
31+
"""A wrapper for the NGSI-LD API batch endpoint."""
3132

3233
def __init__(self, client: AsyncClient, url: str):
3334
self._client = client
3435
self._session = client.client
3536
self.url = url
3637

3738
@rfc7807_error_handle_async
38-
async def _create(
39-
self, entities: Sequence[Entity]) -> BatchResult:
40-
r = await self._session.post(
41-
f"{self.url}/create/",
42-
content=json.dumps([e for e in entities], cls=NgsiEncoder)
43-
)
39+
async def _create(self, entities: Sequence[Entity]) -> BatchResult:
40+
r = await self._session.post(f"{self.url}/create/", content=json.dumps([e for e in entities], cls=NgsiEncoder))
4441
self._client.raise_for_status(r)
4542
if r.status_code == 201:
4643
success, errors = r.json(), []
@@ -55,16 +52,14 @@ async def _create(
5552
async def create(self, entities: Sequence[Entity], batchsize: int = BATCHSIZE) -> BatchResult:
5653
r = BatchResult("create")
5754
for i in range(0, len(entities), batchsize):
58-
r += await self._create(entities[i:i+batchsize])
55+
r += await self._create(entities[i : i + batchsize])
5956
return r
60-
57+
6158
@rfc7807_error_handle_async
6259
async def _upsert(self, entities: Sequence[Entity], opt: Literal["replace", "update"] = "replace") -> BatchResult:
6360
params = {"options": opt} if opt else {}
6461
r = await self._session.post(
65-
f"{self.url}/upsert/",
66-
content=json.dumps([e for e in entities], cls=NgsiEncoder),
67-
params=params
62+
f"{self.url}/upsert/", content=json.dumps([e for e in entities], cls=NgsiEncoder), params=params
6863
)
6964
self._client.raise_for_status(r)
7065
if r.status_code == 201:
@@ -79,21 +74,21 @@ async def _upsert(self, entities: Sequence[Entity], opt: Literal["replace", "upd
7974
return BatchResult("upsert", success, errors)
8075

8176
@rfc7807_error_handle_async
82-
async def upsert(self, entities: Sequence[Entity], *, update: bool = False, batchsize: int = BATCHSIZE) -> BatchResult:
77+
async def upsert(
78+
self, entities: Sequence[Entity], *, update: bool = False, batchsize: int = BATCHSIZE
79+
) -> BatchResult:
8380
# default mode (without any option) is "replace", anyway always force the option
84-
opt = "update" if update else "replace"
81+
opt = "update" if update else "replace"
8582
r = BatchResult("upsert")
8683
for i in range(0, len(entities), batchsize):
87-
r += await self._upsert(entities[i:i+batchsize], opt)
84+
r += await self._upsert(entities[i : i + batchsize], opt)
8885
return r
8986

9087
@rfc7807_error_handle_async
9188
async def _update(self, entities: Sequence[Entity], opt: Literal["noOverwrite"] = None) -> BatchResult:
9289
params = {"options": opt} if opt else {}
9390
r = await self._session.post(
94-
f"{self.url}/update/",
95-
content=json.dumps([e for e in entities], cls=NgsiEncoder),
96-
params=params
91+
f"{self.url}/update/", content=json.dumps([e for e in entities], cls=NgsiEncoder), params=params
9792
)
9893
self._client.raise_for_status(r)
9994
if r.status_code == 204:
@@ -106,11 +101,13 @@ async def _update(self, entities: Sequence[Entity], opt: Literal["noOverwrite"]
106101
return BatchResult("update", success, errors)
107102

108103
@rfc7807_error_handle_async
109-
async def update(self, entities: Sequence[Entity], *, overwrite: bool = True, batchsize: int = BATCHSIZE) -> BatchResult:
104+
async def update(
105+
self, entities: Sequence[Entity], *, overwrite: bool = True, batchsize: int = BATCHSIZE
106+
) -> BatchResult:
110107
opt = "noOverwrite" if not overwrite else None
111108
r = BatchResult("update")
112109
for i in range(0, len(entities), batchsize):
113-
r += await self._update(entities[i:i+batchsize], opt)
110+
r += await self._update(entities[i : i + batchsize], opt)
114111
return r
115112

116113
@rfc7807_error_handle_async
@@ -132,5 +129,5 @@ async def _delete(self, entities: Sequence[EntityOrId]) -> BatchResult:
132129
async def delete(self, entities: Sequence[EntityOrId], batchsize: int = BATCHSIZE) -> BatchResult:
133130
r = BatchResult("delete")
134131
for i in range(0, len(entities), batchsize):
135-
r += await self._delete(entities[i:i+batchsize])
132+
r += await self._delete(entities[i : i + batchsize])
136133
return r

src/ngsildclient/api/asyn/client.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@
1414
import logging
1515
import httpx
1616
from httpx._types import AuthTypes
17-
from dataclasses import dataclass
18-
from typing import TYPE_CHECKING, Optional, Generator, List, Union, Callable
17+
from typing import TYPE_CHECKING, Generator, List, Union, Callable
1918
from math import ceil
2019

2120
from ...model.entity import Entity
22-
from ..constants import *
23-
from ..exceptions import *
21+
from ..constants import (
22+
NGSILD_DEFAULT_PORT,
23+
NGSILD_TEMPORAL_PORT,
24+
UA,
25+
NGSILD_PATH,
26+
ENDPOINT_ENTITIES,
27+
ENDPOINT_BATCH,
28+
ENDPOINT_TYPES,
29+
ENDPOINT_CONTEXTS,
30+
ENDPOINT_SUBSCRIPTIONS,
31+
NGSILD_BASEPATH,
32+
PAGINATION_LIMIT_MAX,
33+
)
2434
from .entities import Entities
2535
from .batch import Batch, BatchResult
2636
from .types import Types
@@ -201,15 +211,15 @@ async def create(self, *entities) -> Union[bool, BatchResult]:
201211
202212
Parameters
203213
----------
204-
entities :
214+
entities :
205215
Entities to be created by the Context Broker
206216
Either a single Entity, or a list of entities, or comma-separated entities
207217
208218
Returns
209219
-------
210220
Entity
211221
The entities successfully upserted
212-
"""
222+
"""
213223
if len(entities) == 1:
214224
if isinstance(entities[0], Entity):
215225
entity = entities[0]
@@ -236,7 +246,7 @@ async def get(
236246
The entity identifier or the entity instance
237247
ctx : str
238248
The context
239-
asdict : bool, optional
249+
asdict : bool
240250
If set (instead of returning an Entity) returns the raw API response (a Python dict that represents the JSON response), by default False
241251
242252
Returns
@@ -253,23 +263,22 @@ async def delete(self, *entities) -> Union[bool, BatchResult]:
253263
254264
Parameters
255265
----------
256-
entities :
266+
entities :
257267
Entities to be deleted by the Context Broker
258268
Either a single Entity, or a list of entities, or comma-separated entities
259269
260270
Returns
261271
-------
262272
Entity
263273
The entities successfully upserted
264-
"""
274+
"""
265275
if len(entities) == 1:
266276
if isinstance(entities[0], Entity):
267277
entity = entities[0]
268278
return await self.entities.delete(entity)
269279
else:
270280
entities = entities[0]
271281
return await self.batch.delete(entities)
272-
273282

274283
async def delete_from_file(self, filename: str) -> Union[bool, dict]:
275284
"""Delete in the broker all entities present in the JSON file.
@@ -307,20 +316,20 @@ async def upsert(self, *entities, update: bool = False) -> Union[bool, BatchResu
307316
308317
Parameters
309318
----------
310-
entities :
319+
entities :
311320
Entities to be upserted by the Context Broker
312321
Either a single Entity, or a list of entities, or comma-separated entities
313322
314323
update: bool
315324
For batch mode only.
316325
If set : "indicates that existing Entity content shall be updated".
317-
If not set : "indicates that all the existing Entity content shall be replaced (default mode)".
326+
If not set : "indicates that all the existing Entity content shall be replaced (default mode)".
318327
319328
Returns
320329
-------
321330
Entity
322331
The entities successfully upserted
323-
"""
332+
"""
324333
if len(entities) == 1:
325334
if isinstance(entities[0], Entity):
326335
entity = entities[0]
@@ -347,20 +356,20 @@ async def update(self, *entities, overwrite=True) -> Union[bool, BatchResult]:
347356
348357
Parameters
349358
----------
350-
entities :
359+
entities :
351360
Entities to be upserted by the Context Broker
352361
Either a single Entity, or a list of entities, or comma-separated entities
353362
354363
overwrite: bool
355364
For batch mode only.
356365
If set : Overwrite (default mode).
357-
If unset switch to "noOverwrite" mode : "indicates that no attribute overwrite shall be performed".
366+
If unset switch to "noOverwrite" mode : "indicates that no attribute overwrite shall be performed".
358367
359368
Returns
360369
-------
361370
Entity
362371
The entities successfully updated
363-
"""
372+
"""
364373
if len(entities) == 1:
365374
if isinstance(entities[0], Entity):
366375
entity = entities[0]

src/ngsildclient/api/asyn/entities.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Author: Fabien BATTELLO <fabien.battello@orange.com> et al.
1111

1212
from __future__ import annotations
13-
from typing import TYPE_CHECKING, Union, Optional, List
13+
from typing import TYPE_CHECKING, Union, List
1414
from httpx import Response
1515
import logging
1616

@@ -21,7 +21,7 @@
2121
from ..constants import JSONLD_CONTEXT, ENDPOINT_ENTITIES
2222
from ...model.entity import Entity
2323

24-
from ..exceptions import rfc7807_error_handle_async, NgsiApiError, NgsiAlreadyExistsError
24+
from ..exceptions import rfc7807_error_handle_async, NgsiAlreadyExistsError
2525

2626
logger = logging.getLogger(__name__)
2727

@@ -38,14 +38,13 @@ def to_broker_url(self, eid: Union[str, Entity]) -> str:
3838
@rfc7807_error_handle_async
3939
async def create(self, entity: Entity, skip: bool = False, overwrite: bool = False) -> bool:
4040
headers = {"Content-Type": "application/ld+json"}
41-
r: Response = await self._client.client.post(url=f"{self.url}/", headers=headers,
42-
content=entity.to_json())
41+
r: Response = await self._client.client.post(url=f"{self.url}/", headers=headers, content=entity.to_json())
4342
if r.status_code == 409: # already exists
4443
if skip:
4544
return False
4645
elif overwrite or self._client.overwrite:
4746
return self.update(entity, check_exists=False)
48-
if not self._client.ignore_errors:
47+
if not self._client.ignore_errors:
4948
self._client.raise_for_status(r)
5049
return True
5150

@@ -105,7 +104,7 @@ async def _query(
105104
self,
106105
type: str = None,
107106
q: str = None,
108-
gq: str = None,
107+
gq: str = None,
109108
ctx: str = None,
110109
limit: int = 0,
111110
offset: int = 0,
@@ -123,7 +122,7 @@ async def _query(
123122
if q:
124123
params["q"] = q
125124
if gq:
126-
params["geoQ"] = gq
125+
params["geoQ"] = gq
127126
headers = {
128127
"Accept": "application/ld+json",
129128
} # overrides session headers

src/ngsildclient/api/asyn/subscriptions.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ async def create(self, subscr: dict, raise_on_conflict: bool = True) -> bool:
4949
id_returned_from_broker = location.rsplit("/", 1)[-1]
5050
id = subscr.get("id")
5151
if id is not None and id != id_returned_from_broker:
52-
raise NgsiApiError(
53-
f"Broker returned wrong id. Expected={id} Returned={id_returned_from_broker}"
54-
)
52+
raise NgsiApiError(f"Broker returned wrong id. Expected={id} Returned={id_returned_from_broker}")
5553
return id_returned_from_broker
5654

5755
@rfc7807_error_handle_async
@@ -61,18 +59,14 @@ async def list(self, pattern: str = None, ctx: str = CORE_CONTEXT) -> Optional[d
6159
# "Content-Type": None,
6260
} # overrides session headers
6361
if ctx is not None:
64-
headers[
65-
"Link"
66-
] = f'<{ctx}>; rel="{CORE_CONTEXT}"; type="application/ld+json"'
62+
headers["Link"] = f'<{ctx}>; rel="{CORE_CONTEXT}"; type="application/ld+json"'
6763
r = await self._session.get(f"{self.url}")
6864
subscriptions = r.json()
6965
if pattern is not None:
7066
subscriptions = [
7167
x
7268
for x in subscriptions
73-
if re.search(
74-
pattern, x.get("name", "") + x.get("description", ""), re.IGNORECASE
75-
)
69+
if re.search(pattern, x.get("name", "") + x.get("description", ""), re.IGNORECASE)
7670
]
7771
return subscriptions
7872

@@ -98,9 +92,7 @@ async def conflicts(self, subscr: dict, ctx: str = CORE_CONTEXT) -> list:
9892
# "Content-Type": None,
9993
} # overrides session headers
10094
if ctx is not None:
101-
headers[
102-
"Link"
103-
] = f'<{ctx}>; rel="{CORE_CONTEXT}"; type="application/ld+json"'
95+
headers["Link"] = f'<{ctx}>; rel="{CORE_CONTEXT}"; type="application/ld+json"'
10496
r = await self._session.get(f"{self.url}")
10597
return [x for x in r.json() if Subscriptions._hash(x) == hashref]
10698

@@ -111,9 +103,7 @@ async def get(self, id: str, ctx: str = CORE_CONTEXT) -> dict:
111103
# "Content-Type": None,
112104
} # overrides session headers
113105
if ctx is not None:
114-
headers[
115-
"Link"
116-
] = f'<{ctx}>; rel="{CORE_CONTEXT}"; type="application/ld+json"'
106+
headers["Link"] = f'<{ctx}>; rel="{CORE_CONTEXT}"; type="application/ld+json"'
117107
r = await self._session.get(f"{self.url}/{id}", headers=headers)
118108
self._client.raise_for_status(r)
119109
return r.json()

src/ngsildclient/api/asyn/temporal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from __future__ import annotations
1313
from typing import TYPE_CHECKING, Union, List, Sequence, Generator, Callable, Awaitable
14-
from dataclasses import dataclass
1514
from datetime import timedelta
1615
from isodate import duration_isoformat
1716
from httpx import Response

0 commit comments

Comments
 (0)