cli #199

Merged
edraft merged 22 commits from cli into dev 2025-10-19 14:40:46 +02:00
2 changed files with 51 additions and 38 deletions
Showing only changes of commit 9647923647 - Show all commits

View File

@@ -42,18 +42,23 @@ def build(project: str, dist: str = None, skip_py_build: bool = None, verbose: b
create_pyproject_toml(project, dist_path / project.name)
python = str(get_venv_python(venv))
subprocess.run(
[
python,
"-m",
"build",
"--outdir",
str(dist_path / project.name),
str(dist_path / project.name),
],
check=True,
stdin=subprocess.DEVNULL if not verbose else None,
stdout=subprocess.DEVNULL if not verbose else None,
stderr=subprocess.DEVNULL if not verbose else None,
Console.spinner(
"Building python package...",
lambda: (
subprocess.run(
[
python,
"-m",
"build",
"--outdir",
str(dist_path / project.name),
str(dist_path / project.name),
],
check=True,
stdin=subprocess.DEVNULL if not verbose else None,
stdout=subprocess.DEVNULL if not verbose else None,
stderr=subprocess.DEVNULL if not verbose else None,
)
),
)
Console.write_line("\nDone!")
Console.write_line(" Done!")

View File

@@ -3,7 +3,7 @@ import os
import re
import shutil
from pathlib import Path
from typing import Optional, List, Dict
from typing import Optional, List, Dict, Self
from urllib.parse import urlparse
from cpl.cli.model.build import Build
@@ -228,42 +228,50 @@ class Project(CPLStructureModel):
for p in references:
os.chdir(Path(p.path).parent)
p.do_build(dist, verbose)
p.do_build(dist, verbose, self)
os.chdir(old_dir)
def do_build(self, dist: Path, verbose: bool = False):
self.build_references(dist, verbose)
Console.write_line(f"Building project {self.name}...")
def do_build(self, dist: Path, verbose: bool = False, parent: Self = None):
if isinstance(dist, str):
dist = Path(dist)
dist_path = dist / self.name
rel_dir = Path(self.path).parent / Path(self.directory)
dist_project = self if parent is None else parent
dist_path = (dist / dist_project.name / self.directory).resolve().absolute()
if parent is None:
if verbose:
Console.write_line(f" Cleaning dist folder at {dist_path}...")
shutil.rmtree(str(dist_path), ignore_errors=True)
if verbose:
Console.write_line(f" Collecting project '{self.name}' files...")
Console.write_line(f" Building references for project {self.name}...")
files = self._collect_files(rel_dir)
self.build_references(dist, verbose)
if len(files) == 0:
return
# Console.write_line(f"Building project {self.name}...")
def _build():
if verbose:
Console.write_line(f" Collecting project '{self.name}' files...")
if verbose:
Console.write_line(f" Cleaning dist folder at {dist_path.absolute()}...")
rel_dir = (Path(self.path).parent / Path(self.directory)).absolute()
files = self._collect_files(rel_dir)
if len(files) == 0:
if verbose:
Console.write_line(f" No files found in {rel_dir}, skipping copy.")
return
shutil.rmtree(str(dist_path), ignore_errors=True)
for file in files:
rel_path = file.relative_to(rel_dir)
dest_file_path = dist_path / rel_path
for file in files:
rel_path = file.relative_to(rel_dir)
dest_file_path = dist_path / rel_path
if not dest_file_path.parent.exists():
os.makedirs(dest_file_path.parent, exist_ok=True)
if not dest_file_path.parent.exists():
os.makedirs(dest_file_path.parent, exist_ok=True)
shutil.copy(file, dest_file_path)
shutil.copy(file, dest_file_path)
if verbose:
Console.write_line(f" Copied {len(files)} files from {rel_dir} to {dist_path}")
Console.write_line(" Done!")
if verbose:
Console.write_line(f" Copied {len(files)} files from {rel_dir.absolute()} to {dist_path.absolute()}")
Console.write_line(" Done!")
Console.spinner(f"Building project {self.name}...", lambda: _build())