comaniac commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r468122151



##########
File path: python/tvm/driver/tvmc/main.py
##########
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+TVMC - TVM driver command-line interface
+"""
+import argparse
+import logging
+import sys
+
+import pkg_resources
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+def add_help_parser(subparsers):
+    """ Include parser for 'help' subcommand """
+
+    parser = subparsers.add_parser("help", help="show help page")
+    # 'func' points to a function that will receive all the arguments
+    # provided by the user. This is the only required attribute
+    parser.set_defaults(func=drive_help)
+
+
+def drive_help(args):
+    """ Show help page """
+
+    print("This is a placeholder command. Args = {0}".format(args))
+
+
+
+def _main(argv):
+    """ TVM command line interface. """
+
+    parser = argparse.ArgumentParser(
+        prog='tvmc',
+        formatter_class=argparse.RawDescriptionHelpFormatter,
+        description="TVM compiler driver",
+        epilog=__doc__,
+    )
+    parser.add_argument(
+        "-v", "--verbose", action="count", default=0, help="increase verbosity"
+    )
+    parser.add_argument(
+        "--version", action="store_true", help="print the version and exit"
+    )
+
+    subparsers = parser.add_subparsers(title="commands")
+
+    add_help_parser(subparsers)

Review comment:
       Based on this I imagine we will have the following in the future:
   ```python
   add_help_parser(subparsers)
   add_compile_parser(subparsers)
   add_tune_parser(subparsers)
   # ...
   ```
   
   And maybe we will have something like `tvmc/compile.py`, and have `from 
compile import add_compile_parser` in this file.
   
   IIUC, we can setup a registration mechanism as follow, although I'm not sure 
if it's overkilled:
   
   In `main.py`:
   
   ```python
   REGISTERED_PARSER = []
   def register_parser(make_subparser):
       REGISTERED_PARSER.append(make_subparser)
       return make_subparser
   
   def _main(argv):
       subparser = parser.add_subparsers()
       for make_subparser in REGISTERED_PARSER:
         make_subparser(subparser)
   ```
   
   In `compile.py`:
   
   ```python
   from main import register_parser
   
   @register_parser
   def _compile_parser(main_subparser):
       subparser = main_subparser.add_parser('compile', help='...')
       # ...
   ```
   
   In this way, we don't need to touch `main.py` anymore when we add a new 
subparser.




----------------------------------------------------------------
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.

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


Reply via email to