Skip to content

Commit 6ec693b

Browse files
authored
Add docstrings to every public mudule, class and function (#446)
1 parent ac184d5 commit 6ec693b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1629
-272
lines changed

cognite/extractorutils/_inner_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
"""
16-
A module containing utilities meant for use inside the extractor-utils package
16+
A module containing utilities meant for use inside the extractor-utils package.
1717
"""
1818

1919
import json

cognite/extractorutils/base.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Module containing the base class for extractors.
3+
"""
14
# Copyright 2021 Cognite AS
25
#
36
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,6 +38,10 @@
3538

3639

3740
class ReloadConfigAction(Enum):
41+
"""
42+
Enum for actions to take when a config file is reloaded.
43+
"""
44+
3845
DO_NOTHING = 1
3946
REPLACE_ATTRIBUTE = 2
4047
SHUTDOWN = 3
@@ -126,8 +133,10 @@ def __init__(
126133

127134
def _initial_load_config(self, override_path: str | None = None) -> None:
128135
"""
129-
Load a configuration file, either from the specified path, or by a path specified by the user in a command line
130-
arg. Will quit further execution of no path is given.
136+
Load a configuration file.
137+
138+
Either from the specified path, or from a path specified by the user in a command line arg. Will quit further
139+
execution if no path is specified.
131140
132141
Args:
133142
override_path: Optional override for file path, ie don't parse command line arguments
@@ -150,6 +159,11 @@ def config_refresher() -> None:
150159
Thread(target=config_refresher, name="ConfigReloader", daemon=True).start()
151160

152161
def reload_config_callback(self) -> None:
162+
"""
163+
If the reload_config_action was set to CALLBACK, this method will be called when the config file is reloaded.
164+
165+
This method should be overridden in subclasses to provide custom behavior when the config file is reloaded.
166+
"""
153167
self.logger.error("Method for reloading configs has not been overridden in subclass")
154168

155169
def _reload_config(self) -> None:
@@ -173,9 +187,11 @@ def _reload_config(self) -> None:
173187

174188
def _load_state_store(self) -> None:
175189
"""
176-
Searches through the config object for a StateStoreConfig. If found, it will use that configuration to generate
177-
a state store, if no such config is found it will either create a LocalStateStore or a NoStateStore depending
178-
on whether the ``use_default_state_store`` argument to the constructor was true or false.
190+
Searches through the config object for a StateStoreConfig.
191+
192+
If found, it will use that configuration to generate a state store, if no such config is found it will either
193+
create a LocalStateStore or a NoStateStore depending on whether the ``use_default_state_store`` argument to the
194+
constructor was true or false.
179195
180196
Either way, the state_store attribute is guaranteed to be set after calling this method.
181197
"""
@@ -213,7 +229,7 @@ def recursive_find_state_store(d: dict[str, Any]) -> StateStoreConfig | None:
213229

214230
def _report_success(self) -> None:
215231
"""
216-
Called on a successful exit of the extractor
232+
Called on a successful exit of the extractor.
217233
"""
218234
if self.extraction_pipeline:
219235
self.logger.info("Reporting new successful run")
@@ -227,7 +243,7 @@ def _report_success(self) -> None:
227243

228244
def _report_error(self, exception: BaseException) -> None:
229245
"""
230-
Called on an unsuccessful exit of the extractor
246+
Called on an unsuccessful exit of the extractor.
231247
232248
Args:
233249
exception: Exception object that caused the extractor to fail
@@ -250,7 +266,6 @@ def __enter__(self) -> "Extractor":
250266
Returns:
251267
self
252268
"""
253-
254269
if str(os.getenv("COGNITE_FUNCTION_RUNTIME", False)).lower() != "true":
255270
# Environment Variables
256271
env_file_found = load_dotenv(dotenv_path="./.env", override=True)
@@ -357,10 +372,11 @@ def __exit__(
357372

358373
def run(self) -> None:
359374
"""
360-
Run the extractor. Ensures that the Extractor is set up correctly (``run`` called within a ``with``) and calls
361-
the ``run_handle``.
375+
Run the extractor.
376+
377+
Ensures that the Extractor is set up correctly (``run`` called within a ``with``) and calls the ``run_handle``.
362378
363-
Can be overrided in subclasses.
379+
Can be overriden in subclasses.
364380
"""
365381
if not self.started:
366382
raise ValueError("You must run the extractor in a context manager")
@@ -371,12 +387,30 @@ def run(self) -> None:
371387

372388
@classmethod
373389
def get_current_config(cls) -> CustomConfigClass:
390+
"""
391+
Get the current configuration singleton.
392+
393+
Returns:
394+
The current configuration singleton
395+
396+
Raises:
397+
ValueError: If no configuration singleton has been created, meaning no config file has been loaded.
398+
"""
374399
if Extractor._config_singleton is None: # type: ignore
375400
raise ValueError("No config singleton created. Have a config file been loaded?")
376401
return Extractor._config_singleton # type: ignore
377402

378403
@classmethod
379404
def get_current_statestore(cls) -> AbstractStateStore:
405+
"""
406+
Get the current state store singleton.
407+
408+
Returns:
409+
The current state store singleton
410+
411+
Raises:
412+
ValueError: If no state store singleton has been created, meaning no state store has been loaded.
413+
"""
380414
if Extractor._statestore_singleton is None:
381415
raise ValueError("No state store singleton created. Have a state store been loaded?")
382416
return Extractor._statestore_singleton

cognite/extractorutils/configtools/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
# limitations under the License.
1414

1515
"""
16-
Module containing tools for loading and verifying config files, and a YAML loader to automatically serialize these
17-
dataclasses from a config file.
16+
Module containing tools for loading and verifying config files.
1817
1918
Configs are described as ``dataclass`` es, and use the ``BaseConfig`` class as a superclass to get a few things
2019
built-in: config version, Cognite project and logging. Use type hints to specify types, use the ``Optional`` type to

cognite/extractorutils/configtools/_util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727

2828
def _to_snake_case(dictionary: dict[str, Any], case_style: str) -> dict[str, Any]:
2929
"""
30-
Ensure that all keys in the dictionary follows the snake casing convention (recursively, so any sub-dictionaries are
31-
changed too).
30+
Ensure that all keys in the dictionary follows the snake casing convention.
31+
32+
This function will recursively fix any list or dictionaries. The input dictionary is never modified in place.
3233
3334
Args:
3435
dictionary: Dictionary to update.

0 commit comments

Comments
 (0)