elijahbenizzy commented on code in PR #595: URL: https://github.com/apache/burr/pull/595#discussion_r2554458389
########## scripts/build_artifacts.py: ########## @@ -0,0 +1,278 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +""" +Build artifacts/wheels helper with subcommands: + + python scripts/build_artifacts.py artifacts [--skip-install] + python scripts/build_artifacts.py wheel [--clean] + python scripts/build_artifacts.py all [--skip-install] [--clean] + +Subcommands: + artifacts -> Build UI artifacts only + wheel -> Build wheel (requires artifacts to exist) + all -> Run both steps (artifacts then wheel) +""" + +import argparse +import os +import shutil +import subprocess +import sys + + +def _ensure_project_root() -> bool: + if not os.path.exists("pyproject.toml"): + print("Error: pyproject.toml not found.") + print("Please run this script from the root of the Burr source directory.") + return False + return True + + +def _check_node_prereqs() -> bool: + print("Checking for required tools...") + required_tools = ["node", "npm"] + missing_tools = [] + + for tool in required_tools: + if shutil.which(tool) is None: + missing_tools.append(tool) + print(f" ✗ '{tool}' not found") + else: + print(f" ✓ '{tool}' found") + + if missing_tools: + print(f"\nError: Missing required tools: {', '.join(missing_tools)}") + print("Please install Node.js and npm to build the UI.") + return False + + print("All required tools found.\n") + return True + + +def _require_build_module() -> bool: + try: + __import__("build") + print("✓ Python 'build' module found.\n") + return True + except ImportError: + print("✗ Python 'build' module not found.") + print("Please install it with: pip install build") + return False + + +def _install_burr(skip_install: bool) -> bool: + if skip_install: + print("Skipping burr installation as requested.\n") + return True + + print("Installing burr from source...") + try: + subprocess.run( + [sys.executable, "-m", "pip", "install", "-e", "."], + check=True, + cwd=os.getcwd(), + ) + print("✓ Burr installed successfully.\n") + return True + except subprocess.CalledProcessError as exc: + print(f"✗ Error installing burr: {exc}") + return False + + +def _build_ui() -> bool: + print("Building UI assets...") + try: + subprocess.run(["burr-admin-build-ui"], check=True) + print("✓ UI build completed successfully.\n") + return True + except subprocess.CalledProcessError as exc: + print(f"✗ Error building UI: {exc}") + return False + + +def _verify_artifacts() -> bool: + build_dir = "burr/tracking/server/build" + print(f"Verifying build output in {build_dir}...") + + if not os.path.exists(build_dir): + print(f"✗ Build directory not found: {build_dir}") + return False + + if not os.listdir(build_dir): + print(f"✗ Build directory is empty: {build_dir}") + return False + + print("✓ Build output verified.\n") + return True + + +def _clean_dist(): + if os.path.exists("dist"): + print("Cleaning dist/ directory...") + shutil.rmtree("dist") + print("✓ dist/ directory cleaned.\n") + + +def _build_wheel() -> bool: + print("Building wheel distribution with 'python -m build --wheel'...") + try: + subprocess.run([sys.executable, "-m", "build", "--wheel", "."], check=True) + print("✓ Wheel build completed successfully.\n") + return True + except subprocess.CalledProcessError as exc: + print(f"✗ Error building wheel: {exc}") + return False + + +def _verify_wheel() -> bool: + print("Verifying wheel output...") + + if not os.path.exists("dist"): + print("✗ dist/ directory not found") + return False + + wheel_files = [f for f in os.listdir("dist") if f.endswith(".whl")] + if not wheel_files: + print("✗ No wheel files found in dist/") + if os.listdir("dist"): + print("Contents of dist/ directory:") + for item in os.listdir("dist"): + print(f" - {item}") + return False + + print(f"✓ Found {len(wheel_files)} wheel file(s):") + for wheel_file in wheel_files: + wheel_path = os.path.join("dist", wheel_file) + size = os.path.getsize(wheel_path) + print(f" - {wheel_file} ({size:,} bytes)") + + print() + return True + + +def create_artifacts(skip_install: bool) -> bool: + if not _ensure_project_root(): + print("Failed to confirm project root.") + return False + if not _check_node_prereqs(): + print("Node/npm prerequisite check failed.") + return False + if not _install_burr(skip_install): + print("Installing burr from source failed.") + return False + if not _build_ui(): + print("UI build failed.") + return False + if not _verify_artifacts(): + print("UI artifact verification failed.") + return False + return True + + +def create_wheel(clean: bool) -> bool: Review Comment: Sure was going to use twine uplaod will likely be adding later -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
