Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-08 07:59:56

0001 #!/usr/bin/env python
0002 """
0003 Build script to install all iDDS packages using pyproject.toml configuration.
0004 This replaces the old setup.py meta-installer.
0005 
0006 Usage:
0007     python build_all.py install         # Install all packages
0008     python build_all.py develop         # Install in development mode
0009     python build_all.py build           # Build all packages
0010     python build_all.py clean           # Clean build artifacts
0011     python build_all.py wheel           # Build wheel distributions
0012 """
0013 
0014 import os
0015 import subprocess
0016 import sys
0017 from pathlib import Path
0018 
0019 
0020 # List of packages in installation order (dependencies first)
0021 PACKAGES = [
0022     'common',
0023     'main',
0024     'client',
0025     'atlas',
0026     'workflow',
0027     'doma',
0028     'website',
0029     'monitor',
0030     'prompt',
0031 ]
0032 
0033 
0034 def run_command(cmd, cwd):
0035     """Run a command in the specified directory."""
0036     print(f"\n{'='*60}")
0037     print(f"Running: {cmd}")
0038     print(f"In directory: {cwd}")
0039     print(f"{'='*60}\n")
0040     
0041     result = subprocess.run(
0042         cmd,
0043         shell=True,
0044         cwd=cwd,
0045         capture_output=False,
0046         text=True
0047     )
0048     
0049     if result.returncode != 0:
0050         print(f"ERROR: Command failed with return code {result.returncode}")
0051         return False
0052     return True
0053 
0054 
0055 def clean_package(package_path):
0056     """Clean build artifacts for a package."""
0057     dirs_to_remove = ['build', 'dist', '*.egg-info', '__pycache__']
0058     
0059     for pattern in dirs_to_remove:
0060         if '*' in pattern:
0061             import glob
0062             for path in glob.glob(str(package_path / pattern)):
0063                 print(f"Removing: {path}")
0064                 if os.path.isdir(path):
0065                     import shutil
0066                     shutil.rmtree(path, ignore_errors=True)
0067         else:
0068             path = package_path / pattern
0069             if path.exists():
0070                 print(f"Removing: {path}")
0071                 import shutil
0072                 shutil.rmtree(path, ignore_errors=True)
0073 
0074 
0075 def process_packages(command):
0076     """Process all packages with the given command."""
0077     current_dir = Path(__file__).parent.resolve()
0078     success_count = 0
0079     
0080     # Map user commands to pip/build commands
0081     command_map = {
0082         'install': 'pip install .',
0083         'develop': 'pip install -e .',
0084         'build': 'python -m build',
0085         'wheel': 'python -m build --wheel',
0086     }
0087     
0088     if command == 'clean':
0089         print("Cleaning build artifacts...")
0090         for package in PACKAGES:
0091             package_path = current_dir / package
0092             if package_path.exists():
0093                 clean_package(package_path)
0094         print("\nClean completed for all packages!")
0095         return
0096     
0097     if command not in command_map:
0098         print(f"Unknown command: {command}")
0099         print(f"Available commands: {', '.join(list(command_map.keys()) + ['clean'])}")
0100         sys.exit(1)
0101     
0102     pip_command = command_map[command]
0103     
0104     for package in PACKAGES:
0105         package_path = current_dir / package
0106         
0107         if not package_path.exists():
0108             print(f"WARNING: Package directory not found: {package_path}")
0109             continue
0110         
0111         if not (package_path / 'pyproject.toml').exists():
0112             print(f"WARNING: No pyproject.toml found in {package}, skipping...")
0113             continue
0114         
0115         success = run_command(pip_command, package_path)
0116         
0117         if success:
0118             success_count += 1
0119             print(f"✓ {package} completed successfully")
0120         else:
0121             print(f"✗ {package} failed")
0122             if input(f"\nContinue with remaining packages? (y/n): ").lower() != 'y':
0123                 break
0124     
0125     print(f"\n{'='*60}")
0126     print(f"Completed: {success_count}/{len(PACKAGES)} packages")
0127     print(f"{'='*60}")
0128 
0129 
0130 def main():
0131     if len(sys.argv) < 2:
0132         print(__doc__)
0133         sys.exit(1)
0134     
0135     command = sys.argv[1]
0136     
0137     # Check if pip and build are available
0138     if command in ['build', 'wheel']:
0139         try:
0140             import build  # noqa: F401
0141         except ImportError:
0142             print("ERROR: 'build' package not found. Install it with:")
0143             print("    pip install build")
0144             sys.exit(1)
0145     
0146     process_packages(command)
0147 
0148 
0149 if __name__ == '__main__':
0150     main()