cognite-extractor-utils 7.5.6__tar.gz → 7.5.8__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.

Potentially problematic release.


This version of cognite-extractor-utils might be problematic. Click here for more details.

Files changed (51) hide show
  1. cognite_extractor_utils-7.5.8/.gitignore +157 -0
  2. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/PKG-INFO +30 -36
  3. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/README.md +3 -3
  4. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/__init__.py +1 -1
  5. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/_inner_util.py +1 -1
  6. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/base.py +4 -3
  7. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/configtools/_util.py +2 -1
  8. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/configtools/elements.py +1 -1
  9. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/configtools/loaders.py +10 -9
  10. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/exceptions.py +1 -1
  11. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/metrics.py +7 -6
  12. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/statestore/hashing.py +6 -6
  13. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/statestore/watermark.py +13 -13
  14. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/threading.py +1 -1
  15. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/configuration/exceptions.py +2 -5
  16. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/configuration/loaders.py +8 -8
  17. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/configuration/models.py +12 -12
  18. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/core/base.py +6 -9
  19. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/core/errors.py +1 -1
  20. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/core/restart_policy.py +1 -1
  21. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/core/runtime.py +10 -55
  22. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/core/tasks.py +1 -1
  23. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/scheduling/_scheduler.py +1 -1
  24. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader/_base.py +2 -1
  25. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader/assets.py +3 -2
  26. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader/data_modeling.py +3 -2
  27. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader/events.py +2 -2
  28. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader/files.py +13 -18
  29. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader/raw.py +3 -2
  30. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader/time_series.py +9 -8
  31. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader/upload_failure_handler.py +2 -2
  32. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader_extractor.py +7 -6
  33. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader_types.py +2 -1
  34. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/util.py +9 -8
  35. cognite_extractor_utils-7.5.8/pyproject.toml +119 -0
  36. cognite_extractor_utils-7.5.6/pyproject.toml +0 -102
  37. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/LICENSE +0 -0
  38. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/configtools/__init__.py +0 -0
  39. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/configtools/validators.py +0 -0
  40. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/py.typed +0 -0
  41. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/statestore/__init__.py +0 -0
  42. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/statestore/_base.py +0 -0
  43. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/__init__.py +0 -0
  44. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/configuration/__init__.py +0 -0
  45. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/core/__init__.py +0 -0
  46. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/core/_dto.py +0 -0
  47. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/core/_messaging.py +0 -0
  48. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/scheduling/__init__.py +0 -0
  49. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/unstable/scheduling/_schedules.py +0 -0
  50. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader/__init__.py +0 -0
  51. {cognite_extractor_utils-7.5.6 → cognite_extractor_utils-7.5.8}/cognite/extractorutils/uploader/_metrics.py +0 -0
