1
0
Эх сурвалжийг харах

feat: allow custom templates on enterprise

trgiangdo 1 жил өмнө
parent
commit
af9ce4ffb1

+ 18 - 4
taipy/_cli/_scaffold_cli.py

@@ -11,6 +11,7 @@
 
 import pathlib
 import sys
+from typing import Dict, Optional
 
 from cookiecutter.exceptions import OutputDirExistsException
 from cookiecutter.main import cookiecutter
@@ -22,12 +23,25 @@ from ._base_cli._taipy_parser import _TaipyParser
 
 
 class _ScaffoldCLI(_AbstractCLI):
-    __TAIPY_PATH = pathlib.Path(taipy.__file__).parent.resolve() / "templates"
-    _TEMPLATE_MAP = {str(x.name): str(x) for x in __TAIPY_PATH.iterdir() if x.is_dir() and not x.name.startswith("_")}
+    _template_map: Dict[str, str] = {}
 
     _COMMAND_NAME = "create"
     _ARGUMENTS = ["--template"]
 
+    @classmethod
+    def generate_template_map(cls, template_path: Optional[pathlib.Path] = None):
+        if not template_path:
+            template_path = pathlib.Path(taipy.__file__).parent.resolve() / "templates"
+
+        # Update the template map with the new templates but do not override the existing ones
+        cls._template_map.update(
+            {
+                str(x.name): str(x)
+                for x in template_path.iterdir()
+                if x.is_dir() and not x.name.startswith("_") and x.name not in cls._template_map
+            }
+        )
+
     @classmethod
     def create_parser(cls):
         create_parser = _TaipyParser._add_subparser(
@@ -36,7 +50,7 @@ class _ScaffoldCLI(_AbstractCLI):
         )
         create_parser.add_argument(
             "--template",
-            choices=list(cls._TEMPLATE_MAP.keys()),
+            choices=list(cls._template_map.keys()),
             default="default",
             help="The Taipy template to create new application.",
         )
@@ -47,7 +61,7 @@ class _ScaffoldCLI(_AbstractCLI):
         if not args:
             return
         try:
-            cookiecutter(cls._TEMPLATE_MAP[args.template])
+            cookiecutter(cls._template_map[args.template])
         except OutputDirExistsException as err:
             error_msg = f"{str(err)}. Please remove the existing directory or provide a new folder name."
             print(error_msg)  # noqa: T201

+ 8 - 2
taipy/_entrypoint.py

@@ -36,19 +36,25 @@ def _entrypoint():
         help="Print the current Taipy version and exit.",
     )
 
+    if find_spec("taipy.enterprise"):
+        from taipy.enterprise._entrypoint import _entrypoint_initialize as _enterprise_entrypoint_initialize
+
+        _enterprise_entrypoint_initialize()
+
     _RunCLI.create_parser()
     _GuiCLI.create_run_parser()
     _CoreCLI.create_run_parser()
 
     _VersionCLI.create_parser()
+    _ScaffoldCLI.generate_template_map()
     _ScaffoldCLI.create_parser()
     _MigrateCLI.create_parser()
     _HelpCLI.create_parser()
 
     if find_spec("taipy.enterprise"):
-        from taipy.enterprise._entrypoint import _entrypoint as _enterprise_entrypoint
+        from taipy.enterprise._entrypoint import _entrypoint_handling as _enterprise_entrypoint_handling
 
-        _enterprise_entrypoint()
+        _enterprise_entrypoint_handling()
 
     args, _ = _TaipyParser._parser.parse_known_args()
     if args.version: