From 2cadcbebf92500ba0b4629ad4ef7985f1755d138 Mon Sep 17 00:00:00 2001 From: Joseph Calise Date: Thu, 1 Jun 2023 14:51:26 -0700 Subject: [PATCH 1/4] adding type annotations to functions --- ts/model_server.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ts/model_server.py b/ts/model_server.py index bf3a2e9b8f3..c7eca9babb6 100644 --- a/ts/model_server.py +++ b/ts/model_server.py @@ -2,6 +2,7 @@ File to define the entry point to Model Server """ +from ast import Dict import os import platform import re @@ -12,8 +13,8 @@ import psutil -from ts.arg_parser import ArgParser -from ts.version import __version__ +from arg_parser import ArgParser +from version import __version__ TS_NAMESPACE = "org.pytorch.serve.ModelServer" @@ -98,7 +99,8 @@ def start(): sys.exit(1) ts_conf_file = ts_config - platform_path_separator = {"Windows": "", "Darwin": ".:", "Linux": ".:"} + platform_path_separator = { + "Windows": "", "Darwin": ".:", "Linux": ".:"} class_path = "{}{}".format( platform_path_separator[platform.system()], os.path.join(ts_home, "ts", "frontend", "*"), From a685107c104121ff50722be033da502cc77e22b8 Mon Sep 17 00:00:00 2001 From: Joseph Calise Date: Thu, 1 Jun 2023 15:04:43 -0700 Subject: [PATCH 2/4] added type annotations and tested with mypy --- ts/model_server.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ts/model_server.py b/ts/model_server.py index c7eca9babb6..70eee8b5d07 100644 --- a/ts/model_server.py +++ b/ts/model_server.py @@ -2,7 +2,7 @@ File to define the entry point to Model Server """ -from ast import Dict +#from ast import Dict import os import platform import re @@ -10,16 +10,16 @@ import sys import tempfile from builtins import str - +from typing import Dict import psutil -from arg_parser import ArgParser -from version import __version__ +from ts.arg_parser import ArgParser +from ts.version import __version__ TS_NAMESPACE = "org.pytorch.serve.ModelServer" -def start(): +def start() -> None: """ This is the entry point for model server :return: @@ -203,7 +203,7 @@ def start(): print("start java frontend failed:", sys.exc_info()) -def load_properties(file_path): +def load_properties(file_path: str) -> Dict[str, str]: """ Read properties file into map. """ @@ -216,7 +216,6 @@ def load_properties(file_path): if len(pair) > 1: key = pair[0].strip() props[key] = pair[1].strip() - return props From a5daffd05c7c688bb26f37be4809833c5d8003a0 Mon Sep 17 00:00:00 2001 From: Joseph Calise Date: Thu, 1 Jun 2023 15:07:13 -0700 Subject: [PATCH 3/4] added type annotations and completed mypy tests --- ts/model_server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ts/model_server.py b/ts/model_server.py index 70eee8b5d07..0c18ac48cca 100644 --- a/ts/model_server.py +++ b/ts/model_server.py @@ -2,7 +2,6 @@ File to define the entry point to Model Server """ -#from ast import Dict import os import platform import re From 8abd283e4e0057fe3c4e5faa7468ea97c254a7f7 Mon Sep 17 00:00:00 2001 From: Joseph Calise Date: Thu, 1 Jun 2023 18:10:56 -0700 Subject: [PATCH 4/4] ts/model_server.py added to files --- mypy.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy.ini b/mypy.ini index fbc0f98dbc6..2e1165bdc18 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,7 +1,7 @@ [mypy] ; A good-first-issue is to add types to a file ; As you do start adding them in files and slowly make the excluded files empty -files = ts/context.py +files = ts/context.py, ts/model_server.py exclude = examples, binaries, ts_scripts, test, kubernetes, benchmarks, model-archiver, workflow-archiver, ts/tests, ts/utils