Skip to content

Commit 0bec16d

Browse files
committed
✨ install deps by custom package manager
1 parent cb3dba3 commit 0bec16d

File tree

17 files changed

+483
-150
lines changed

17 files changed

+483
-150
lines changed

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
cli.load_entry()
44
cli.load_register("entari_cli.plugins")
5-
cli.main("entari setting --local abc.package_manager pdm")
5+
cli.main("entari setting --local --edit")

pdm.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Entari Command Line Tool, extract from arclet.entari.__main__"
55
authors = [
66
{name = "RF-Tar-Railt", email = "[email protected]"},
77
]
8-
dependencies = ["cli-lite>=0.11.0", "colorama>=0.4.6", "tomlkit>=0.13.3", "ruamel-yaml>=0.18.15", "python-dotenv>=1.1.1", "packaging>=25.0", "findpython>=0.7.0"]
8+
dependencies = ["cli-lite>=0.11.2", "colorama>=0.4.6", "tomlkit>=0.13.3", "ruamel-yaml>=0.18.15", "python-dotenv>=1.1.1", "packaging>=25.0", "findpython>=0.7.0"]
99
requires-python = ">=3.9"
1010
readme = "README.md"
1111
license = {text = "MIT"}

src/entari_cli/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pkgutil
33

44
from clilte import CommandLine
5+
from colorama.ansi import Fore
56

67
from .i18n import Lang
78

@@ -18,6 +19,13 @@
1819
load_preset=False,
1920
)
2021

22+
23+
def printer(exc: Exception) -> None:
24+
print(f"{Fore.RED}[Error: {exc.__class__.__name__}]{Fore.RESET}: {exc!s}")
25+
26+
27+
cli.exception_printer = printer
28+
2129
COMMANDS_MODULE_PATH = importlib.import_module("entari_cli.commands").__path__
2230

2331
for _, name, _ in pkgutil.iter_modules(COMMANDS_MODULE_PATH):

src/entari_cli/commands/config/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
YAML_PLUGIN_COMMON_TEMPLATE,
1818
YAML_PLUGIN_DEV_TEMPLATE,
1919
)
20-
from .path import ConfigPath # noqa: F401
20+
2121
from ...project import get_project_root
22+
from .path import ConfigPath # noqa: F401
2223

2324

2425
def check_env(file: Path):

src/entari_cli/commands/init.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import sys
33

44
from arclet.alconna import Alconna, Args, Arparma, CommandMeta, MultiVar, Option
5-
from clilte import BasePlugin, PluginMetadata, register
5+
from clilte import BasePlugin, CommandLine, PluginMetadata, register
66
from clilte.core import Next
77
from colorama import Fore
88

99
from entari_cli import i18n_
10-
from entari_cli.process import call_pip
11-
from entari_cli.project import ensure_python
12-
from entari_cli.py_info import check_package_installed
10+
from entari_cli.project import ensure_python, install_dependencies
11+
from entari_cli.py_info import PythonInfo, check_package_installed, get_package_version
12+
from entari_cli.template import WORKSPACE_PROJECT_TEMPLATE
1313
from entari_cli.utils import ask
1414
from entari_cli.venv import get_venv_like_prefix
1515

@@ -19,8 +19,14 @@ class InitEnv(BasePlugin):
1919
def init(self):
2020
return Alconna(
2121
"init",
22+
Option("-d|--develop", help_text=i18n_.commands.init.options.develop()),
2223
Option("-py|--python", Args["path/", str], help_text=i18n_.commands.init.options.python()),
23-
Option("--install-args", Args["params/", MultiVar(str)], help_text=i18n_.commands.init.options.install_args(), dest="install"),
24+
Option(
25+
"--install-args",
26+
Args["params/", MultiVar(str)],
27+
help_text=i18n_.commands.init.options.install_args(),
28+
dest="install",
29+
),
2430
meta=CommandMeta(i18n_.commands.init.description()),
2531
)
2632

@@ -32,10 +38,16 @@ def meta(self) -> PluginMetadata:
3238
)
3339

