gromero commented on a change in pull request #9229:
URL: https://github.com/apache/tvm/pull/9229#discussion_r735795280



##########
File path: python/tvm/driver/tvmc/common.py
##########
@@ -520,3 +522,84 @@ def parse_configs(input_configs):
         pass_context_configs[name] = parsed_value
 
     return pass_context_configs
+
+
+def get_project_options(project_info):
+    options = project_info["project_options"]
+
+    options_by_method = defaultdict(list)
+    for opt in options:
+        # Get list of methods associated with an option based on the
+        # existance of a 'required' or 'optional' lists. API specification
+        # guarantees at least one of these lists will exist. If a list does
+        # not exist it's returned as None by the API.
+        metadata = ["required", "optional"]
+        om = [(opt[md], True if md == "required" else False) for md in 
metadata if opt[md]]
+        for methods, is_opt_required in om:
+            for method in methods:
+                name = opt["name"]
+
+                if opt["type"] == "bool":
+                    # TODO(gromero): Use only choices= and merge with non-bool 
options below
+                    option_choices_text = f"{name}={{true, false}}"
+
+                else:
+                    if opt["choices"]:
+                        choices = "{" + ", ".join(opt["choices"]) + "}"
+                    else:
+                        choices = opt["name"].upper()
+
+                    option_choices_text = f"{name}={choices}"
+
+                help_text = opt["help"][0].lower() + opt["help"][1:]
+                formatted_help_text = format_option(option_choices_text, 
help_text, is_opt_required)
+
+                option = {
+                    "name": opt["name"],
+                    "choices": opt["choices"],
+                    "help_text": formatted_help_text,
+                    "required": is_opt_required,
+                }
+                options_by_method[method].append(option)
+
+    return options_by_method
+
+
+def get_options(options):

Review comment:
       @mehrdadh added docstrings for `get_options` and other functions in 
https://github.com/apache/tvm/pull/9229/commits/7ed6635ba3f05c7ab9cbd319986b30ff9de63990
   
https://github.com/apache/tvm/pull/9229/commits/2ff3d802540be393820e7f3e8af64b47a795058e
   
https://github.com/apache/tvm/pull/9229/commits/377174558bd3adbf2f0ca4fbc00bec0abd9a1bb6
   
https://github.com/apache/tvm/pull/9229/commits/7534618bd051d372f57e6469c933bac66196fb94

##########
File path: python/tvm/driver/tvmc/common.py
##########
@@ -520,3 +522,84 @@ def parse_configs(input_configs):
         pass_context_configs[name] = parsed_value
 
     return pass_context_configs
+
+
+def get_project_options(project_info):
+    options = project_info["project_options"]
+
+    options_by_method = defaultdict(list)
+    for opt in options:
+        # Get list of methods associated with an option based on the
+        # existance of a 'required' or 'optional' lists. API specification
+        # guarantees at least one of these lists will exist. If a list does
+        # not exist it's returned as None by the API.
+        metadata = ["required", "optional"]
+        om = [(opt[md], True if md == "required" else False) for md in 
metadata if opt[md]]
+        for methods, is_opt_required in om:
+            for method in methods:
+                name = opt["name"]
+
+                if opt["type"] == "bool":
+                    # TODO(gromero): Use only choices= and merge with non-bool 
options below
+                    option_choices_text = f"{name}={{true, false}}"
+
+                else:
+                    if opt["choices"]:
+                        choices = "{" + ", ".join(opt["choices"]) + "}"
+                    else:
+                        choices = opt["name"].upper()
+
+                    option_choices_text = f"{name}={choices}"
+
+                help_text = opt["help"][0].lower() + opt["help"][1:]
+                formatted_help_text = format_option(option_choices_text, 
help_text, is_opt_required)
+
+                option = {
+                    "name": opt["name"],
+                    "choices": opt["choices"],
+                    "help_text": formatted_help_text,
+                    "required": is_opt_required,
+                }
+                options_by_method[method].append(option)
+
+    return options_by_method
+
+
+def get_options(options):

Review comment:
       @mehrdadh added docstrings for `get_options` and other functions in
   
   
https://github.com/apache/tvm/pull/9229/commits/7ed6635ba3f05c7ab9cbd319986b30ff9de63990
   
https://github.com/apache/tvm/pull/9229/commits/2ff3d802540be393820e7f3e8af64b47a795058e
   
https://github.com/apache/tvm/pull/9229/commits/377174558bd3adbf2f0ca4fbc00bec0abd9a1bb6
   
https://github.com/apache/tvm/pull/9229/commits/7534618bd051d372f57e6469c933bac66196fb94




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to