2024-11-27 13:14:52 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
2025-03-21 14:25:26 +01:00
|
|
|
from in_container_utils import AIRFLOW_DIST_PATH, click, console, run_command
|
2024-11-27 13:14:52 +00:00
|
|
|
|
2025-03-21 14:25:26 +01:00
|
|
|
ALLOWED_DISTRIBUTION_FORMAT = ["wheel", "sdist", "both"]
|
2024-11-27 13:14:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_airflow_python_client(extension: str):
|
2025-03-21 14:25:26 +01:00
|
|
|
packages = [f.as_posix() for f in AIRFLOW_DIST_PATH.glob(f"apache_airflow_client-[0-9]*.{extension}")]
|
2024-11-27 13:14:52 +00:00
|
|
|
if len(packages) > 1:
|
|
|
|
|
console.print(f"\n[red]Found multiple airflow client packages: {packages}\n")
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
elif len(packages) == 0:
|
|
|
|
|
console.print("\n[red]No airflow client package found\n")
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
if packages:
|
|
|
|
|
console.print(f"\n[bright_blue]Found airflow client package: {packages[0]}\n")
|
|
|
|
|
else:
|
|
|
|
|
console.print("\n[yellow]No airflow client package found.\n")
|
|
|
|
|
return packages[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
|
|
|
|
@click.option(
|
2025-03-21 14:25:26 +01:00
|
|
|
"--distribution-format",
|
|
|
|
|
default=ALLOWED_DISTRIBUTION_FORMAT[0],
|
|
|
|
|
envvar="DISTRIBUTION_FORMAT",
|
2024-11-27 13:14:52 +00:00
|
|
|
show_default=True,
|
2025-03-21 14:25:26 +01:00
|
|
|
type=click.Choice(ALLOWED_DISTRIBUTION_FORMAT),
|
2024-11-27 13:14:52 +00:00
|
|
|
help="Package format to use",
|
|
|
|
|
)
|
|
|
|
|
@click.option(
|
2025-03-21 14:25:26 +01:00
|
|
|
"--use-distributions-from-dist",
|
2024-11-27 13:14:52 +00:00
|
|
|
is_flag=True,
|
|
|
|
|
default=True,
|
|
|
|
|
show_default=True,
|
2025-03-21 14:25:26 +01:00
|
|
|
envvar="USE_DISTRIBUTIONS_FROM_DIST",
|
|
|
|
|
help="Should install distributions from dist folder if set.",
|
2024-11-27 13:14:52 +00:00
|
|
|
)
|
|
|
|
|
@click.option(
|
|
|
|
|
"--github-actions",
|
|
|
|
|
is_flag=True,
|
|
|
|
|
default=False,
|
|
|
|
|
show_default=True,
|
|
|
|
|
envvar="GITHUB_ACTIONS",
|
|
|
|
|
help="Running in GitHub Actions",
|
|
|
|
|
)
|
2025-03-21 14:25:26 +01:00
|
|
|
def install_airflow_python_client(
|
|
|
|
|
distribution_format: str, use_distributions_from_dist: bool, github_actions: bool
|
|
|
|
|
):
|
|
|
|
|
if use_distributions_from_dist and distribution_format not in ["wheel", "sdist"]:
|
|
|
|
|
console.print(
|
|
|
|
|
f"[red]DISTRIBUTION_FORMAT must be one of 'wheel' or 'sdist' and not {distribution_format}"
|
|
|
|
|
)
|
2024-11-27 13:14:52 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
2025-03-21 14:25:26 +01:00
|
|
|
extension = "whl" if distribution_format == "wheel" else "tar.gz"
|
2024-11-27 13:14:52 +00:00
|
|
|
|
|
|
|
|
install_airflow_python_client_cmd = [
|
2025-08-30 20:18:30 +05:30
|
|
|
"uv",
|
2024-11-27 13:14:52 +00:00
|
|
|
"pip",
|
|
|
|
|
"install",
|
|
|
|
|
find_airflow_python_client(extension),
|
|
|
|
|
]
|
|
|
|
|
console.print("\n[bright_blue]Installing airflow python client\n")
|
|
|
|
|
run_command(install_airflow_python_client_cmd, github_actions=github_actions, check=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
install_airflow_python_client()
|