3440
def dispatch(self, result: Arparma, next_: Next):
41+
from entari_cli.commands.setting import SelfSetting
42+
3543
if result.find("init"):
3644
python = result.query[str]("init.python.path", "")
3745
args = result.query[tuple[str, ...]]("init.install.params", ())
38-
46+
is_dev = result.find("init.develop")
47+
extra = ["yaml", "cron"]
48+
if is_dev:
49+
extra += ["reload", "dotenv"]
50+
extras = ",".join(extra)
3951
python_path = sys.executable
4052
if get_venv_like_prefix(sys.executable)[0] is None:
4153
ans = ask(i18n_.venv.ask_create(), "Y/n").strip().lower()
@@ -45,8 +57,24 @@ def dispatch(self, result: Arparma, next_: Next):
4557
if check_package_installed("arclet.entari", python_path):
4658
return f"{Fore.YELLOW}{i18n_.commands.init.messages.initialized()}{Fore.RESET}"
4759
else:
48-
ret_code = call_pip(sys.executable, "install", "arclet-entari[full]", *args)
60+
ret_code = install_dependencies(
61+
CommandLine.current().get_plugin(SelfSetting), # type: ignore
62+
[f"arclet.entari[{extras}]"],
63+
python_path,
64+
args,
65+
)
4966
if ret_code != 0:
50-
return f"{Fore.RED}{i18n_.project.install_failed()}{Fore.RESET}"
67+
return
68+
toml_file = Path.cwd() / "pyproject.toml"
69+
if not toml_file.exists():
70+
info = PythonInfo.from_path(python_path)
71+
with toml_file.open("w", encoding="utf-8") as f:
72+
f.write(
73+
WORKSPACE_PROJECT_TEMPLATE.format(
74+
extra=extras,
75+
entari_version=get_package_version("arclet.entari", python_path) or "0.15.0",
76+
python_requirement=f">= {info.major}.{info.minor}",
77+
)
78+
)
5179
return f"{Fore.GREEN}{i18n_.commands.init.messages.success()}{Fore.RESET}"
5280
return next_(None)

src/entari_cli/commands/new.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
from arclet.alconna import Alconna, Args, Arparma, CommandMeta, MultiVar, Option
55
from clilte import BasePlugin, PluginMetadata, register
6-
from clilte.core import Next
6+
from clilte.core import CommandLine, Next
77
from colorama import Fore
88

99
from entari_cli import i18n_
1010
from entari_cli.config import EntariConfig
11-
from entari_cli.consts import YES, NO
12-
from entari_cli.process import call_pip
11+
from entari_cli.consts import NO, YES
1312
from entari_cli.project import (
1413
PYTHON_VERSION,
1514
ensure_python,
1615
get_user_email_from_git,
16+
install_dependencies,
1717
sanitize_project_name,
1818
validate_project_name,
1919
)
@@ -41,7 +41,12 @@ def init(self):
4141
Option("-O|--optional", help_text=i18n_.commands.new.options.optional()),
4242
Option("-p|--priority", Args["num/", int], help_text=i18n_.commands.new.options.priority()),
4343
Option("-py|--python", Args["path/", str], help_text=i18n_.commands.new.options.python()),
44-
Option("--install-args", Args["params/", MultiVar(str)], help_text=i18n_.commands.new.options.install_args(), dest="install"),
44+
Option(
45+
"--install-args",
46+
Args["params/", MultiVar(str)],
47+
help_text=i18n_.commands.new.options.install_args(),
48+
dest="install",
49+
),
4550
meta=CommandMeta(i18n_.commands.new.description()),
4651
)
4752

@@ -53,6 +58,8 @@ def meta(self) -> PluginMetadata:
5358
)
5459

5560
def dispatch(self, result: Arparma, next_: Next):
61+
from entari_cli.commands.setting import SelfSetting
62+
5663
if result.find("new"):
5764
is_application = result.find("new.application")
5865
python = result.query[str]("new.python.path", "")
@@ -69,9 +76,14 @@ def dispatch(self, result: Arparma, next_: Next):
6976
if use_venv:
7077
python_path = str(ensure_python(Path.cwd(), python).executable)
7178
if not check_package_installed("arclet.entari", python_path):
72-
ret_code = call_pip(python_path, "install", "arclet-entari[full]", *args)
79+
ret_code = install_dependencies(
80+
CommandLine.current().get_plugin(SelfSetting), # type: ignore
81+
[f"arclet.entari[yaml,cron,reload.dotenv]"],
82+
python_path,
83+
args,
84+
)
7385
if ret_code != 0:
74-
return f"{Fore.RED}{i18n_.project.install_failed()}{Fore.RESET}"
86+
return
7587
entari_version = get_package_version("arclet.entari", python_path) or entari_version
7688
name = result.query[str]("new.name")
7789
if not name:

0 commit comments

Comments
 (0)