81 lines
2.6 KiB
Python
81 lines
2.6 KiB
Python
import shutil
|
|
from pathlib import Path
|
|
import PyInstaller.__main__
|
|
import typer
|
|
from rich import print
|
|
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
@app.command()
|
|
def build(build: bool = True, copy: bool = True, test: bool = False, dest: str | None = None):
|
|
"""Windows-focused build script.
|
|
|
|
- `--test` creates a one-file test binary in `dist\test`.
|
|
- `--copy` (default) copies the artifact to the shared network path used previously.
|
|
"""
|
|
|
|
project_root = Path(__file__).resolve().parent
|
|
|
|
if build:
|
|
if test:
|
|
print("Building Windows test one-file bundle with PyInstaller")
|
|
# On Windows use ';' as add-data separator (src;dest)
|
|
PyInstaller.__main__.run([
|
|
str(project_root / "nice.py"),
|
|
"--onefile",
|
|
"--name",
|
|
"anon_gui_test",
|
|
"--distpath",
|
|
str(project_root / "dist" / "test"),
|
|
"--workpath",
|
|
str(project_root / "build" / "test"),
|
|
"--specpath",
|
|
str(project_root / "build" / "specs"),
|
|
"--add-data",
|
|
"icon;icon",
|
|
"--hidden-import",
|
|
"bs4",
|
|
"--hidden-import",
|
|
"requests",
|
|
"--hidden-import",
|
|
"nicegui",
|
|
])
|
|
else:
|
|
print("Building using spec: nice_uploader.spec")
|
|
PyInstaller.__main__.run([str(project_root / "nice_uploader.spec")])
|
|
|
|
if copy:
|
|
# Windows-only default destination used previously in the repo
|
|
default_dest = Path(r"\\ict\Go\RCH\Shared\Dragon-Xray\rad-tools\uploader\Uploader")
|
|
|
|
artifact_dir = project_root / "dist" / ("test" if test else "")
|
|
if not artifact_dir.exists():
|
|
artifact_dir = project_root / "dist"
|
|
|
|
# Look for a matching artifact
|
|
candidates = list(artifact_dir.glob("Uploader*")) + list(artifact_dir.glob("*.exe"))
|
|
if not candidates:
|
|
print(f"No build artifact found in {artifact_dir}, skipping copy")
|
|
return
|
|
|
|
artifact = candidates[0]
|
|
|
|
dest_path = Path(dest) if dest else default_dest
|
|
dest_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
if artifact.is_file():
|
|
target = dest_path / artifact.name
|
|
print(f"Copying {artifact} -> {target}")
|
|
shutil.copy2(artifact, target)
|
|
else:
|
|
target = dest_path / artifact.name
|
|
print(f"Copying directory {artifact} -> {target}")
|
|
if target.exists():
|
|
shutil.rmtree(target)
|
|
shutil.copytree(artifact, target)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app() |