@@ -0,0 +1,157 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Local test files
7
+ test.py
8
+ test.yaml
9
+ local-test.yaml
10
+ pyrightconfig.json
11
+
12
+ # Tokens, etc
13
+ token.txt
14
+
15
+ # Mac files
16
+ .DS_Store
17
+
18
+ # C extensions
19
+ *.so
20
+
21
+ # Distribution / packaging
22
+ .Python
23
+ build/
24
+ develop-eggs/
25
+ dist/
26
+ downloads/
27
+ eggs/
28
+ .eggs/
29
+ lib/
30
+ lib64/
31
+ parts/
32
+ sdist/
33
+ var/
34
+ wheels/
35
+ pip-wheel-metadata/
36
+ share/python-wheels/
37
+ *.egg-info/
38
+ .installed.cfg
39
+ *.egg
40
+ MANIFEST
41
+
42
+ # PyInstaller
43
+ # Usually these files are written by a python script from a template
44
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
45
+ *.manifest
46
+ *.spec
47
+
48
+ # Installer logs
49
+ pip-log.txt
50
+ pip-delete-this-directory.txt
51
+
52
+ # Unit test / coverage reports
53
+ htmlcov/
54
+ .tox/
55
+ .nox/
56
+ .coverage
57
+ .coverage.*
58
+ .cache
59
+ test-report.xml
60
+ nosetests.xml
61
+ coverage.xml
62
+ *.cover
63
+ .hypothesis/
64
+ .pytest_cache/
65
+
66
+ # Translations
67
+ *.mo
68
+ *.pot
69
+
70
+ # Django stuff:
71
+ *.log
72
+ local_settings.py
73
+ db.sqlite3
74
+ db.sqlite3-journal
75
+
76
+ # Flask stuff:
77
+ instance/
78
+ .webassets-cache
79
+
80
+ # Scrapy stuff:
81
+ .scrapy
82
+
83
+ # Sphinx documentation
84
+ docs/_build/
85
+
86
+ # PyBuilder
87
+ target/
88
+
89
+ # Jupyter Notebook
90
+ .ipynb_checkpoints
91
+
92
+ # IPython
93
+ profile_default/
94
+ ipython_config.py
95
+
96
+ # pyenv
97
+ .python-version
98
+
99
+ # pipenv
100
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
101
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
102
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
103
+ # install all needed dependencies.
104
+ #Pipfile.lock
105
+
106
+ uv.lock
107
+ poetry.lock
108
+
109
+ # pyenv
110
+ .python-version
111
+
112
+ # celery beat schedule file
113
+ celerybeat-schedule
114
+
115
+ # SageMath parsed files
116
+ *.sage.py
117
+
118
+ # Environments
119
+ .env
120
+ .venv
121
+ env/
122
+ venv/
123
+ ENV/
124
+ env.bak/
125
+ venv.bak/
126
+
127
+ # Spyder project settings
128
+ .spyderproject
129
+ .spyproject
130
+
131
+ # Rope project settings
132
+ .ropeproject
133
+
134
+ # mkdocs documentation
135
+ /site
136
+
137
+ # mypy
138
+ .mypy_cache/
139
+ .dmypy.json
140
+ dmypy.json
141
+
142
+ # Pyre type checker
143
+ .pyre/
144
+ =======
145
+
146
+ # jetbrains
147
+ .idea/
148
+
149
+ # vscode
150
+ .vscode/
151
+
152
+ # unit tests output
153
+ /test_dump_config.yml
154
+ /testfile-invalid.json
155
+ /testfile-startstop.json
156
+ /bar
157
+ /foo
@@ -1,39 +1,34 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: cognite-extractor-utils
3
- Version: 7.5.6
3
+ Version: 7.5.8
4
4
  Summary: Utilities for easier development of extractors for CDF
5
- Home-page: https://github.com/cognitedata/python-extractor-utils
5
+ Project-URL: repository, https://github.com/cognitedata/python-extractor-utils
6
+ Author-email: Mathias Lohne <mathias.lohne@cognite.com>
6
7
  License: Apache-2.0
7
- Author: Mathias Lohne
8
- Author-email: mathias.lohne@cognite.com
9
- Requires-Python: >=3.9.0,<4.0.0
10
- Classifier: License :: OSI Approved :: Apache Software License
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.9
13
- Classifier: Programming Language :: Python :: 3.10
14
- Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Programming Language :: Python :: 3.13
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Programming Language :: Python
11
+ Requires-Python: >=3.10
12
+ Requires-Dist: arrow>=1.0.0
13
+ Requires-Dist: azure-identity>=1.14.0
14
+ Requires-Dist: azure-keyvault-secrets>=4.7.0
15
+ Requires-Dist: cognite-sdk>=7.59.0
16
+ Requires-Dist: croniter>=6.0.0
17
+ Requires-Dist: dacite>=1.6.0
18
+ Requires-Dist: decorator>=5.1.1
19
+ Requires-Dist: httpx<1,>=0.27.0
20
+ Requires-Dist: jsonlines>=4.0.0
21
+ Requires-Dist: more-itertools>=10.0.0
22
+ Requires-Dist: orjson>=3.10.3
23
+ Requires-Dist: prometheus-client<=1.0.0,>=0.7.0
24
+ Requires-Dist: psutil>=6.0.0
25
+ Requires-Dist: pydantic>=2.8.2
26
+ Requires-Dist: pyhumps>=3.8.0
27
+ Requires-Dist: python-dotenv>=1.0.0
28
+ Requires-Dist: pyyaml<7,>=5.3.0
29
+ Requires-Dist: typing-extensions<5,>=3.7.4
17
30
  Provides-Extra: experimental
