| |
| """ |
| Build and test the StoxChai NSE Predictor pip package |
| """ |
|
|
| import subprocess |
| import sys |
| import os |
| from pathlib import Path |
|
|
| def run_command(cmd, description): |
| """Run a command and handle errors""" |
| print(f"π {description}...") |
| try: |
| result = subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True) |
| print(f"β
{description} completed successfully") |
| return True |
| except subprocess.CalledProcessError as e: |
| print(f"β {description} failed:") |
| print(f" Error: {e}") |
| if e.stdout: |
| print(f" Output: {e.stdout}") |
| if e.stderr: |
| print(f" Error: {e.stderr}") |
| return False |
|
|
| def main(): |
| """Main build function""" |
| print("ποΈ Building StoxChai NSE Predictor Package") |
| print("=" * 50) |
| |
| |
| package_dir = Path("stoxchai_nse_predictor") |
| if not package_dir.exists(): |
| print("β Package directory not found") |
| return False |
| |
| os.chdir(package_dir) |
| |
| |
| print("π§Ή Cleaning previous builds...") |
| for item in ["build", "dist", "*.egg-info"]: |
| run_command(f"rm -rf {item}", f"Cleaning {item}") |
| |
| |
| if not run_command("python setup.py sdist bdist_wheel", "Building package"): |
| return False |
| |
| |
| print("\nπ¦ Package contents:") |
| dist_dir = Path("dist") |
| if dist_dir.exists(): |
| for file in dist_dir.glob("*"): |
| size_mb = file.stat().st_size / (1024 * 1024) |
| print(f" {file.name} ({size_mb:.1f} MB)") |
| |
| |
| print("\nπ§ Installing package in development mode...") |
| if not run_command("pip install -e .", "Installing package"): |
| return False |
| |
| |
| print("\nπ§ͺ Testing the package...") |
| |
| |
| try: |
| import stoxchai_nse_predictor |
| print("β
Package import successful") |
| print(f" Version: {stoxchai_nse_predictor.__version__}") |
| print(f" Author: {stoxchai_nse_predictor.__author__}") |
| except ImportError as e: |
| print(f"β Package import failed: {e}") |
| return False |
| |
| |
| print("\nπ± Testing CLI...") |
| if not run_command("stoxchai-predict --info", "Testing CLI info command"): |
| return False |
| |
| |
| print("\nπ― Testing prediction...") |
| if not run_command("stoxchai-predict --sample --model randomforest", "Testing prediction"): |
| return False |
| |
| print("\nπ Package build and test completed successfully!") |
| print("\nπ Next steps:") |
| print("1. Upload to PyPI: python -m twine upload dist/*") |
| print("2. Install globally: pip install stoxchai-nse-predictor") |
| print("3. Use in code: from stoxchai_nse_predictor import StoxChaiStockPredictor") |
| |
| return True |
|
|
| if __name__ == "__main__": |
| success = main() |
| sys.exit(0 if success else 1) |
|
|