diff --git a/scripts/tools/initialize_virtualenv.py b/scripts/tools/initialize_virtualenv.py index 1058a21af2d0..f78a2dab40bc 100755 --- a/scripts/tools/initialize_virtualenv.py +++ b/scripts/tools/initialize_virtualenv.py @@ -55,7 +55,7 @@ def check_for_package_extras() -> str: return "devel" -def pip_install_requirements() -> int: +def uv_install_requirements() -> int: """ install the requirements of the current python version. return 0 if success, anything else is an error. @@ -88,16 +88,12 @@ def pip_install_requirements() -> int: """ ) - version = get_python_version() - constraint = ( - f"https://raw.githubusercontent.com/apache/airflow/constraints-main/" - f"constraints-source-providers-{version}.txt" - ) - pip_install_command = ["pip", "install", "-e", f".[{extras}]", "--constraint", constraint] - quoted_command = " ".join([shlex.quote(parameter) for parameter in pip_install_command]) + extra_param = [x for extra in extras.split(",") for x in ("--extra", extra)] + uv_install_command = ["uv", "sync"] + extra_param + quoted_command = " ".join([shlex.quote(parameter) for parameter in uv_install_command]) print() print(f"Running command: \n {quoted_command}\n") - e = subprocess.run(pip_install_command) + e = subprocess.run(uv_install_command) return e.returncode @@ -107,7 +103,8 @@ def get_python_version() -> str: """ major = sys.version_info[0] minor = sys.version_info[1] - return f"{major}.{minor}" + micro = sys.version_info[2] + return f"{major}.{minor}.{micro}" def main(): @@ -118,11 +115,10 @@ def main(): airflow_sources = Path(__file__).resolve().parents[2] if not check_if_in_virtualenv(): - print( - "Local virtual environment not activated.\nPlease create and activate it " - "first. (for example using 'python3 -m venv venv && source venv/bin/activate')" - ) - sys.exit(1) + version = get_python_version() + e = subprocess.run(["uv", "venv", "--python", version]) + if e.returncode != 0: + print(f"There was a problem with 'uv venv'. Error code: {e.returncode}") print("Initializing environment...") print(f"This will remove the folder {airflow_home_dir} and reset all the databases!") @@ -144,7 +140,7 @@ def main(): clean_up_airflow_home(airflow_home_dir) - return_code = pip_install_requirements() + return_code = uv_install_requirements() if return_code != 0: print( @@ -172,7 +168,7 @@ def main(): env["AIRFLOW__DATABASE__SQL_ALCHEMY_POOL_ENABLED"] = "False" env["AIRFLOW__CORE__DAGS_FOLDER"] = f"{airflow_sources}/empty" env["AIRFLOW__CORE__PLUGINS_FOLDER"] = f"{airflow_sources}/empty" - subprocess.run(["airflow", "db", "reset", "--yes"], env=env) + subprocess.run(["uv", "run", "airflow", "db", "reset", "--yes"], env=env) print("\nResetting AIRFLOW sqlite unit test database...") env = os.environ.copy() @@ -181,7 +177,7 @@ def main(): env["AIRFLOW__DATABASE__SQL_ALCHEMY_POOL_ENABLED"] = "False" env["AIRFLOW__CORE__DAGS_FOLDER"] = f"{airflow_sources}/empty" env["AIRFLOW__CORE__PLUGINS_FOLDER"] = f"{airflow_sources}/empty" - subprocess.run(["airflow", "db", "reset", "--yes"], env=env) + subprocess.run(["uv", "run", "airflow", "db", "reset", "--yes"], env=env) print("\nInitialization of environment complete! Go ahead and develop Airflow!")