18
- Requires-Dist: arrow (>=1.0.0,<2.0.0)
19
- Requires-Dist: azure-identity (>=1.14.0,<2.0.0)
20
- Requires-Dist: azure-keyvault-secrets (>=4.7.0,<5.0.0)
21
- Requires-Dist: cognite-sdk (>=7.59.0,<8.0.0)
22
- Requires-Dist: croniter (>=6.0.0,<7.0.0)
23
- Requires-Dist: dacite (>=1.6.0,<2.0.0)
24
- Requires-Dist: decorator (>=5.1.1,<6.0.0)
25
- Requires-Dist: httpx (>=0.27.0,<0.28.0)
26
- Requires-Dist: jsonlines (>=4.0.0,<5.0.0)
27
- Requires-Dist: more-itertools (>=10.0.0,<11.0.0)
28
- Requires-Dist: orjson (>=3.10.3,<4.0.0)
29
- Requires-Dist: prometheus-client (>0.7.0,<=1.0.0)
30
- Requires-Dist: psutil (>=6.0.0,<7.0.0)
31
- Requires-Dist: pydantic (>=2.8.2,<3.0.0)
32
- Requires-Dist: pyhumps (>=3.8.0,<4.0.0)
33
- Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
34
- Requires-Dist: pyyaml (>=5.3.0,<7)
35
- Requires-Dist: typing-extensions (>=3.7.4,<5)
36
- Project-URL: Repository, https://github.com/cognitedata/python-extractor-utils
31
+ Requires-Dist: cognite-sdk-experimental; extra == 'experimental'
37
32
  Description-Content-Type: text/markdown
38
33
 
39
34
  <a href="https://cognite.com/">
@@ -96,10 +91,10 @@ as a code of conduct.
96
91
 
97
92
  ### Development environment
98
93
 
