Skip to content

Commit 115b2e8

Browse files
authored
Merge pull request #2380 from Avaiga/feature/enterprise#550-make-CreateCLI-class-expandable
Feature/enterprise#550 - Create _CreateCLIFactory to allow expanding the taipy create command
2 parents 31e22a0 + 5e927f4 commit 115b2e8

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

taipy/_entrypoint.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from importlib.util import find_spec
1515

1616
from taipy.common._cli._base_cli._taipy_parser import _TaipyParser
17-
from taipy.common._cli._create_cli import _CreateCLI
17+
from taipy.common._cli._create_cli_factory import _CreateCLIFactory
1818
from taipy.common._cli._help_cli import _HelpCLI
1919
from taipy.common._cli._run_cli import _RunCLI
2020
from taipy.core._cli._core_cli_factory import _CoreCLIFactory
@@ -42,14 +42,15 @@ def _entrypoint():
4242
_enterprise_entrypoint_initialize()
4343

4444
_core_cli = _CoreCLIFactory._build_cli()
45+
_create_cli = _CreateCLIFactory._build_cli()
4546

4647
_RunCLI.create_parser()
4748
_GuiCLI.create_run_parser()
4849
_core_cli.create_run_parser()
4950

5051
_VersionCLIFactory._build_cli().create_parser()
51-
_CreateCLI.generate_template_map()
52-
_CreateCLI.create_parser()
52+
_create_cli.generate_template_map()
53+
_create_cli.create_parser()
5354
_MigrateCLI.create_parser()
5455
_HelpCLI.create_parser()
5556

@@ -67,7 +68,7 @@ def _entrypoint():
6768
_HelpCLI.handle_command()
6869
_VersionCLIFactory._build_cli().handle_command()
6970
_MigrateCLI.handle_command()
70-
_CreateCLI.handle_command()
71+
_create_cli.handle_command()
7172

7273
_TaipyParser._remove_argument("help")
7374
_TaipyParser._parser.print_help()

taipy/common/_cli/_create_cli.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import pathlib
1313
import sys
14-
from typing import Dict, Optional
14+
from typing import Dict
1515

1616
from cookiecutter.exceptions import OutputDirExistsException
1717
from cookiecutter.main import cookiecutter
@@ -29,9 +29,8 @@ class _CreateCLI(_AbstractCLI):
2929
_ARGUMENTS = ["--application"]
3030

3131
@classmethod
32-
def generate_template_map(cls, template_path: Optional[pathlib.Path] = None):
33-
if not template_path:
34-
template_path = pathlib.Path(taipy.__file__).parent.resolve() / "templates"
32+
def generate_template_map(cls):
33+
template_path = pathlib.Path(taipy.__file__).parent.resolve() / "templates"
3534

3635
# Update the template map with the new templates but do not override the existing ones
3736
cls._template_map.update(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2021-2025 Avaiga Private Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
# the License. You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
# specific language governing permissions and limitations under the License.
11+
12+
from importlib import import_module
13+
from operator import attrgetter
14+
from typing import Type
15+
16+
from taipy.common._cli._base_cli._abstract_cli import _AbstractCLI
17+
18+
from ...core.common._check_dependencies import EnterpriseEditionUtils
19+
from ._create_cli import _CreateCLI
20+
21+
22+
class _CreateCLIFactory:
23+
@staticmethod
24+
def _build_cli() -> Type[_AbstractCLI]:
25+
if EnterpriseEditionUtils._using_enterprise():
26+
module = import_module(EnterpriseEditionUtils._TAIPY_ENTERPRISE_MODULE + ".templates._create_cli")
27+
create_cli = attrgetter("_CreateCLI")(module)
28+
else:
29+
create_cli = _CreateCLI
30+
31+
return create_cli

0 commit comments

Comments
 (0)