mik-laj commented on a change in pull request #19867:
URL: https://github.com/apache/airflow/pull/19867#discussion_r758665058
##########
File path: Breeze2
##########
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+# isort: skip
+import os
+import sys
+
+# Python <3.4 does not have pathlib
+if sys.version_info.major != 3 or sys.version_info.minor < 7:
+ print("ERROR! Make sure you use Python 3.7+ !!")
+ sys.exit(1)
+
+import subprocess
+from os import execv
+from pathlib import Path
+
+AIRFLOW_SOURCES_DIR = Path(__file__).parent.resolve()
+BUILD_DIR = AIRFLOW_SOURCES_DIR / ".build"
+BUILD_BREEZE_DIR = BUILD_DIR / "breeze2"
+BUILD_BREEZE_CFG_SAVED = BUILD_BREEZE_DIR / "setup.cfg.saved"
+BUILD_BREEZE_VENV_DIR = BUILD_BREEZE_DIR / "venv"
+BUILD_BREEZE_VENV_BIN_DIR = BUILD_BREEZE_VENV_DIR / "bin"
+BUILD_BREEZE_VENV_PIP = BUILD_BREEZE_VENV_BIN_DIR / "pip"
+BUILD_BREEZE_VENV_BREEZE = BUILD_BREEZE_VENV_BIN_DIR / "Breeze2"
+
+BREEZE_SOURCE_PATH = AIRFLOW_SOURCES_DIR / "dev" / "breeze"
+BREEZE_SETUP_CFG_PATH = BREEZE_SOURCE_PATH / "setup.cfg"
+
+BUILD_BREEZE_DIR.mkdir(parents=True, exist_ok=True)
+
+
+def needs_installation() -> bool:
+ """Returns true if Breeze's virtualenv needs (re)installation"""
+ if not BUILD_BREEZE_VENV_DIR.exists() or not
BUILD_BREEZE_CFG_SAVED.exists():
+ return True
+ with open(BREEZE_SETUP_CFG_PATH) as current, open(BUILD_BREEZE_CFG_SAVED)
as saved:
+ current_config, saved_config = current.read(), saved.read()
+ return current_config != saved_config
+
+
+def save_config():
+ """Saves cfg file to virtualenv to check if there is a need for
reinstallation of the virtualenv"""
+ with open(BREEZE_SETUP_CFG_PATH) as current, open(BUILD_BREEZE_CFG_SAVED,
"w") as saved:
+ saved.write(current.read())
+
+
+if needs_installation():
+ print(f"(Re)Installing Breeze's virtualenv in {BUILD_BREEZE_VENV_DIR}")
+ BUILD_BREEZE_VENV_DIR.mkdir(parents=True, exist_ok=True)
+ subprocess.Popen([sys.executable, "-m", "venv",
f"{BUILD_BREEZE_VENV_DIR}"]).wait()
+ subprocess.Popen(
+ [f"{BUILD_BREEZE_VENV_PIP}", "install", "--upgrade", "-e", "."],
cwd=BREEZE_SOURCE_PATH
+ ).wait()
Review comment:
```suggestion
subprocess.run([sys.executable, "-m", "venv",
f"{BUILD_BREEZE_VENV_DIR}"], check=True)
subprocess.run(
[f"{BUILD_BREEZE_VENV_PIP}", "install", "--upgrade", "-e", "."],
cwd=BREEZE_SOURCE_PATH,
check=True
)
```
> The recommended approach to invoking subprocesses is to use the run()
function for all use cases it can handle. For more advanced use cases, the
underlying Popen interface can be used directly.
>
> The run() function was added in Python 3.5; if you need to retain
compatibility with older versions, see the Older high-level API section.
https://docs.python.org/3/library/subprocess.html
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]