From f60c2d0def62eb689aecd6f6174dc8dd7130b42f Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 2 Aug 2022 11:54:00 +0530 Subject: [PATCH] fix: Use venv module instead of virtualenv Only migrate-env requires virtualenv wrapper. However, it can be installed and run manually too. Virtualenv wrapper is patched in debian to change the path of bins - which venv is free from. --- bench/bench.py | 11 +++-------- bench/commands/setup.py | 2 +- bench/utils/__init__.py | 8 ++------ bench/utils/bench.py | 3 +++ docs/bench_usage.md | 2 +- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/bench/bench.py b/bench/bench.py index 3d286bf1..a331e270 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -30,7 +30,6 @@ from bench.utils.bench import ( restart_process_manager, remove_backups_crontab, get_venv_path, - get_virtualenv_path, get_env_cmd, ) from bench.utils.render import job, step @@ -71,7 +70,7 @@ class Bench(Base, Validator): @property def python(self) -> str: - return get_env_cmd("python", bench_path=self.name) + return get_env_cmd("python*", bench_path=self.name) @property def shallow_clone(self) -> bool: @@ -347,15 +346,11 @@ class BenchSetup(Base): click.secho("Setting Up Environment", fg="yellow") frappe = os.path.join(self.bench.name, "apps", "frappe") - virtualenv = get_virtualenv_path(verbose=verbose) quiet_flag = "" if verbose else "--quiet" if not os.path.exists(self.bench.python): - if virtualenv: - self.run(f"{virtualenv} {quiet_flag} env -p {python}", cwd=self.bench.name) - else: - venv = get_venv_path(verbose=verbose, python=python) - self.run(f"{venv} env", cwd=self.bench.name) + venv = get_venv_path(verbose=verbose, python=python) + self.run(f"{venv} env", cwd=self.bench.name) self.pip() diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 4139e8fb..4d1fa88a 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -96,7 +96,7 @@ def setup_backups(): Bench(".").setup.backups() -@click.command("env", help="Setup virtualenv for bench") +@click.command("env", help="Setup Python environment for bench") @click.option( "--python", type=str, default="python3", help="Path to Python Executable." ) diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index 952ca2a4..778e5319 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -234,7 +234,7 @@ def run_frappe_cmd(*args, **kwargs): f = get_env_cmd("python", bench_path=bench_path) sites_dir = os.path.join(bench_path, "sites") - is_async = False if from_command_line else True + is_async = not from_command_line if is_async: stderr = stdout = subprocess.PIPE else: @@ -247,11 +247,7 @@ def run_frappe_cmd(*args, **kwargs): stderr=stderr, ) - if is_async: - return_code = print_output(p) - else: - return_code = p.wait() - + return_code = print_output(p) if is_async else p.wait() if return_code > 0: sys.exit(return_code) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 999915ad..f2644db7 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -172,6 +172,9 @@ def migrate_env(python, backup=False): 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. diff --git a/docs/bench_usage.md b/docs/bench_usage.md index 7bf52a1a..07b7e080 100644 --- a/docs/bench_usage.md +++ b/docs/bench_usage.md @@ -130,7 +130,7 @@ The setup commands used for setting up the Frappe environment in context of the - **sudoers**: Add commands to sudoers list for allowing bench commands execution without root password - - **env**: Setup virtualenv for bench. This sets up a `env` folder under the root of the bench directory. + - **env**: Setup Python virtual environment for bench. This sets up a `env` folder under the root of the bench directory. - **redis**: Generates configuration for Redis - **fonts**: Add Frappe fonts to system - **config**: Generate or over-write sites/common_site_config.json