From eee4f5b4cff587f1d41c9d27ff8bd1935f94fce5 Mon Sep 17 00:00:00 2001 From: Robin Andersson Date: Wed, 18 Oct 2023 11:09:34 +0200 Subject: [PATCH] [HWORKS-798] Add **kwargs to python client libraries (#205) --- python/__init__.py | 2 +- python/hsml/deployable_component.py | 1 + python/hsml/deployable_component_logs.py | 2 +- python/hsml/deployment.py | 6 +++++- python/hsml/inference_batcher.py | 1 + python/hsml/inference_endpoint.py | 2 +- python/hsml/inference_logger.py | 1 + python/hsml/kafka_topic.py | 1 + python/hsml/model.py | 1 + python/hsml/model_registry.py | 1 + python/hsml/model_schema.py | 1 + python/hsml/model_serving.py | 7 ++++++- python/hsml/predictor.py | 1 + python/hsml/predictor_state.py | 1 + python/hsml/predictor_state_condition.py | 1 + python/hsml/python/model.py | 1 + python/hsml/resources.py | 1 + python/hsml/schema.py | 1 + python/hsml/sklearn/model.py | 1 + python/hsml/tag.py | 1 + python/hsml/tensorflow/model.py | 1 + python/hsml/torch/model.py | 1 + python/hsml/transformer.py | 1 + python/setup.py | 9 +++------ 24 files changed, 35 insertions(+), 11 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index 075bc32ec..ff0a6f046 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -12,4 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# \ No newline at end of file +# diff --git a/python/hsml/deployable_component.py b/python/hsml/deployable_component.py index f4028d719..6f9406ab0 100644 --- a/python/hsml/deployable_component.py +++ b/python/hsml/deployable_component.py @@ -33,6 +33,7 @@ def __init__( script_file: Optional[str] = None, resources: Optional[Resources] = None, inference_batcher: Optional[Union[InferenceBatcher, dict]] = None, + **kwargs, ): self._script_file = script_file self._resources = resources diff --git a/python/hsml/deployable_component_logs.py b/python/hsml/deployable_component_logs.py index 50e2821fc..dc25ab4f3 100644 --- a/python/hsml/deployable_component_logs.py +++ b/python/hsml/deployable_component_logs.py @@ -29,7 +29,7 @@ class DeployableComponentLogs: `DeployableComponentLogs`. Server logs of a deployable component """ - def __init__(self, instance_name: str, content: str): + def __init__(self, instance_name: str, content: str, **kwargs): self._instance_name = instance_name self._content = content self._created_at = datetime.now() diff --git a/python/hsml/deployment.py b/python/hsml/deployment.py index 8f4af7eb0..eb68300ea 100644 --- a/python/hsml/deployment.py +++ b/python/hsml/deployment.py @@ -34,7 +34,11 @@ class Deployment: """Metadata object representing a deployment in Model Serving.""" def __init__( - self, predictor, name: Optional[str] = None, description: Optional[str] = None + self, + predictor, + name: Optional[str] = None, + description: Optional[str] = None, + **kwargs, ): self._predictor = predictor self._description = description diff --git a/python/hsml/inference_batcher.py b/python/hsml/inference_batcher.py index 608843f1a..87455da00 100644 --- a/python/hsml/inference_batcher.py +++ b/python/hsml/inference_batcher.py @@ -40,6 +40,7 @@ def __init__( max_batch_size: Optional[int] = None, max_latency: Optional[int] = None, timeout: Optional[int] = None, + **kwargs, ): self._enabled = enabled if enabled is not None else INFERENCE_BATCHER.ENABLED self._max_batch_size = max_batch_size if max_batch_size is not None else None diff --git a/python/hsml/inference_endpoint.py b/python/hsml/inference_endpoint.py index 519ee36af..a832ca203 100644 --- a/python/hsml/inference_endpoint.py +++ b/python/hsml/inference_endpoint.py @@ -30,7 +30,7 @@ class InferenceEndpointPort: `InferenceEndpointPort`. Port of an inference endpoint. """ - def __init__(self, name: str, number: int): + def __init__(self, name: str, number: int, **kwargs): self._name = name self._number = number diff --git a/python/hsml/inference_logger.py b/python/hsml/inference_logger.py index d8858bd7c..b596a087d 100644 --- a/python/hsml/inference_logger.py +++ b/python/hsml/inference_logger.py @@ -37,6 +37,7 @@ def __init__( self, kafka_topic: Optional[Union[KafkaTopic, dict]] = DEFAULT, mode: Optional[str] = INFERENCE_LOGGER.MODE_ALL, + **kwargs, ): self._kafka_topic = util.get_obj_from_json(kafka_topic, KafkaTopic) self._mode = self._validate_mode(mode) or ( diff --git a/python/hsml/kafka_topic.py b/python/hsml/kafka_topic.py index 5052a776b..c1ab893ef 100644 --- a/python/hsml/kafka_topic.py +++ b/python/hsml/kafka_topic.py @@ -29,6 +29,7 @@ def __init__( name: str = KAFKA_TOPIC.CREATE, num_replicas: Optional[int] = None, num_partitions: Optional[int] = None, + **kwargs, ): self._name = name self._num_replicas, self._num_partitions = self._validate_topic_config( diff --git a/python/hsml/model.py b/python/hsml/model.py index 28c72b65c..2f9c4e476 100644 --- a/python/hsml/model.py +++ b/python/hsml/model.py @@ -51,6 +51,7 @@ def __init__( input_example=None, framework=None, model_registry_id=None, + **kwargs, ): self._id = id self._name = name diff --git a/python/hsml/model_registry.py b/python/hsml/model_registry.py index bea6a5a75..296b3e73d 100644 --- a/python/hsml/model_registry.py +++ b/python/hsml/model_registry.py @@ -34,6 +34,7 @@ def __init__( project_id, model_registry_id, shared_registry_project_name=None, + **kwargs, ): self._project_name = project_name self._project_id = project_id diff --git a/python/hsml/model_schema.py b/python/hsml/model_schema.py index 13be1dd8f..697c0bd37 100644 --- a/python/hsml/model_schema.py +++ b/python/hsml/model_schema.py @@ -35,6 +35,7 @@ def __init__( self, input_schema: Optional[Schema] = None, output_schema: Optional[Schema] = None, + **kwargs, ): if input_schema is not None: self.input_schema = input_schema diff --git a/python/hsml/model_serving.py b/python/hsml/model_serving.py index 0e9946dca..5851fa4f6 100644 --- a/python/hsml/model_serving.py +++ b/python/hsml/model_serving.py @@ -32,7 +32,12 @@ class ModelServing: DEFAULT_VERSION = 1 - def __init__(self, project_name: str, project_id: int): + def __init__( + self, + project_name: str, + project_id: int, + **kwargs, + ): self._project_name = project_name self._project_id = project_id diff --git a/python/hsml/predictor.py b/python/hsml/predictor.py index 05c4faf2d..0feabec61 100644 --- a/python/hsml/predictor.py +++ b/python/hsml/predictor.py @@ -52,6 +52,7 @@ def __init__( description: Optional[str] = None, created_at: Optional[str] = None, creator: Optional[str] = None, + **kwargs, ): serving_tool = ( self._validate_serving_tool(serving_tool) diff --git a/python/hsml/predictor_state.py b/python/hsml/predictor_state.py index d527c92fa..eff8a84b7 100644 --- a/python/hsml/predictor_state.py +++ b/python/hsml/predictor_state.py @@ -34,6 +34,7 @@ def __init__( deployed: Optional[bool], condition: Optional[PredictorStateCondition], status: str, + **kwargs, ): self._available_predictor_instances = available_predictor_instances self._available_transformer_instances = available_transformer_instances diff --git a/python/hsml/predictor_state_condition.py b/python/hsml/predictor_state_condition.py index f05577799..63db1f085 100644 --- a/python/hsml/predictor_state_condition.py +++ b/python/hsml/predictor_state_condition.py @@ -28,6 +28,7 @@ def __init__( type: str, status: Optional[bool] = None, reason: Optional[str] = None, + **kwargs, ): self._type = type self._status = status diff --git a/python/hsml/python/model.py b/python/hsml/python/model.py index e67c2fbed..0bdd00d37 100644 --- a/python/hsml/python/model.py +++ b/python/hsml/python/model.py @@ -40,6 +40,7 @@ def __init__( training_dataset=None, input_example=None, model_registry_id=None, + **kwargs, ): super().__init__( id, diff --git a/python/hsml/resources.py b/python/hsml/resources.py index dc2872aa3..c2f642f17 100644 --- a/python/hsml/resources.py +++ b/python/hsml/resources.py @@ -40,6 +40,7 @@ def __init__( cores: int, memory: int, gpus: int, + **kwargs, ): self._cores = cores self._memory = memory diff --git a/python/hsml/schema.py b/python/hsml/schema.py index bad972a35..60c0c16b1 100644 --- a/python/hsml/schema.py +++ b/python/hsml/schema.py @@ -44,6 +44,7 @@ def __init__( list, ] ] = None, + **kwargs, ): # A tensor schema is either ndarray of a list containing name, type and shape dicts if isinstance(object, numpy.ndarray) or ( diff --git a/python/hsml/sklearn/model.py b/python/hsml/sklearn/model.py index f30091083..cb2b55bde 100644 --- a/python/hsml/sklearn/model.py +++ b/python/hsml/sklearn/model.py @@ -40,6 +40,7 @@ def __init__( training_dataset=None, input_example=None, model_registry_id=None, + **kwargs, ): super().__init__( id, diff --git a/python/hsml/tag.py b/python/hsml/tag.py index 5c0a2cc74..4119a00aa 100644 --- a/python/hsml/tag.py +++ b/python/hsml/tag.py @@ -31,6 +31,7 @@ def __init__( items=None, count=None, type=None, + **kwargs, ): self._name = name self._value = value diff --git a/python/hsml/tensorflow/model.py b/python/hsml/tensorflow/model.py index 8c6fa0d9f..060e65315 100644 --- a/python/hsml/tensorflow/model.py +++ b/python/hsml/tensorflow/model.py @@ -40,6 +40,7 @@ def __init__( training_dataset=None, input_example=None, model_registry_id=None, + **kwargs, ): super().__init__( id, diff --git a/python/hsml/torch/model.py b/python/hsml/torch/model.py index 113792aec..5c7d69f53 100644 --- a/python/hsml/torch/model.py +++ b/python/hsml/torch/model.py @@ -40,6 +40,7 @@ def __init__( training_dataset=None, input_example=None, model_registry_id=None, + **kwargs, ): super().__init__( id, diff --git a/python/hsml/transformer.py b/python/hsml/transformer.py index b498e71bf..7fd4e78eb 100644 --- a/python/hsml/transformer.py +++ b/python/hsml/transformer.py @@ -30,6 +30,7 @@ def __init__( self, script_file: str, resources: Optional[Union[TransformerResources, dict]] = None, # base + **kwargs, ): resources = ( self._validate_resources( diff --git a/python/setup.py b/python/setup.py index 0d180d078..4af853fbe 100644 --- a/python/setup.py +++ b/python/setup.py @@ -40,13 +40,10 @@ def read(fname): "numpy", "pyjks", "mock", - "tqdm" + "tqdm", ], extras_require={ - "dev": [ - "pytest", - "flake8", - "black"], + "dev": ["pytest", "flake8", "black"], "docs": [ "mkdocs==1.3.0", "mkdocs-material==8.2.8", @@ -56,7 +53,7 @@ def read(fname): "markdown-include", "markdown==3.3.7", "pymdown-extensions", - ] + ], }, author="Logical Clocks AB", author_email="robin@logicalclocks.com",