99
- We use [poetry](https://python-poetry.org) to manage dependencies and to administrate virtual environments. To develop
94
+ We use [uv](https://docs.astral.sh/uv/) to manage dependencies and to administrate virtual environments. To develop
100
95
  `extractor-utils`, follow the following steps to set up your local environment:
101
96
 
102
- 1. [Install poetry](https://python-poetry.org/docs/#installation) if you haven't already.
97
+ 1. [Install uv](https://docs.astral.sh/uv/getting-started/installation/) if you haven't already.
103
98
 
104
99
  2. Clone repository:
105
100
  ```
@@ -111,7 +106,7 @@ We use [poetry](https://python-poetry.org) to manage dependencies and to adminis
111
106
  ```
112
107
  4. Create virtual environment and install dependencies:
113
108
  ```
114
- $ poetry install
109
+ $ uv sync
115
110
  ```
116
111
 
117
112
 
@@ -127,4 +122,3 @@ $ poetry run pre-commit install
127
122
  Each public method, class and module should have docstrings. Docstrings are written in the [Google
128
123
  style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings). Please include unit and/or
129
124
  integration tests for submitted code, and remember to update the [changelog](./CHANGELOG.md).
130
-
@@ -58,10 +58,10 @@ as a code of conduct.
58
58
 
59
59
  ### Development environment
60
60
 
61
- We use [poetry](https://python-poetry.org) to manage dependencies and to administrate virtual environments. To develop
61
+ We use [uv](https://docs.astral.sh/uv/) to manage dependencies and to administrate virtual environments. To develop
62
62
  `extractor-utils`, follow the following steps to set up your local environment:
63
63
 
64
- 1. [Install poetry](https://python-poetry.org/docs/#installation) if you haven't already.
64
+ 1. [Install uv](https://docs.astral.sh/uv/getting-started/installation/) if you haven't already.
65
65
 
66
66
  2. Clone repository:
67
67
  ```
@@ -73,7 +73,7 @@ We use [poetry](https://python-poetry.org) to manage dependencies and to adminis
73
73
  ```
74
74
  4. Create virtual environment and install dependencies:
75
75
  ```
76
- $ poetry install
76
+ $ uv sync
77
77
  ```
78
78
 
79
79
 
@@ -16,7 +16,7 @@
16
16
  Cognite extractor utils is a Python package that simplifies the development of new extractors.
17
17
  """
18
18
 
19
- __version__ = "7.5.6"
19
+ __version__ = "7.5.8"
20
20
  from .base import Extractor
21
21
 
22
22
  __all__ = ["Extractor"]
@@ -40,7 +40,7 @@ class _DecimalEncoder(json.JSONEncoder):
40
40
  def default(self, obj: Any) -> dict[str, str]:
41
41
  if isinstance(obj, Decimal):
42
42
  return {"type": "decimal_encoded", "value": str(obj)}
43
- return super(_DecimalEncoder, self).default(obj)
43
+ return super().default(obj)
44
44
 
45
45
 
46
46
  class _DecimalDecoder(json.JSONDecoder):
@@ -15,11 +15,12 @@
15
15
  import logging
16
16
  import os
17
17
  import sys
18
+ from collections.abc import Callable
18
19
  from dataclasses import is_dataclass
19
20
  from enum import Enum
20
21
  from threading import Thread
21
22
  from types import TracebackType
22
- from typing import Any, Callable, Generic, Type, TypeVar
23
+ from typing import Any, Generic, TypeVar
23
24
 
24
25
  from dotenv import find_dotenv, load_dotenv
25
26
 
@@ -79,7 +80,7 @@ class Extractor(Generic[CustomConfigClass]):
79
80
  description: str,
80
81
  version: str | None = None,
81
82
  run_handle: RunHandle | None = None,
82
- config_class: Type[CustomConfigClass],
83
+ config_class: type[CustomConfigClass],
83
84
  metrics: BaseMetrics | None = None,
84
85
  use_default_state_store: bool = True,
85
86
  cancellation_token: CancellationToken | None = None,
@@ -322,7 +323,7 @@ class Extractor(Generic[CustomConfigClass]):
322
323
  return self
323
324
 
324
325
  def __exit__(
325
- self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
326
+ self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
326
327
  ) -> bool:
327
328
  """
328
329
  Shuts down the extractor. Makes sure states are preserved, that all uploads of data and metrics are done, etc.
@@ -13,8 +13,9 @@
13
13
  # limitations under the License.
14
14
  import base64
15
15
  import re
16
+ from collections.abc import Callable
16
17
  from pathlib import Path
17
- from typing import Any, Callable
18
+ from typing import Any
18
19
 
19
20
  from cryptography.hazmat.primitives import hashes
20
21
  from cryptography.hazmat.primitives import serialization as serialization
@@ -770,7 +770,7 @@ class CastableInt(int):
770
770
  floats and other types supported by standard int.
771
771
  """
772
772
 
773
- if not isinstance(value, (int, str, bytes)):
773
+ if not isinstance(value, int | str | bytes):
774
774
  raise ValueError(f"CastableInt cannot be created form value {value!r} of type {type(value)!r}.")
775
775
 
776
776
  return super().__new__(cls, value)
@@ -19,10 +19,11 @@ import logging
19
19
  import os
20
20
  import re
21
21
  import sys
22
+ from collections.abc import Callable, Iterable
22
23
  from enum import Enum
23
24
  from hashlib import sha256
24
25
  from pathlib import Path
25
- from typing import Any, Callable, Generic, Iterable, TextIO, Type, TypeVar, cast
26
+ from typing import Any, Generic, TextIO, TypeVar, cast
26
27
 
27
28
  import dacite
28
29
  import yaml
@@ -211,7 +212,7 @@ def _load_yaml_dict(
211
212
 
212
213
  def _load_yaml(
213
214
  source: TextIO | str,
214
- config_type: Type[CustomConfigClass],
215
+ config_type: type[CustomConfigClass],
215
216
  case_style: str = "hyphen",
216
217
  expand_envvars: bool = True,
217
218
  dict_manipulator: Callable[[dict[str, Any]], dict[str, Any]] = lambda x: x,
@@ -243,13 +244,13 @@ def _load_yaml(
243
244
  else:
244
245
  path = None
245
246
 
246
- def name(type_: Type) -> str:
247
+ def name(type_: type) -> str:
247
248
  return type_.__name__ if hasattr(type_, "__name__") else str(type_)
248
249
 
249
- def all_types(type_: Type) -> Iterable[Type]:
250
+ def all_types(type_: type) -> Iterable[type]:
250
251
  return type_.__args__ if hasattr(type_, "__args__") else [type_]
251
252
 
252
- if isinstance(e, (dacite.WrongTypeError, dacite.UnionMatchError)) and e.value is not None:
253
+ if isinstance(e, dacite.WrongTypeError | dacite.UnionMatchError) and e.value is not None:
253
254
  got_type = name(type(e.value))
254
255
  need_type = ", ".join(name(t) for t in all_types(e.field_type))
255
256
 
@@ -268,7 +269,7 @@ def _load_yaml(
268
269
 
269
270
  def load_yaml(
270
271
  source: TextIO | str,
271
- config_type: Type[CustomConfigClass],
272
+ config_type: type[CustomConfigClass],
272
273
  case_style: str = "hyphen",
273
274
  expand_envvars: bool = True,
274
275
  keyvault_loader: KeyVaultLoader | None = None,
@@ -346,7 +347,7 @@ def compile_patterns(ignore_patterns: list[str | IgnorePattern]) -> list[re.Patt
346
347
 
347
348
 
348
349
  class ConfigResolver(Generic[CustomConfigClass]):
349
- def __init__(self, config_path: str, config_type: Type[CustomConfigClass]):
350
+ def __init__(self, config_path: str, config_type: type[CustomConfigClass]):
350
351
  self.config_path = config_path
351
352
  self.config_type = config_type
352
353
 
@@ -356,7 +357,7 @@ class ConfigResolver(Generic[CustomConfigClass]):
356
357
  self._cognite_client: CogniteClient | None = None
357
358
 
358
359
  def _reload_file(self) -> None:
359
- with open(self.config_path, "r") as stream:
360
+ with open(self.config_path) as stream:
360
361
  self._config_text = stream.read()
361
362
 
362
363
  @property
@@ -401,7 +402,7 @@ class ConfigResolver(Generic[CustomConfigClass]):
401
402
 
402
403
  @classmethod
403
404
  def from_cli(
404
- cls, name: str, description: str, version: str, config_type: Type[CustomConfigClass]
405
+ cls, name: str, description: str, version: str, config_type: type[CustomConfigClass]
405
406
  ) -> "ConfigResolver":
406
407
  argument_parser = argparse.ArgumentParser(sys.argv[0], description=description)
407
408
  argument_parser.add_argument(
@@ -23,7 +23,7 @@ class InvalidConfigError(Exception):
23
23
  """
24
24
 
25
25
  def __init__(self, message: str, details: list[str] | None = None):
26
- super(InvalidConfigError, self).__init__()
26
+ super().__init__()
27
27
  self.message = message
28
28
  self.details = details
29
29
 
@@ -41,9 +41,10 @@ import logging
41
41
  import os
42
42
  import threading
43
43
  from abc import ABC, abstractmethod
44
+ from collections.abc import Callable
44
45
  from time import sleep
45
46
  from types import TracebackType
46
- from typing import Any, Callable, Type, TypeVar
47
+ from typing import Any, TypeVar
47
48
 
48
49
  import arrow
49
50
  import psutil
@@ -65,7 +66,7 @@ _metrics_singularities = {}
65
66
  T = TypeVar("T")
66
67
 
67
68
 
68
- def safe_get(cls: Type[T], *args: Any, **kwargs: Any) -> T:
69
+ def safe_get(cls: type[T], *args: Any, **kwargs: Any) -> T:
69
70
  """
70
71
  A factory for instances of metrics collections.
71
72
 
@@ -232,7 +233,7 @@ class AbstractMetricsPusher(ABC):
232
233
  return self
233
234
 
234
235
  def __exit__(
235
- self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
236
+ self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
236
237
  ) -> None:
237
238
  """
238
239
  Wraps around stop method, for use as context manager
@@ -269,7 +270,7 @@ class PrometheusPusher(AbstractMetricsPusher):
269
270
  thread_name: str | None = None,
270
271
  cancellation_token: CancellationToken | None = None,
271
272
  ):
272
- super(PrometheusPusher, self).__init__(push_interval, thread_name, cancellation_token)
273
+ super().__init__(push_interval, thread_name, cancellation_token)
273
274
 
274
275
  self.username = username
275
276
  self.job_name = job_name
@@ -345,7 +346,7 @@ class CognitePusher(AbstractMetricsPusher):
345
346
  thread_name: str | None = None,
346
347
  cancellation_token: CancellationToken | None = None,
347
348
  ):
348
- super(CognitePusher, self).__init__(push_interval, thread_name, cancellation_token)
349
+ super().__init__(push_interval, thread_name, cancellation_token)
349
350
 
350
351
  self.cdf_client = cdf_client
351
352
  self.asset = asset
@@ -409,7 +410,7 @@ class CognitePusher(AbstractMetricsPusher):
409
410
  datapoints: list[dict[str, str | int | list[Any] | Datapoints | DatapointsArray]] = []
410
411
 
411
412
  for metric in REGISTRY.collect():
412
- if type(metric) == Metric and metric.type in ["gauge", "counter"]:
413
+ if isinstance(metric, Metric) and metric.type in ["gauge", "counter"]:
413
414
  if len(metric.samples) == 0:
414
415
  continue
415
416
 
@@ -1,8 +1,9 @@
1
1
  import hashlib
2
2
  import json
3
3
  from abc import ABC
4
+ from collections.abc import Iterable, Iterator
4
5
  from types import TracebackType
5
- from typing import Any, Iterable, Iterator, Type
6
+ from typing import Any
6
7
 
7
8
  import orjson
8
9
 
@@ -66,8 +67,7 @@ class AbstractHashStateStore(_BaseStateStore, ABC):
66
67
 
67
68
  def __iter__(self) -> Iterator[str]:
68
69
  with self.lock:
69
- for key in self._local_state:
70
- yield key
70
+ yield from self._local_state
71
71
 
72
72
 
73
73
  class RawHashStateStore(AbstractHashStateStore):
@@ -169,7 +169,7 @@ class RawHashStateStore(AbstractHashStateStore):
169
169
 
170
170
  def __exit__(
171
171
  self,
172
- exc_type: Type[BaseException] | None,
172
+ exc_type: type[BaseException] | None,
173
173
  exc_val: BaseException | None,
174
174
  exc_tb: TracebackType | None,
175
175
  ) -> None:
@@ -214,7 +214,7 @@ class LocalHashStateStore(AbstractHashStateStore):
214
214
 
215
215
  with self.lock:
216
216
  try:
217
- with open(self._file_path, "r") as f:
217
+ with open(self._file_path) as f:
218
218
  self._local_state = json.load(f, cls=_DecimalDecoder)
219
219
  except FileNotFoundError:
220
220
  pass
@@ -243,7 +243,7 @@ class LocalHashStateStore(AbstractHashStateStore):
243
243
 
244
244
  def __exit__(
245
245
  self,
246
- exc_type: Type[BaseException] | None,
246
+ exc_type: type[BaseException] | None,
247
247
  exc_val: BaseException | None,
248
248
  exc_tb: TracebackType | None,
249
249
  ) -> None:
@@ -87,8 +87,9 @@ You can set a state store to automatically update on upload triggers from an upl
87
87
 
88
88
  import json
89
89
  from abc import ABC
90
+ from collections.abc import Callable, Iterator
90
91
  from types import TracebackType
91
- from typing import Any, Callable, Dict, Iterator, List, Tuple, Type, Union
92
+ from typing import Any
92
93
 
93
94
  from cognite.client import CogniteClient
94
95
  from cognite.client.exceptions import CogniteAPIError
@@ -126,10 +127,10 @@ class AbstractStateStore(_BaseStateStore, ABC):
126
127
  cancellation_token=cancellation_token,
127
128
  )
128
129
 
129
- self._local_state: Dict[str, Dict[str, Any]] = {}
130
- self._deleted: List[str] = []
130
+ self._local_state: dict[str, dict[str, Any]] = {}
131
+ self._deleted: list[str] = []
131
132
 
132
- def get_state(self, external_id: Union[str, List[str]]) -> Union[Tuple[Any, Any], List[Tuple[Any, Any]]]:
133
+ def get_state(self, external_id: str | list[str]) -> tuple[Any, Any] | list[tuple[Any, Any]]:
133
134
  """
134
135
  Get state(s) for external ID(s)
135
136
 
@@ -192,7 +193,7 @@ class AbstractStateStore(_BaseStateStore, ABC):
192
193
  self._local_state.pop(external_id, None)
193
194
  self._deleted.append(external_id)
194
195
 
195
- def post_upload_handler(self) -> Callable[[List[Dict[str, Union[str, DataPointList]]]], None]:
196
+ def post_upload_handler(self) -> Callable[[list[dict[str, str | DataPointList]]], None]:
196
197
  """
197
198
  Get a callable suitable for passing to a time series upload queue as post_upload_function, that will
198
199
  automatically update the states in this state store when that upload queue is uploading.
@@ -201,7 +202,7 @@ class AbstractStateStore(_BaseStateStore, ABC):
201
202
  A function that expands the current states with the values given
202
203
  """
203
204
 
204
- def callback(uploaded_points: List[Dict[str, Union[str, DataPointList]]]) -> None:
205
+ def callback(uploaded_points: list[dict[str, str | DataPointList]]) -> None:
205
206
  for time_series in uploaded_points:
206
207
  # Use CDF timestamps
207
208
  data_points = time_series["datapoints"]
@@ -238,10 +239,10 @@ class AbstractStateStore(_BaseStateStore, ABC):
238
239
 
239
240
  return False
240
241
 
241
- def __getitem__(self, external_id: str) -> Tuple[Any, Any]:
242
+ def __getitem__(self, external_id: str) -> tuple[Any, Any]:
242
243
  return self.get_state(external_id) # type: ignore # will not be list if input is single str
243
244
 
244
- def __setitem__(self, key: str, value: Tuple[Any, Any]) -> None:
245
+ def __setitem__(self, key: str, value: tuple[Any, Any]) -> None:
245
246
  self.set_state(external_id=key, low=value[0], high=value[1])
246
247
 
247
248
  def __contains__(self, external_id: str) -> bool:
@@ -251,8 +252,7 @@ class AbstractStateStore(_BaseStateStore, ABC):
251
252
  return len(self._local_state)
252
253
 
253
254
  def __iter__(self) -> Iterator[str]:
254
- for key in self._local_state:
255
- yield key
255
+ yield from self._local_state
256
256
 
257
257
 
258
258
  class RawStateStore(AbstractStateStore):
@@ -380,7 +380,7 @@ class RawStateStore(AbstractStateStore):
380
380
  return self
381
381
 
382
382
  def __exit__(
383
- self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
383
+ self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
384
384
  ) -> None:
385
385
  """
386
386
  Wraps around stop method, for use as context manager
@@ -430,7 +430,7 @@ class LocalStateStore(AbstractStateStore):
430
430
 
431
431
  with self.lock:
432
432
  try:
433
- with open(self._file_path, "r") as f:
433
+ with open(self._file_path) as f:
434
434
  self._local_state = json.load(f, cls=_DecimalDecoder)
435
435
  except FileNotFoundError:
436
436
  pass
@@ -460,7 +460,7 @@ class LocalStateStore(AbstractStateStore):
460
460
 
461
461
  def __exit__(
462
462
  self,
463
- exc_type: Type[BaseException] | None,
463
+ exc_type: type[BaseException] | None,
464
464
  exc_val: BaseException | None,
465
465
  exc_tb: TracebackType | None,
466
466
  ) -> None:
@@ -17,7 +17,7 @@ class CancellationToken:
17
17
  def __init__(self, condition: Condition | None = None) -> None:
18
18
  self._cv: Condition = condition or Condition()
19
19
  self._is_cancelled_int: bool = False
20
- self._parent: "CancellationToken" | None = None
20
+ self._parent: CancellationToken | None = None
21
21
 
22
22
  def __repr__(self) -> str:
23
23
  cls = self.__class__
@@ -1,6 +1,3 @@
1
- from typing import List, Optional
2
-
3
-
4
1
  class InvalidConfigError(Exception):
5
2
  """
6
3
  Exception thrown from ``load_yaml`` and ``load_yaml_dict`` if config file is invalid. This can be due to
@@ -10,8 +7,8 @@ class InvalidConfigError(Exception):
10
7
  * Unkown fields
11
8
  """
12
9
 
13
- def __init__(self, message: str, details: Optional[List[str]] = None):
14
- super(InvalidConfigError, self).__init__()
10
+ def __init__(self, message: str, details: list[str] | None = None):
11
+ super().__init__()
15
12
  self.message = message
16
13
  self.details = details
17
14