Improved build

This commit is contained in:
2025-10-12 18:19:58 +02:00
parent 883fa2d691
commit 9647923647
2 changed files with 51 additions and 38 deletions

View File

@@ -42,6 +42,9 @@ def build(project: str, dist: str = None, skip_py_build: bool = None, verbose: b
create_pyproject_toml(project, dist_path / project.name) create_pyproject_toml(project, dist_path / project.name)
python = str(get_venv_python(venv)) python = str(get_venv_python(venv))
Console.spinner(
"Building python package...",
lambda: (
subprocess.run( subprocess.run(
[ [
python, python,
@@ -56,4 +59,6 @@ def build(project: str, dist: str = None, skip_py_build: bool = None, verbose: b
stdout=subprocess.DEVNULL if not verbose else None, stdout=subprocess.DEVNULL if not verbose else None,
stderr=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 re
import shutil import shutil
from pathlib import Path from pathlib import Path
from typing import Optional, List, Dict from typing import Optional, List, Dict, Self
from urllib.parse import urlparse from urllib.parse import urlparse
from cpl.cli.model.build import Build from cpl.cli.model.build import Build
@@ -228,32 +228,38 @@ class Project(CPLStructureModel):
for p in references: for p in references:
os.chdir(Path(p.path).parent) os.chdir(Path(p.path).parent)
p.do_build(dist, verbose) p.do_build(dist, verbose, self)
os.chdir(old_dir) os.chdir(old_dir)
def do_build(self, dist: Path, verbose: bool = False): def do_build(self, dist: Path, verbose: bool = False, parent: Self = None):
self.build_references(dist, verbose)
Console.write_line(f"Building project {self.name}...")
if isinstance(dist, str): if isinstance(dist, str):
dist = Path(dist) dist = Path(dist)
dist_path = dist / self.name dist_project = self if parent is None else parent
rel_dir = Path(self.path).parent / Path(self.directory) 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" Building references for project {self.name}...")
self.build_references(dist, verbose)
# Console.write_line(f"Building project {self.name}...")
def _build():
if verbose: if verbose:
Console.write_line(f" Collecting project '{self.name}' files...") Console.write_line(f" Collecting project '{self.name}' files...")
rel_dir = (Path(self.path).parent / Path(self.directory)).absolute()
files = self._collect_files(rel_dir) files = self._collect_files(rel_dir)
if len(files) == 0: if len(files) == 0:
return
if verbose: if verbose:
Console.write_line(f" Cleaning dist folder at {dist_path.absolute()}...") 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: for file in files:
rel_path = file.relative_to(rel_dir) rel_path = file.relative_to(rel_dir)
@@ -265,5 +271,7 @@ class Project(CPLStructureModel):
shutil.copy(file, dest_file_path) shutil.copy(file, dest_file_path)
if verbose: if verbose:
Console.write_line(f" Copied {len(files)} files from {rel_dir.absolute()} to {dist_path.absolute()}") Console.write_line(f" Copied {len(files)} files from {rel_dir} to {dist_path}")
Console.write_line(" Done!") Console.write_line(" Done!")
Console.spinner(f"Building project {self.name}...", lambda: _build())