Improved build
This commit is contained in:
@@ -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)
|
create_pyproject_toml(project, dist_path / project.name)
|
||||||
python = str(get_venv_python(venv))
|
python = str(get_venv_python(venv))
|
||||||
|
|
||||||
subprocess.run(
|
Console.spinner(
|
||||||
[
|
"Building python package...",
|
||||||
python,
|
lambda: (
|
||||||
"-m",
|
subprocess.run(
|
||||||
"build",
|
[
|
||||||
"--outdir",
|
python,
|
||||||
str(dist_path / project.name),
|
"-m",
|
||||||
str(dist_path / project.name),
|
"build",
|
||||||
],
|
"--outdir",
|
||||||
check=True,
|
str(dist_path / project.name),
|
||||||
stdin=subprocess.DEVNULL if not verbose else None,
|
str(dist_path / project.name),
|
||||||
stdout=subprocess.DEVNULL if not verbose else None,
|
],
|
||||||
stderr=subprocess.DEVNULL if not verbose else None,
|
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!")
|
||||||
|
|||||||
@@ -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,42 +228,50 @@ 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:
|
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:
|
# Console.write_line(f"Building project {self.name}...")
|
||||||
return
|
def _build():
|
||||||
|
if verbose:
|
||||||
|
Console.write_line(f" Collecting project '{self.name}' files...")
|
||||||
|
|
||||||
if verbose:
|
rel_dir = (Path(self.path).parent / Path(self.directory)).absolute()
|
||||||
Console.write_line(f" Cleaning dist folder at {dist_path.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:
|
if not dest_file_path.parent.exists():
|
||||||
rel_path = file.relative_to(rel_dir)
|
os.makedirs(dest_file_path.parent, exist_ok=True)
|
||||||
dest_file_path = dist_path / rel_path
|
|
||||||
|
|
||||||
if not dest_file_path.parent.exists():
|
shutil.copy(file, dest_file_path)
|
||||||
os.makedirs(dest_file_path.parent, exist_ok=True)
|
|
||||||
|
|
||||||
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.spinner(f"Building project {self.name}...", lambda: _build())
|
||||||
Console.write_line(f" Copied {len(files)} files from {rel_dir.absolute()} to {dist_path.absolute()}")
|
|
||||||
Console.write_line(" Done!")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user