# Copyright 2026 European Union
# Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
# SPDX-License-Identifier: EUPL-1.2
"""Coordinate project creation and optional setup actions.\n\n:author: Bulgheroni Antonio\n"""
from pathlib import Path
from mafw.scaffold import ProjectSpec, generate_project
from mafw.scaffold.installer import InstallOutcome, install_project
from mafw.tools.shell_tools import run
[docs]
def _create_project(
*,
raw_name: str | None,
description: str | None,
python_version: str | None,
author_name: str | None,
author_email: str | None,
path: Path | None,
with_storage: bool,
init_git: bool,
install: str | None,
) -> tuple[ProjectSpec, Path, InstallOutcome | None]:
"""Create a project, optionally initialize Git and install its environment.
:return: The validated specification, generated directory, and optional install result.
"""
spec = ProjectSpec.create(
raw_name=raw_name,
description=description,
python_version=python_version,
author_name=author_name,
author_email=author_email,
path=path,
with_storage=with_storage,
)
project_dir = generate_project(spec)
if init_git:
# Git initialization is opt-in and delegated to the git executable.
run(['git', 'init', str(project_dir)], quiet=True)
outcome = install_project(project_dir, install) if install is not None else None
return spec, project_dir, outcome