|
| 1 | +# Copyright (c) 2025 Airbyte, Inc., all rights reserved. |
| 2 | +"""Standalone CLI for the Airbyte CDK Manifest Runner. |
| 3 | +
|
| 4 | +This CLI provides commands for running and managing the FastAPI-based manifest runner server. |
| 5 | +
|
| 6 | +**Installation:** |
| 7 | +
|
| 8 | +To use the manifest-runner functionality, install the CDK with the manifest-runner extra: |
| 9 | +
|
| 10 | +```bash |
| 11 | +pip install airbyte-cdk[manifest-runner] |
| 12 | +# or |
| 13 | +poetry install --extras manifest-runner |
| 14 | +``` |
| 15 | +
|
| 16 | +**Usage:** |
| 17 | +
|
| 18 | +```bash |
| 19 | +manifest-runner start --port 8000 |
| 20 | +manifest-runner info |
| 21 | +manifest-runner --help |
| 22 | +``` |
| 23 | +""" |
| 24 | + |
| 25 | +import sys |
| 26 | +from typing import Optional |
| 27 | + |
| 28 | +import rich_click as click |
| 29 | + |
| 30 | +# Import server dependencies with graceful fallback |
| 31 | +try: |
| 32 | + import fastapi |
| 33 | + import uvicorn |
| 34 | + |
| 35 | + FASTAPI_AVAILABLE = True |
| 36 | +except ImportError: |
| 37 | + FASTAPI_AVAILABLE = False |
| 38 | + fastapi = None |
| 39 | + uvicorn = None |
| 40 | + |
| 41 | + |
| 42 | +def _check_manifest_runner_dependencies() -> None: |
| 43 | + """Check if manifest-runner dependencies are installed.""" |
| 44 | + if not FASTAPI_AVAILABLE: |
| 45 | + click.echo( |
| 46 | + "❌ Manifest runner dependencies not found. Please install with:\n\n" |
| 47 | + " pip install airbyte-cdk[manifest-runner]\n" |
| 48 | + " # or\n" |
| 49 | + " poetry install --extras manifest-runner\n", |
| 50 | + err=True, |
| 51 | + ) |
| 52 | + sys.exit(1) |
| 53 | + |
| 54 | + |
| 55 | +@click.group( |
| 56 | + help=__doc__.replace("\n", "\n\n"), # Render docstring as help text (markdown) |
| 57 | + invoke_without_command=True, |
| 58 | +) |
| 59 | +@click.option( |
| 60 | + "--version", |
| 61 | + is_flag=True, |
| 62 | + help="Show the version of the Airbyte CDK Manifest Runner.", |
| 63 | +) |
| 64 | +@click.pass_context |
| 65 | +def cli( |
| 66 | + ctx: click.Context, |
| 67 | + version: bool, |
| 68 | +) -> None: |
| 69 | + """Airbyte CDK Manifest Runner CLI.""" |
| 70 | + if version: |
| 71 | + click.echo("Airbyte CDK Manifest Runner v1.0.0") |
| 72 | + ctx.exit() |
| 73 | + |
| 74 | + if ctx.invoked_subcommand is None: |
| 75 | + # If no subcommand is provided, show the help message. |
| 76 | + click.echo(ctx.get_help()) |
| 77 | + ctx.exit() |
| 78 | + |
| 79 | + |
| 80 | +@cli.command() |
| 81 | +@click.option( |
| 82 | + "--host", |
| 83 | + default="127.0.0.1", |
| 84 | + help="Host to bind the server to", |
| 85 | + show_default=True, |
| 86 | +) |
| 87 | +@click.option( |
| 88 | + "--port", |
| 89 | + default=8000, |
| 90 | + help="Port to bind the server to", |
| 91 | + show_default=True, |
| 92 | +) |
| 93 | +@click.option( |
| 94 | + "--reload", |
| 95 | + is_flag=True, |
| 96 | + help="Enable auto-reload for development", |
| 97 | +) |
| 98 | +def start(host: str, port: int, reload: bool) -> None: |
| 99 | + """Start the FastAPI manifest runner server.""" |
| 100 | + _check_manifest_runner_dependencies() |
| 101 | + |
| 102 | + # Import and use the main server function |
| 103 | + from airbyte_cdk.manifest_runner.main import run_server |
| 104 | + |
| 105 | + run_server( |
| 106 | + host=host, |
| 107 | + port=port, |
| 108 | + reload=reload, |
| 109 | + ) |
| 110 | + |
| 111 | + |
| 112 | +@cli.command() |
| 113 | +def info() -> None: |
| 114 | + """Show manifest runner information and status.""" |
| 115 | + if FASTAPI_AVAILABLE: |
| 116 | + click.echo("✅ Manifest runner dependencies are installed") |
| 117 | + click.echo(f" FastAPI version: {fastapi.__version__}") |
| 118 | + click.echo(f" Uvicorn version: {uvicorn.__version__}") |
| 119 | + else: |
| 120 | + click.echo("❌ Manifest runner dependencies not installed") |
| 121 | + click.echo(" Install with: pip install airbyte-cdk[manifest-runner]") |
| 122 | + |
| 123 | + |
| 124 | +def run() -> None: |
| 125 | + """Entry point for the manifest-runner CLI.""" |
| 126 | + cli() |
| 127 | + |
| 128 | + |
| 129 | +if __name__ == "__main__": |
| 130 | + run() |
0 commit comments