From 7f1c5ad9c673f158885b083c39000d071f6400a0 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 29 Nov 2022 12:23:13 +0530 Subject: [PATCH 1/5] fix: migrate_env silent failures --- bench/utils/bench.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 5467256a..eb2b00eb 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -223,7 +223,8 @@ def migrate_env(python, backup=False): logger.log(f"Migration Successful to {python}") except Exception: if venv_creation or packages_setup: - logger.warning("Migration Error") + logger.warning("Migration Error", exc_info=True) + raise def validate_upgrade(from_ver, to_ver, bench_path="."): From 61e0f4acbf4b7e95da2d1d0b26516cd41bfc6eed Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 29 Nov 2022 12:23:49 +0530 Subject: [PATCH 2/5] fix: correct python path for migrate_env Currently it's executing env directory which would never work. --- bench/utils/bench.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index eb2b00eb..742dc5ba 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -218,7 +218,7 @@ def migrate_env(python, backup=False): venv_creation = exec_cmd(f"{virtualenv} --python {python} {pvenv}") apps = " ".join([f"-e {os.path.join('apps', app)}" for app in bench.apps]) - packages_setup = exec_cmd(f"{pvenv} -m pip install --upgrade {apps}") + packages_setup = exec_cmd(f"{pvenv}/bin/python -m pip install --upgrade {apps}") logger.log(f"Migration Successful to {python}") except Exception: From 4f0193ca9349d971e1ce3087c556b9710bc5db69 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 29 Nov 2022 12:33:53 +0530 Subject: [PATCH 3/5] fix: install one app at a time, frappe first --- bench/utils/bench.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 742dc5ba..8922814e 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -212,18 +212,23 @@ def migrate_env(python, backup=False): shutil.move(dest, target) # Create virtualenv using specified python - venv_creation, packages_setup = 1, 1 + def _install_app(app): + app_path = f"-e {os.path.join('apps', app)}" + exec_cmd(f"{pvenv}/bin/python -m pip install --upgrade {app_path}") + try: logger.log(f"Setting up a New Virtual {python} Environment") - venv_creation = exec_cmd(f"{virtualenv} --python {python} {pvenv}") + exec_cmd(f"{virtualenv} --python {python} {pvenv}") - apps = " ".join([f"-e {os.path.join('apps', app)}" for app in bench.apps]) - packages_setup = exec_cmd(f"{pvenv}/bin/python -m pip install --upgrade {apps}") + # Install frappe first + _install_app("frappe") + for app in bench.apps: + if str(app) != "frappe": + _install_app(app) logger.log(f"Migration Successful to {python}") except Exception: - if venv_creation or packages_setup: - logger.warning("Migration Error", exc_info=True) + logger.warning("Python env migration Error", exc_info=True) raise From e37df969c1641eda06ecf84f4ad63310f37f9183 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 29 Nov 2022 12:40:11 +0530 Subject: [PATCH 4/5] refactor(migrate_env): virtualenv -> venv --- bench/utils/bench.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 8922814e..c324c063 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -175,10 +175,6 @@ def migrate_env(python, backup=False): nvenv = "env" path = os.getcwd() python = which(python) - virtualenv = which("virtualenv") - if not virtualenv: - raise FileNotFoundError("`virtualenv` not found. Install it and try again.") - pvenv = os.path.join(path, nvenv) # Clear Cache before Bench Dies. @@ -218,7 +214,7 @@ def migrate_env(python, backup=False): try: logger.log(f"Setting up a New Virtual {python} Environment") - exec_cmd(f"{virtualenv} --python {python} {pvenv}") + exec_cmd(f"{python} -m venv {pvenv}") # Install frappe first _install_app("frappe") From 0e59159e1167357f6d8411708a93ad37cc4b959e Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 29 Nov 2022 12:49:19 +0530 Subject: [PATCH 5/5] fix: dont attempt migrating to active virtualenv --- bench/utils/bench.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index c324c063..62f3e596 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -177,6 +177,15 @@ def migrate_env(python, backup=False): python = which(python) pvenv = os.path.join(path, nvenv) + if python.startswith(pvenv): + # The supplied python version is in active virtualenv which we are about to nuke. + click.secho( + "Python version supplied is present in currently sourced virtual environment.\n" + "`deactiviate` the current virtual environment before migrating environments.", + fg="yellow", + ) + sys.exit(1) + # Clear Cache before Bench Dies. try: config = bench.conf