From 62d37933c62627621f727692dbed7d028275fa96 Mon Sep 17 00:00:00 2001 From: blackmambaza <68467311+blackmambaza@users.noreply.github.com> Date: Thu, 12 Oct 2023 17:53:26 +0200 Subject: [PATCH] Improved the code quality to ease future maintenance (#248) Co-authored-by: Michael Wyatt --- .../proto/modelresponse_pb2_grpc.py | 42 ++++++++++--------- mii/server.py | 4 +- setup.py | 16 ++++--- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/mii/grpc_related/proto/modelresponse_pb2_grpc.py b/mii/grpc_related/proto/modelresponse_pb2_grpc.py index 95cfa825..2735b034 100644 --- a/mii/grpc_related/proto/modelresponse_pb2_grpc.py +++ b/mii/grpc_related/proto/modelresponse_pb2_grpc.py @@ -74,65 +74,67 @@ def __init__(self, channel): class ModelResponseServicer(object): """Missing associated documentation comment in .proto file.""" + ERROR_MSG = 'Method not implemented!' + def Terminate(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details(self.ERROR_MSG) + raise NotImplementedError(self.ERROR_MSG) def CreateSession(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details(self.ERROR_MSG) + raise NotImplementedError(self.ERROR_MSG) def DestroySession(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details(self.ERROR_MSG) + raise NotImplementedError(self.ERROR_MSG) def GeneratorReply(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details(self.ERROR_MSG) + raise NotImplementedError(self.ERROR_MSG) def ClassificationReply(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details(self.ERROR_MSG) + raise NotImplementedError(self.ERROR_MSG) def QuestionAndAnswerReply(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details(self.ERROR_MSG) + raise NotImplementedError(self.ERROR_MSG) def FillMaskReply(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details(self.ERROR_MSG) + raise NotImplementedError(self.ERROR_MSG) def TokenClassificationReply(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details(self.ERROR_MSG) + raise NotImplementedError(self.ERROR_MSG) def ConversationalReply(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details(self.ERROR_MSG) + raise NotImplementedError(self.ERROR_MSG) def Txt2ImgReply(self, request, context): """Missing associated documentation comment in .proto file.""" context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details(self.ERROR_MSG) + raise NotImplementedError(self.ERROR_MSG) def add_ModelResponseServicer_to_server(servicer, server): diff --git a/mii/server.py b/mii/server.py index d5201284..2a4f7a8e 100644 --- a/mii/server.py +++ b/mii/server.py @@ -89,9 +89,11 @@ def _launch_server_process(self, model_config, msg_server_type, ds_launch_str="", - server_args=[]): + server_args=None): launch_str = f"{sys.executable} -m mii.launch.multi_gpu_server" b64_config_str = config_to_b64_str(model_config) + if server_args is None: + server_args = [] server_args.append(f"--model-config {b64_config_str}") server_args_str = " ".join(server_args) cmd = f"{ds_launch_str} {launch_str} {server_args_str}".strip().split(" ") diff --git a/setup.py b/setup.py index 2675cc72..cf8af9ab 100644 --- a/setup.py +++ b/setup.py @@ -49,15 +49,19 @@ def command_exists(cmd): # Build specifiers like .devX can be added at install time. Otherwise, add the git hash. # example: MII_BUILD_STR=".dev20201022" python setup.py sdist bdist_wheel +MII_BUILD_STRING = 'MII_BUILD_STRING' +BUILD_FILE = 'build.txt' +mii_build_string = os.environ.get(MII_BUILD_STRING) + # Building wheel for distribution, update version file -if 'MII_BUILD_STRING' in os.environ: +if mii_build_string: # Build string env specified, probably building for distribution - with open('build.txt', 'w') as fd: - fd.write(os.environ.get('MII_BUILD_STRING')) - version_str += os.environ.get('MII_BUILD_STRING') -elif os.path.isfile('build.txt'): + with open(BUILD_FILE, 'w') as fd: + fd.write(mii_build_string) + version_str += mii_build_string +elif os.path.isfile(BUILD_FILE): # build.txt exists, probably installing from distribution - with open('build.txt', 'r') as fd: + with open(BUILD_FILE, 'r') as fd: version_str += fd.read().strip() else: # None of the above, probably installing from source