소스 검색

feat: add taipy run command

trgiangdo 1 년 전
부모
커밋
eaca6b8aad
2개의 변경된 파일67개의 추가작업 그리고 0개의 파일을 삭제
  1. 59 0
      src/taipy/_cli/_run_cli.py
  2. 8 0
      src/taipy/_entrypoint.py

+ 59 - 0
src/taipy/_cli/_run_cli.py

@@ -0,0 +1,59 @@
+# Copyright 2023 Avaiga Private Limited
+#
+# 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. See the License for the
+# specific language governing permissions and limitations under the License.
+
+import subprocess
+import sys
+
+from taipy._cli._base_cli import _CLI
+
+
+class _RunCLI:
+    @classmethod
+    def create_parser(cls):
+        run_parser = _CLI._add_subparser("run", help="Run a Taipy application.")
+        run_parser.add_argument(
+            "application_main_file",
+        )
+
+        sub_run_parser = run_parser.add_subparsers(title="subcommands")
+        sub_run_parser.add_parser(
+            "external-args",
+            help="""
+                Arguments defined after this keyword will be considered as external arguments
+                to be passed to the application
+            """,
+        )
+
+    @classmethod
+    def parse_arguments(cls):
+        args = _CLI._parse()
+
+        if getattr(args, "which", None) == "run":
+            all_args = sys.argv[3:]  # First 3 args are always (1) Python executable, (2) run, (3) Python file
+
+            external_args = []
+            try:
+                external_args_index = all_args.index("external-args")
+            except ValueError:
+                pass
+            else:
+                external_args.extend(all_args[external_args_index + 1 :])
+                all_args = all_args[:external_args_index]
+
+            taipy_args = [f"--taipy-{arg[2:]}" if arg.startswith("--") else arg for arg in all_args]
+
+            subprocess.run(
+                [sys.executable, args.application_main_file, *(taipy_args + external_args)],
+                stdout=sys.stdout,
+                stderr=sys.stdout,
+            )
+
+            sys.exit(0)

+ 8 - 0
src/taipy/_entrypoint.py

@@ -13,9 +13,12 @@ import os
 import sys
 
 from taipy._cli._base_cli import _CLI
+from taipy.core._core_cli import _CoreCLI
 from taipy.core._version._cli._version_cli import _VersionCLI
+from taipy.gui._gui_cli import _GuiCLI
 
 from ._cli._help_cli import _HelpCLI
+from ._cli._run_cli import _RunCLI
 from ._cli._scaffold_cli import _ScaffoldCLI
 from .version import _get_version
 
@@ -26,6 +29,10 @@ def _entrypoint():
 
     _CLI._parser.add_argument("-v", "--version", action="store_true", help="Print the current Taipy version and exit.")
 
+    _RunCLI.create_parser()
+    _GuiCLI.create_run_parser()
+    _CoreCLI.create_run_parser()
+
     _VersionCLI.create_parser()
     _ScaffoldCLI.create_parser()
     _HelpCLI.create_parser()
@@ -35,6 +42,7 @@ def _entrypoint():
         print(f"Taipy {_get_version()}")
         sys.exit(0)
 
+    _RunCLI.parse_arguments()
     _HelpCLI.parse_arguments()
     _VersionCLI.parse_arguments()
     _ScaffoldCLI.parse_arguments()