WIP: dev into master #184
0
src/cli/cpl/cli/command/execute/__init__.py
Normal file
0
src/cli/cpl/cli/command/execute/__init__.py
Normal file
17
src/cli/cpl/cli/command/execute/run.py
Normal file
17
src/cli/cpl/cli/command/execute/run.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import click
|
||||
|
||||
from cpl.cli.cli import cli
|
||||
from cpl.cli.utils.structure import get_project_by_name_or_path
|
||||
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]):
|
||||
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)
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
from pathlib import Path
|
||||
|
||||
from cpl.cli.cli import cli
|
||||
from cpl.cli.command.execute.run import run
|
||||
from cpl.cli.command.package.remove import remove
|
||||
from cpl.cli.command.package.add import add
|
||||
from cpl.cli.command.structure.init import init
|
||||
@@ -32,7 +33,7 @@ def _load_scripts():
|
||||
if ws is None:
|
||||
continue
|
||||
|
||||
Configuration.set("workspace_path", os.path.abspath(p))
|
||||
Configuration.set("workspace", Workspace.from_file(p))
|
||||
return ws.scripts
|
||||
|
||||
return {}
|
||||
@@ -60,7 +61,7 @@ def configure():
|
||||
cli.add_command(remove)
|
||||
|
||||
# run
|
||||
# cli.add_command(run)
|
||||
cli.add_command(run)
|
||||
# cli.add_command(start)
|
||||
|
||||
|
||||
|
||||
@@ -1,41 +1,14 @@
|
||||
from pathlib import Path
|
||||
|
||||
from cpl.cli.model.project import Project
|
||||
from cpl.cli.model.workspace import Workspace
|
||||
from cpl.core.configuration import Configuration
|
||||
from cpl.core.console import Console
|
||||
|
||||
|
||||
def resolve_project(path: Path, name: str | None) -> Project:
|
||||
project_file = path / "cpl.project.json"
|
||||
if project_file.exists():
|
||||
return Project.from_file(project_file)
|
||||
|
||||
workspace_file = path / "cpl.workspace.json"
|
||||
if workspace_file.exists():
|
||||
workspace = Workspace.from_file(workspace_file)
|
||||
if name:
|
||||
for p in workspace.projects:
|
||||
project = Project.from_file(p)
|
||||
if project.name == name:
|
||||
return project
|
||||
|
||||
elif workspace.default_project:
|
||||
for p in workspace.projects:
|
||||
project = Project.from_file(p)
|
||||
if project.name == workspace.default_project:
|
||||
return project
|
||||
|
||||
Console.error(f"Could not find project file '{path}'")
|
||||
exit(1)
|
||||
|
||||
def get_project_by_name_or_path(project: str) -> Project:
|
||||
if project is None:
|
||||
raise ValueError("Project name or path must be provided.")
|
||||
|
||||
workspace = None
|
||||
if Configuration.get("workspace_path") is not None:
|
||||
workspace = Workspace.from_file(Configuration.get("workspace_path"))
|
||||
workspace = Configuration.get("workspace")
|
||||
|
||||
path = Path(project)
|
||||
if path.exists() and path.is_dir() and (path / "cpl.project.json").exists():
|
||||
|
||||
@@ -9,12 +9,12 @@ from cpl.core.console import Console
|
||||
|
||||
def ensure_venv(start_path: Path | None = None) -> Path:
|
||||
start_path = start_path or Path.cwd()
|
||||
workspace_path = Configuration.get("workspace_path")
|
||||
workspace = Configuration.get("workspace")
|
||||
|
||||
if workspace_path is not None:
|
||||
workspace_path = Path(os.path.dirname(workspace_path))
|
||||
if workspace is not None:
|
||||
workspace = Path(os.path.dirname(workspace.path))
|
||||
|
||||
ws_venv = workspace_path / ".venv"
|
||||
ws_venv = workspace / ".venv"
|
||||
if ws_venv.exists():
|
||||
return ws_venv
|
||||
|
||||
@@ -23,8 +23,8 @@ def ensure_venv(start_path: Path | None = None) -> Path:
|
||||
if venv_path.exists():
|
||||
return venv_path
|
||||
|
||||
if workspace_path is not None:
|
||||
venv_path = workspace_path / ".venv"
|
||||
if workspace is not None:
|
||||
venv_path = workspace / ".venv"
|
||||
else:
|
||||
venv_path = start_path / ".venv"
|
||||
|
||||
|
||||
@@ -8,5 +8,6 @@ export PYTHONPATH="$ROOT_DIR/core:$ROOT_DIR/cli:$PYTHONPATH"
|
||||
|
||||
old_dir="$(pwd)"
|
||||
cd ../
|
||||
echo "$@"
|
||||
python -m cpl.cli.main "$@"
|
||||
cd "$old_dir"
|
||||
Reference in New Issue
Block a user