From 440fb6128ebc2d2beba92dfa00a756bf7d1d878f Mon Sep 17 00:00:00 2001 From: Qu Date: Tue, 16 Jan 2024 14:12:37 +0800 Subject: [PATCH] fix(knext): fix bugs and add debug mode (#84) Co-authored-by: baifuyu --- python/knext/knext/client/builder.py | 9 + python/knext/knext/client/model/base.py | 7 +- python/knext/knext/command/exception.py | 27 ++- python/knext/knext/rest/__init__.py | 7 +- python/knext/knext/rest/api_client.py | 2 - python/knext/knext/rest/models/__init__.py | 7 +- .../pipeline/config/base_fusing_config.py | 8 +- .../config/new_instance_fusing_config.py | 188 ------------------ ...g_config.py => overwrite_fusing_config.py} | 28 +-- python/knext/setup.py | 1 + 10 files changed, 48 insertions(+), 236 deletions(-) delete mode 100644 python/knext/knext/rest/models/builder/pipeline/config/new_instance_fusing_config.py rename python/knext/knext/rest/models/builder/pipeline/config/{not_import_fusing_config.py => overwrite_fusing_config.py} (85%) diff --git a/python/knext/knext/client/builder.py b/python/knext/knext/client/builder.py index fd869635..66bfda53 100644 --- a/python/knext/knext/client/builder.py +++ b/python/knext/knext/client/builder.py @@ -96,6 +96,15 @@ class BuilderClient(Client): if kwargs.get("lead_to"): java_cmd.append("--leadTo") + if os.getenv("KNEXT_DEBUG_MODE", "False") == "True": + print_java_cmd = [ + cmd if not cmd.startswith("{") else f"'{cmd}'" for cmd in java_cmd + ] + print_java_cmd = [ + cmd if not cmd.count(";") > 0 else f"'{cmd}'" for cmd in print_java_cmd + ] + print(json.dumps(" ".join(print_java_cmd))[1:-1].replace("'", '"')) + subprocess.call(java_cmd) def query(self, job_inst_id: int): diff --git a/python/knext/knext/client/model/base.py b/python/knext/knext/client/model/base.py index 191587dd..276dad81 100644 --- a/python/knext/knext/client/model/base.py +++ b/python/knext/knext/client/model/base.py @@ -467,7 +467,12 @@ class BaseProperty(ABC): members = inspect.getmembers(self.__class__) for name, member in members: if isinstance(member, property): - setattr(self, name, getattr(other, name)) + if name == "sub_properties": + setattr( + self, name, [prop for _, prop in getattr(other, name).items()] + ) + else: + setattr(self, name, getattr(other, name)) def to_dict(self): """Returns the model properties as a dict""" diff --git a/python/knext/knext/command/exception.py b/python/knext/knext/command/exception.py index 8deedc38..02b803de 100644 --- a/python/knext/knext/command/exception.py +++ b/python/knext/knext/command/exception.py @@ -9,8 +9,7 @@ # Unless required by applicable law or agreed to in writing, software distributed under the License # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express # or implied. - - +import os from json import JSONDecodeError from typing import Any @@ -26,15 +25,15 @@ class _ApiExceptionHandler(Group): """Echo exceptions.""" def invoke(self, ctx: Context) -> Any: - return super().invoke(ctx) - # # TODO - # try: - # return super().invoke(ctx) - # except ApiException as api: - # try: - # body = json.loads(api.body) - # except JSONDecodeError: - # raise api - # click.secho("ERROR: " + body, fg="bright_red") - # except Exception as e: - # click.secho("ERROR: " + e.__str__(), fg="bright_red") + if os.getenv("KNEXT_DEBUG_MODE", "False") == "True": + return super().invoke(ctx) + try: + return super().invoke(ctx) + except ApiException as api: + try: + body = json.loads(api.body) + except JSONDecodeError: + raise api + click.secho("ERROR: " + body, fg="bright_red") + except Exception as e: + click.secho("ERROR: " + e.__str__(), fg="bright_red") diff --git a/python/knext/knext/rest/__init__.py b/python/knext/knext/rest/__init__.py index 8f3865e4..29206591 100644 --- a/python/knext/knext/rest/__init__.py +++ b/python/knext/knext/rest/__init__.py @@ -227,12 +227,9 @@ from knext.rest.models.builder.pipeline.config.operator_predicting_config import OperatorPredictingConfig, ) from knext.rest.models.builder.pipeline.config.predicting_config import PredictingConfig -from knext.rest.models.builder.pipeline.config.new_instance_fusing_config import ( - NewInstanceFusingConfig, +from knext.rest.models.builder.pipeline.config.overwrite_fusing_config import ( + OverwriteFusingConfig, ) from knext.rest.models.builder.pipeline.config.spg_type_mapping_node_configs import ( SpgTypeMappingNodeConfigs, ) -from knext.rest.models.builder.pipeline.config.not_import_fusing_config import ( - NotImportFusingConfig, -) diff --git a/python/knext/knext/rest/api_client.py b/python/knext/knext/rest/api_client.py index ec2b9fc5..1b893ccd 100644 --- a/python/knext/knext/rest/api_client.py +++ b/python/knext/knext/rest/api_client.py @@ -154,7 +154,6 @@ class ApiClient(object): _request_timeout=None, _host=None, ): - config = self.configuration # header parameters @@ -765,7 +764,6 @@ class ApiClient(object): class BaseApi(object): - api_client: ApiClient def __init__(self, api_client=None): diff --git a/python/knext/knext/rest/models/__init__.py b/python/knext/knext/rest/models/__init__.py index 0262b359..a920deda 100644 --- a/python/knext/knext/rest/models/__init__.py +++ b/python/knext/knext/rest/models/__init__.py @@ -204,12 +204,9 @@ from knext.rest.models.builder.pipeline.config.operator_predicting_config import OperatorPredictingConfig, ) from knext.rest.models.builder.pipeline.config.predicting_config import PredictingConfig -from knext.rest.models.builder.pipeline.config.new_instance_fusing_config import ( - NewInstanceFusingConfig, +from knext.rest.models.builder.pipeline.config.overwrite_fusing_config import ( + OverwriteFusingConfig, ) from knext.rest.models.builder.pipeline.config.spg_type_mapping_node_configs import ( SpgTypeMappingNodeConfigs, ) -from knext.rest.models.builder.pipeline.config.not_import_fusing_config import ( - NotImportFusingConfig, -) diff --git a/python/knext/knext/rest/models/builder/pipeline/config/base_fusing_config.py b/python/knext/knext/rest/models/builder/pipeline/config/base_fusing_config.py index dc1d2d2d..ccb880e3 100644 --- a/python/knext/knext/rest/models/builder/pipeline/config/base_fusing_config.py +++ b/python/knext/knext/rest/models/builder/pipeline/config/base_fusing_config.py @@ -46,12 +46,6 @@ class BaseFusingConfig(object): attribute_map = {"strategy_type": "strategyType", "fusing_type": "fusingType"} - discriminator_value_class_map = { - "OPERATOR": "OperatorFusingConfig", - "NEW_INSTANCE": "NewInstanceFusingConfig", - "NOT_IMPORT": "NotImportFusingConfig", - } - def __init__( self, strategy_type="FUSING", fusing_type=None, local_vars_configuration=None ): # noqa: E501 @@ -129,7 +123,7 @@ class BaseFusingConfig(object): raise ValueError( "Invalid value for `fusing_type`, must not be `None`" ) # noqa: E501 - allowed_values = ["OPERATOR", "NEW_INSTANCE", "NOT_IMPORT"] # noqa: E501 + allowed_values = ["OPERATOR", "OVERWRITE"] # noqa: E501 if ( self.local_vars_configuration.client_side_validation and fusing_type not in allowed_values diff --git a/python/knext/knext/rest/models/builder/pipeline/config/new_instance_fusing_config.py b/python/knext/knext/rest/models/builder/pipeline/config/new_instance_fusing_config.py deleted file mode 100644 index 900e21cb..00000000 --- a/python/knext/knext/rest/models/builder/pipeline/config/new_instance_fusing_config.py +++ /dev/null @@ -1,188 +0,0 @@ -# coding: utf-8 -# Copyright 2023 Ant Group CO., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software distributed under the License -# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express -# or implied. - -""" - knext - - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import pprint -import re # noqa: F401 - -import six - -from knext.rest.configuration import Configuration - - -class NewInstanceFusingConfig(object): - """NOTE: This class is auto generated by OpenAPI Generator. - Ref: https://openapi-generator.tech - - Do not edit the class manually. - """ - - """ - Attributes: - openapi_types (dict): The key is attribute name - and the value is attribute type. - attribute_map (dict): The key is attribute name - and the value is json key in definition. - """ - openapi_types = {"strategy_type": "str", "fusing_type": "str"} - - attribute_map = {"strategy_type": "strategyType", "fusing_type": "fusingType"} - - def __init__( - self, - strategy_type="FUSING", - fusing_type="NEW_INSTANCE", - local_vars_configuration=None, - ): # noqa: E501 - """NewInstanceFusingConfig - a model defined in OpenAPI""" # noqa: E501 - if local_vars_configuration is None: - local_vars_configuration = Configuration() - self.local_vars_configuration = local_vars_configuration - - self._strategy_type = None - self._fusing_type = None - self.discriminator = fusing_type - - self.strategy_type = strategy_type - self.fusing_type = fusing_type - - @property - def strategy_type(self): - """Gets the strategy_type of this NewInstanceFusingConfig. # noqa: E501 - - - :return: The strategy_type of this NewInstanceFusingConfig. # noqa: E501 - :rtype: str - """ - return self._strategy_type - - @strategy_type.setter - def strategy_type(self, strategy_type): - """Sets the strategy_type of this NewInstanceFusingConfig. - - - :param strategy_type: The strategy_type of this NewInstanceFusingConfig. # noqa: E501 - :type: str - """ - if ( - self.local_vars_configuration.client_side_validation - and strategy_type is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `strategy_type`, must not be `None`" - ) # noqa: E501 - allowed_values = ["LINKING", "FUSING", "PREDICTING"] # noqa: E501 - if ( - self.local_vars_configuration.client_side_validation - and strategy_type not in allowed_values - ): # noqa: E501 - raise ValueError( - "Invalid value for `strategy_type` ({0}), must be one of {1}".format( # noqa: E501 - strategy_type, allowed_values - ) - ) - - self._strategy_type = strategy_type - - @property - def fusing_type(self): - """Gets the fusing_type of this NewInstanceFusingConfig. # noqa: E501 - - - :return: The fusing_type of this NewInstanceFusingConfig. # noqa: E501 - :rtype: str - """ - return self._fusing_type - - @fusing_type.setter - def fusing_type(self, fusing_type): - """Sets the fusing_type of this NewInstanceFusingConfig. - - - :param fusing_type: The fusing_type of this NewInstanceFusingConfig. # noqa: E501 - :type: str - """ - if ( - self.local_vars_configuration.client_side_validation and fusing_type is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `fusing_type`, must not be `None`" - ) # noqa: E501 - allowed_values = ["OPERATOR", "NEW_INSTANCE"] # noqa: E501 - if ( - self.local_vars_configuration.client_side_validation - and fusing_type not in allowed_values - ): # noqa: E501 - raise ValueError( - "Invalid value for `fusing_type` ({0}), must be one of {1}".format( # noqa: E501 - fusing_type, allowed_values - ) - ) - - self._fusing_type = fusing_type - - def to_dict(self): - """Returns the model properties as a dict""" - result = {} - - for attr, _ in six.iteritems(self.openapi_types): - value = getattr(self, attr) - if isinstance(value, list): - result[attr] = list( - map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) - ) - elif hasattr(value, "to_dict"): - result[attr] = value.to_dict() - elif isinstance(value, dict): - result[attr] = dict( - map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") - else item, - value.items(), - ) - ) - else: - result[attr] = value - - return result - - def to_str(self): - """Returns the string representation of the model""" - return pprint.pformat(self.to_dict()) - - def __repr__(self): - """For `print` and `pprint`""" - return self.to_str() - - def __eq__(self, other): - """Returns true if both objects are equal""" - if not isinstance(other, NewInstanceFusingConfig): - return False - - return self.to_dict() == other.to_dict() - - def __ne__(self, other): - """Returns true if both objects are not equal""" - if not isinstance(other, NewInstanceFusingConfig): - return True - - return self.to_dict() != other.to_dict() diff --git a/python/knext/knext/rest/models/builder/pipeline/config/not_import_fusing_config.py b/python/knext/knext/rest/models/builder/pipeline/config/overwrite_fusing_config.py similarity index 85% rename from python/knext/knext/rest/models/builder/pipeline/config/not_import_fusing_config.py rename to python/knext/knext/rest/models/builder/pipeline/config/overwrite_fusing_config.py index 4634c1af..191de034 100644 --- a/python/knext/knext/rest/models/builder/pipeline/config/not_import_fusing_config.py +++ b/python/knext/knext/rest/models/builder/pipeline/config/overwrite_fusing_config.py @@ -28,7 +28,7 @@ import six from knext.rest.configuration import Configuration -class NotImportFusingConfig(object): +class OverwriteFusingConfig(object): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -49,10 +49,10 @@ class NotImportFusingConfig(object): def __init__( self, strategy_type="FUSING", - fusing_type="NOT_IMPORT", + fusing_type="OVERWRITE", local_vars_configuration=None, ): # noqa: E501 - """NotImportFusingConfig - a model defined in OpenAPI""" # noqa: E501 + """OverwriteFusingConfig - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() self.local_vars_configuration = local_vars_configuration @@ -66,20 +66,20 @@ class NotImportFusingConfig(object): @property def strategy_type(self): - """Gets the strategy_type of this NotImportFusingConfig. # noqa: E501 + """Gets the strategy_type of this OverwriteFusingConfig. # noqa: E501 - :return: The strategy_type of this NotImportFusingConfig. # noqa: E501 + :return: The strategy_type of this OverwriteFusingConfig. # noqa: E501 :rtype: str """ return self._strategy_type @strategy_type.setter def strategy_type(self, strategy_type): - """Sets the strategy_type of this NotImportFusingConfig. + """Sets the strategy_type of this OverwriteFusingConfig. - :param strategy_type: The strategy_type of this NotImportFusingConfig. # noqa: E501 + :param strategy_type: The strategy_type of this OverwriteFusingConfig. # noqa: E501 :type: str """ if ( @@ -104,20 +104,20 @@ class NotImportFusingConfig(object): @property def fusing_type(self): - """Gets the fusing_type of this NotImportFusingConfig. # noqa: E501 + """Gets the fusing_type of this OverwriteFusingConfig. # noqa: E501 - :return: The fusing_type of this NotImportFusingConfig. # noqa: E501 + :return: The fusing_type of this OverwriteFusingConfig. # noqa: E501 :rtype: str """ return self._fusing_type @fusing_type.setter def fusing_type(self, fusing_type): - """Sets the fusing_type of this NotImportFusingConfig. + """Sets the fusing_type of this OverwriteFusingConfig. - :param fusing_type: The fusing_type of this NotImportFusingConfig. # noqa: E501 + :param fusing_type: The fusing_type of this OverwriteFusingConfig. # noqa: E501 :type: str """ if ( @@ -126,7 +126,7 @@ class NotImportFusingConfig(object): raise ValueError( "Invalid value for `fusing_type`, must not be `None`" ) # noqa: E501 - allowed_values = ["OPERATOR", "NEW_INSTANCE", "NOT_IMPORT"] # noqa: E501 + allowed_values = ["OPERATOR", "OVERWRITE"] # noqa: E501 if ( self.local_vars_configuration.client_side_validation and fusing_type not in allowed_values @@ -175,14 +175,14 @@ class NotImportFusingConfig(object): def __eq__(self, other): """Returns true if both objects are equal""" - if not isinstance(other, NotImportFusingConfig): + if not isinstance(other, OverwriteFusingConfig): return False return self.to_dict() == other.to_dict() def __ne__(self, other): """Returns true if both objects are not equal""" - if not isinstance(other, NotImportFusingConfig): + if not isinstance(other, OverwriteFusingConfig): return True return self.to_dict() != other.to_dict() diff --git a/python/knext/setup.py b/python/knext/setup.py index 06d2be05..1f498966 100644 --- a/python/knext/setup.py +++ b/python/knext/setup.py @@ -41,6 +41,7 @@ __package_name__ = "{package_name}" __version__ = "{version}" from knext.common.env import init_env + init_env() """ wf.write(content)