omnata-plugin-runtime 0.5.7a130__py3-none-any.whl → 0.5.7a132__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,11 @@ import threading
23
23
  import time
24
24
  import hashlib
25
25
  import requests
26
+ import pkgutil
27
+ import inspect
28
+ import importlib
29
+ import sys
30
+ import os
26
31
  from abc import ABC, abstractmethod
27
32
  from decimal import Decimal
28
33
  from functools import partial, wraps, reduce
@@ -2242,19 +2247,9 @@ def consumer_udtf(param_docs: Dict[str, Dict[str, Any]]):
2242
2247
  fields = {
2243
2248
  name: (param.annotation, param_docs.get(name, {}).get("default", param.default))
2244
2249
  for name, param in params.items()
2245
- if name != 'self' and name != 'mandatory_arg'
2250
+ if name != 'cls' and name != 'connection_parameters'
2246
2251
  }
2247
2252
 
2248
- DynamicModel = create_model('DynamicModel', **fields)
2249
-
2250
- # Attach the documentation to the function
2251
- original_process.__doc__ = original_process.__doc__ or ""
2252
- original_process.__doc__ += "\n\nArgs:\n"
2253
- for name, param in params.items():
2254
- if name != 'self':
2255
- doc = param_docs.get(name, {})
2256
- original_process.__doc__ += f" {name} ({param.annotation.__name__}): {doc.get('description', 'No description provided.')}\n"
2257
-
2258
2253
  @wraps(original_process)
2259
2254
  def wrapped_process(self, connection_parameters, *args, **kwargs):
2260
2255
  if connection_parameters is None:
@@ -2263,12 +2258,6 @@ def consumer_udtf(param_docs: Dict[str, Dict[str, Any]]):
2263
2258
  if not isinstance(connection_parameters, Dict):
2264
2259
  raise ValueError("The first argument must be an object, the result of calling PLUGIN_CONNECTION.")
2265
2260
 
2266
- try:
2267
- # Validate the arguments using the dynamic Pydantic model
2268
- validated_args = DynamicModel(**kwargs)
2269
- except ValidationError as e:
2270
- raise ValueError(f"Argument validation error: {e}")
2271
-
2272
2261
  # convert the connection parameters dictionary to a ConnectionConfigurationParameters object which includes the real secrets
2273
2262
  if 'other_secrets_name' in connection_parameters:
2274
2263
  # this is the new way, where the sync engine only passes the name of the secret
@@ -2285,7 +2274,7 @@ def consumer_udtf(param_docs: Dict[str, Dict[str, Any]]):
2285
2274
  parameters = ConnectionConfigurationParameters.model_validate(connection_parameters)
2286
2275
 
2287
2276
  # Pass the validated arguments to the function
2288
- return original_process(self, parameters, *args, **validated_args.dict())
2277
+ return original_process(self, parameters, *args, **kwargs)
2289
2278
  # Replace the original 'process' method with the wrapped version
2290
2279
  setattr(cls, 'process', wrapped_process)
2291
2280
 
@@ -2293,3 +2282,61 @@ def consumer_udtf(param_docs: Dict[str, Dict[str, Any]]):
2293
2282
 
2294
2283
  return class_decorator
2295
2284
 
