Skip to content

Commit

Permalink
BUG Update initialise_virtualenv.py to use uv sync (apache#44096)
Browse files Browse the repository at this point in the history
* Update initialse_virtualenv.py to use uv sync

* fixup! Update initialse_virtualenv.py to use uv sync

---------

Co-authored-by: Jarek Potiuk <[email protected]>
  • Loading branch information
SuccessMoses and potiuk authored Nov 17, 2024
1 parent b6c75d2 commit 987c50a
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions scripts/tools/initialize_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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


Expand All @@ -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():
Expand All @@ -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!")
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand All @@ -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!")

Expand Down

0 comments on commit 987c50a

Please sign in to comment.