/
niceSOFT
/
python3-hatchling
Обзор
Документация
Войти
/
niceSOFT
/
python3-hatchling
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/hatch/cli/env/create.py
49 строк
2 KB
Cary Hawkins
Enable removing environments if there is an error during creation unless keep-env flag is passed in (#2148)
07 янв 2026, 04:05
Не верифицирован
07 янв 2026, 04:05
ca29937
Код
Авторство
О чём код?
from __future__ import annotations import os from typing import TYPE_CHECKING import click from hatch.config.constants import AppEnvVars if TYPE_CHECKING: from hatch.cli.application import Application @click.command(short_help="Create environments") @click.argument("env_name", default="default") @click.pass_obj def create(app: Application, env_name: str): """Create environments.""" app.ensure_environment_plugin_dependencies() environments = app.project.expand_environments(env_name) if not environments: app.abort(f"Environment `{env_name}` is not defined by project config") incompatible = {} for env in environments: environment = app.project.get_environment(env) if environment.exists(): app.display_warning(f"Environment `{env}` already exists") continue try: environment.check_compatibility() except Exception as e: # noqa: BLE001 if env_name in app.project.config.matrices: incompatible[env] = str(e) continue app.abort(f"Environment `{env}` is incompatible: {e}") app.project.prepare_environment(environment, keep_env=bool(os.environ.get(AppEnvVars.KEEP_ENV))) if incompatible: num_incompatible = len(incompatible) app.display_warning( f"Skipped {num_incompatible} incompatible environment{'s' if num_incompatible > 1 else ''}:" ) for env, reason in incompatible.items(): app.display_warning(f"{env} -> {reason}")