2285
+ def find_classes_with_attribute(attribute_name: str,path:str = '.'):
2286
+ # Get the directory's absolute path
2287
+ current_dir = os.path.abspath(path)
2288
+
2289
+ # List to hold the classes that match the attribute
2290
+ matching_classes = []
2291
+
2292
+ # Iterate over all modules in the current directory
2293
+ for _, module_name, _ in pkgutil.iter_modules([current_dir]):
2294
+ # Import the module
2295
+ module = importlib.import_module(module_name)
2296
+
2297
+ # Iterate over all members of the module
2298
+ for name, obj in inspect.getmembers(module, inspect.isclass):
2299
+ # Check if the class has the specified attribute
2300
+ if hasattr(obj, attribute_name):
2301
+ matching_classes.append(obj)
2302
+
2303
+
2304
+ def consumer_udf(param_docs: Dict[str, Dict[str, Any]]):
2305
+ def decorator(func):
2306
+ sig = signature(func)
2307
+ params = sig.parameters
2308
+
2309
+ # Ensure the first argument is mandatory and positional
2310
+ if list(params.keys())[0] != 'connection_parameters':
2311
+ raise ValueError("The first argument should be 'connection_parameters'.")
2312
+
2313
+ @wraps(func)
2314
+ def wrapper(self, connection_parameters, *args, **kwargs):
2315
+ if connection_parameters is None:
2316
+ raise ValueError("Connection not found")
2317
+
2318
+ if not isinstance(connection_parameters, Dict):
2319
+ raise ValueError("The first argument must be an object, the result of calling PLUGIN_CONNECTION.")
2320
+
2321
+ # convert the connection parameters dictionary to a ConnectionConfigurationParameters object which includes the real secrets
2322
+ if 'other_secrets_name' in connection_parameters:
2323
+ # this is the new way, where the sync engine only passes the name of the secret
2324
+ oauth_secrets_name = None
2325
+ if 'oauth_secret_name' in connection_parameters:
2326
+ oauth_secrets_name = connection_parameters['oauth_secret_name']
2327
+ del connection_parameters['oauth_secret_name']
2328
+ result = get_secrets(oauth_secrets_name,connection_parameters['other_secrets_name'])
2329
+ connection_parameters['connection_secrets'] = result
2330
+ del connection_parameters['other_secrets_name']
2331
+ parameters = ConnectionConfigurationParameters.model_validate(connection_parameters)
2332
+ else:
2333
+ # deprecated way, where the sync engine passes the secrets directly
2334
+ parameters = ConnectionConfigurationParameters.model_validate(connection_parameters)
2335
+
2336
+ # Pass the validated arguments to the function
2337
+ return func(parameters, *args, **kwargs)
2338
+
2339
+ wrapper._is_omnata_consumer_udf = True
2340
+ return wrapper
2341
+
2342
+ return decorator
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.5.7a130
3
+ Version: 0.5.7a132
4
4
  Summary: Classes and common runtime components for building and running Omnata Plugins
5
5
  Author: James Weakley
6
6
  Author-email: james.weakley@omnata.com
@@ -3,10 +3,10 @@ omnata_plugin_runtime/api.py,sha256=FxzTqri4no8ClkOm7vZADG8aD47jcGBCTTQDEORmOJM,
3
3
  omnata_plugin_runtime/configuration.py,sha256=TI6GaVFhewVawBCaYN34GujY57qEP6q2nik4YpSEk5s,38100
4
4
  omnata_plugin_runtime/forms.py,sha256=GzSPEwcijsoPCXEO1mHiE8ylvX_KSE5TkhwqkymA2Ss,19755
5
5
  omnata_plugin_runtime/logging.py,sha256=bn7eKoNWvtuyTk7RTwBS9UARMtqkiICtgMtzq3KA2V0,3272
6
- omnata_plugin_runtime/omnata_plugin.py,sha256=jznVOLsrJbeta_50c21Ab2SNfwP79-WkXcBJ4BNHNkY,115179
6
+ omnata_plugin_runtime/omnata_plugin.py,sha256=eV1QKOqdxktkVB3ZEQPS7A9a9q7UOsyEhfyZ-JwV5iw,117231
7
7
  omnata_plugin_runtime/plugin_entrypoints.py,sha256=PFSLsYEVnWHVvSoOYTtTK2JY6pp6_8_eYP53WqLRiPE,27975
8
8
  omnata_plugin_runtime/rate_limiting.py,sha256=DVQ_bc-mVLBkrU1PTns1MWXhHiLpSB5HkWCcdePtJ2A,25611
9
- omnata_plugin_runtime-0.5.7a130.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
- omnata_plugin_runtime-0.5.7a130.dist-info/METADATA,sha256=bfYMu8hzQFu5-LW4ObOCXVy9KODwjxSOhPC3Zzbl87U,1985
11
- omnata_plugin_runtime-0.5.7a130.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
- omnata_plugin_runtime-0.5.7a130.dist-info/RECORD,,
9
+ omnata_plugin_runtime-0.5.7a132.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
+ omnata_plugin_runtime-0.5.7a132.dist-info/METADATA,sha256=YHhi631jWmg1ZBJuNsry--DCdhMxWVNynL2ZreqnS7w,1985
11
+ omnata_plugin_runtime-0.5.7a132.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
+ omnata_plugin_runtime-0.5.7a132.dist-info/RECORD,,