mirror of
https://github.com/frappe/bench.git
synced 2024-11-16 01:57:08 +00:00
fix: Remove virtualenv dependency
Use virtualenv cli only if found in PATH. Else use venv package of the invoker's Python installation. venv was added in the std lib since PY33. ref: https://docs.python.org/3/library/venv.html
This commit is contained in:
parent
a88932592e
commit
e0f6b1735d
@ -29,6 +29,7 @@ from bench.utils.bench import (
|
|||||||
restart_process_manager,
|
restart_process_manager,
|
||||||
remove_backups_crontab,
|
remove_backups_crontab,
|
||||||
get_venv_path,
|
get_venv_path,
|
||||||
|
get_virtualenv_path,
|
||||||
get_env_cmd,
|
get_env_cmd,
|
||||||
)
|
)
|
||||||
from bench.utils.render import job, step
|
from bench.utils.render import job, step
|
||||||
@ -347,14 +348,20 @@ class BenchSetup(Base):
|
|||||||
import bench.cli
|
import bench.cli
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
verbose = bench.cli.verbose
|
||||||
|
|
||||||
click.secho("Setting Up Environment", fg="yellow")
|
click.secho("Setting Up Environment", fg="yellow")
|
||||||
|
|
||||||
frappe = os.path.join(self.bench.name, "apps", "frappe")
|
frappe = os.path.join(self.bench.name, "apps", "frappe")
|
||||||
virtualenv = get_venv_path()
|
virtualenv = get_virtualenv_path(verbose=verbose)
|
||||||
quiet_flag = "" if bench.cli.verbose else "--quiet"
|
quiet_flag = "" if verbose else "--quiet"
|
||||||
|
|
||||||
if not os.path.exists(self.bench.python):
|
if not os.path.exists(self.bench.python):
|
||||||
|
if virtualenv:
|
||||||
self.run(f"{virtualenv} {quiet_flag} env -p {python}")
|
self.run(f"{virtualenv} {quiet_flag} env -p {python}")
|
||||||
|
else:
|
||||||
|
venv = get_venv_path(verbose=verbose)
|
||||||
|
self.run(f"{venv} env")
|
||||||
|
|
||||||
self.pip()
|
self.pip()
|
||||||
|
|
||||||
|
@ -33,19 +33,25 @@ def get_env_cmd(cmd, bench_path="."):
|
|||||||
return os.path.abspath(os.path.join(bench_path, "env", "bin", cmd))
|
return os.path.abspath(os.path.join(bench_path, "env", "bin", cmd))
|
||||||
|
|
||||||
|
|
||||||
def get_venv_path():
|
def get_virtualenv_path(verbose=False):
|
||||||
venv = which("virtualenv")
|
virtualenv_path = which("virtualenv")
|
||||||
|
|
||||||
if not venv:
|
if not virtualenv_path and verbose:
|
||||||
|
log("virtualenv cannot be found", level=2)
|
||||||
|
|
||||||
|
return virtualenv_path
|
||||||
|
|
||||||
|
|
||||||
|
def get_venv_path(verbose=False):
|
||||||
current_python = sys.executable
|
current_python = sys.executable
|
||||||
with open(os.devnull, "wb") as devnull:
|
with open(os.devnull, "wb") as devnull:
|
||||||
is_venv_installed = not subprocess.call(
|
is_venv_installed = not subprocess.call(
|
||||||
[current_python, "-m", "venv", "--help"], stdout=devnull
|
[current_python, "-m", "venv", "--help"], stdout=devnull
|
||||||
)
|
)
|
||||||
if is_venv_installed:
|
if is_venv_installed:
|
||||||
venv = f"{current_python} -m venv"
|
return f"{current_python} -m venv"
|
||||||
|
else:
|
||||||
return venv or log("virtualenv cannot be found", level=2)
|
log("virtualenv cannot be found", level=2)
|
||||||
|
|
||||||
|
|
||||||
def update_node_packages(bench_path=".", apps=None):
|
def update_node_packages(bench_path=".", apps=None):
|
||||||
|
@ -6,4 +6,3 @@ python-crontab~=2.4.0
|
|||||||
requests
|
requests
|
||||||
semantic-version~=2.8.2
|
semantic-version~=2.8.2
|
||||||
setuptools
|
setuptools
|
||||||
virtualenv
|
|
||||||
|
Loading…
Reference in New Issue
Block a user