You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This essentially does what other low-code sources do at build time, but at runtime,
161
-
with a user-provided manifest in the config. This better reflects what happens in the
162
-
connector builder.
158
+
"""
159
+
Create a declarative source with an injected manifest configuration.
160
+
161
+
This function dynamically creates a ConcurrentDeclarativeSource at runtime using a user-provided manifest, similar to how low-code sources are built. It validates the configuration and prepares the source for execution.
162
+
163
+
Parameters:
164
+
args (list[str]): Command-line arguments containing configuration, catalog, and state information.
165
+
166
+
Returns:
167
+
ConcurrentDeclarativeSource: A configured declarative source ready for sync operations.
168
+
169
+
Raises:
170
+
ValueError: If the configuration is invalid or missing required manifest information.
171
+
Exception: For any unexpected errors during source creation, with detailed error tracing.
172
+
173
+
Notes:
174
+
- Requires a configuration with an '__injected_declarative_manifest' key
175
+
- The manifest must be a dictionary
176
+
- Provides structured error reporting for configuration issues
Generically creates a custom component based on the model type and a class_name reference to the custom Python class being
985
-
instantiated. Only the model's additional properties that match the custom class definition are passed to the constructor
986
-
:param model: The Pydantic model of the custom component being created
987
-
:param config: The custom defined connector config
988
-
:return: The declarative component built from the Pydantic model to be used at runtime
984
+
Create a custom component from a Pydantic model with dynamic class instantiation.
985
+
986
+
This method dynamically creates a custom component by loading a class from a specified module and instantiating it with appropriate arguments. It handles complex scenarios such as nested components, type inference, and argument passing.
987
+
988
+
Parameters:
989
+
model (Any): A Pydantic model representing the custom component configuration.
990
+
config (Config): The connector configuration used for module and component resolution.
991
+
**kwargs (Any): Additional keyword arguments to override or supplement model arguments.
992
+
993
+
Returns:
994
+
Any: An instantiated custom component with resolved nested components and configurations.
995
+
996
+
Raises:
997
+
ValueError: If the component class cannot be loaded or instantiated.
998
+
TypeError: If arguments do not match the component's constructor signature.
999
+
1000
+
Notes:
1001
+
- Supports nested component creation
1002
+
- Performs type inference for component fields
1003
+
- Handles both dictionary and list-based component configurations
1004
+
- Prioritizes kwargs over model arguments in case of field collisions
"""Get a components module object based on the provided config.
1050
-
1051
-
If custom python components is provided, this will be loaded. Otherwise, we will
1052
-
attempt to load from the `components` module already imported.
1065
+
"""
1066
+
Get a components module object based on the provided configuration.
1067
+
1068
+
This method dynamically creates a module for custom Python components defined in the configuration. It ensures that custom components are defined in a module named 'components' and allows runtime module creation and execution.
1069
+
1070
+
Parameters:
1071
+
config (Config): A configuration object containing the custom components definition.
1072
+
1073
+
Returns:
1074
+
types.ModuleType: A dynamically created module containing the custom components.
1075
+
1076
+
Raises:
1077
+
ValueError: If no custom components are provided or if the components are not defined in a module named 'components'.
1078
+
1079
+
Notes:
1080
+
- Uses the special key '__injected_components_py' to retrieve custom component code
1081
+
- Creates a new module dynamically using types.ModuleType
1082
+
- Executes the provided Python code within the new module's namespace
1083
+
- Registers the module in sys.modules for future imports
"""Load and return the components module from the connector directory.
35
-
36
-
This assumes the components module is located at <connector_dir>/components.py.
34
+
"""
35
+
Load and return the components module from the connector directory.
36
+
37
+
This function attempts to load the 'components.py' module from the specified connector directory. It handles various potential failure scenarios during module loading.
38
+
39
+
Parameters:
40
+
connector_dir (Path): The root directory of the connector containing the components module.
41
+
42
+
Returns:
43
+
ModuleType | None: The loaded components module if successful, or None if:
44
+
- The components.py file does not exist
45
+
- The module specification cannot be created
46
+
- The module loader is unavailable
47
+
48
+
Raises:
49
+
No explicit exceptions are raised; returns None on failure.
Initialize the page increment with a starting page number of 1.
51
+
52
+
This method is called after the class initialization and sets the initial page
53
+
to 1 by invoking the parent class's __post_init__ method and then explicitly
54
+
setting the _page attribute.
55
+
56
+
Parameters:
57
+
parameters (Mapping[str, Any]): Configuration parameters passed during initialization.
58
+
"""
32
59
super().__post_init__(parameters)
33
60
self._page=1
34
61
35
62
defreset(self):
63
+
"""
64
+
Reset the page counter to the initial state.
65
+
66
+
This method resets the internal page counter to 1, allowing pagination to start over from the beginning. It is useful when you want to restart the pagination process for a new request or after completing a previous pagination cycle.
0 commit comments