WIP: dev into master #184

Draft
edraft wants to merge 121 commits from dev into master
Showing only changes of commit 3c26c73b41 - Show all commits

View File

@@ -1,17 +1,51 @@
import os
import subprocess
from pathlib import Path
import click
from cpl.cli.cli import cli
from cpl.cli.utils.structure import get_project_by_name_or_path
from cpl.cli.utils.venv import get_venv_python, ensure_venv
from cpl.core.configuration import Configuration
from cpl.core.console import Console
@cli.command("run", aliases=["r"])
@click.argument("args", nargs=-1)
@click.option("--project", "-p", type=str)
def run(project: str, args: list[str]):
@click.option("--dev", "-d", is_flag=True, help="Use sources instead of build output")
@click.option("--verbose", "-v", is_flag=True, help="Enable verbose output")
def run(project: str, args: list[str], dev: bool, verbose: bool):
project = get_project_by_name_or_path(project or "./")
if project.main is None:
Console.error(f"Project {project.name} has no executable")
return
Console.write_line(project.main, args)
path = str(Path(project.path).parent.resolve().absolute())
executable = project.main
if not dev:
dist_path = Path(project.path).parent / "dist"
if Configuration.get("workspace") is not None:
dist_path = Path(Configuration.get("workspace").path).parent / "dist"
dist_path = Path(dist_path).resolve().absolute()
if verbose:
Console.write_line(f"Creating dist folder at {dist_path}...")
os.makedirs(dist_path, exist_ok=True)
project.do_build(dist_path, verbose)
path = dist_path / project.name
main = project.main.replace(project.directory, "").lstrip("/\\")
executable = path / main
python = str(get_venv_python(ensure_venv()).absolute())
Console.write_line(f"\nStarting project {project.name}...")
if verbose:
Console.write_line(f" with args {args}...")
Console.write_line("\n\n") # add some space before output
subprocess.run([python, executable, *args], cwd=path)