Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove virtualenv dependency #1314

Merged
merged 1 commit into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
gavindsouza committed May 30, 2022
commit e0f6b1735d355e03d9e7dc221231ab33b7dec4c3
13 changes: 10 additions & 3 deletions bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
restart_process_manager,
remove_backups_crontab,
get_venv_path,
get_virtualenv_path,
get_env_cmd,
)
from bench.utils.render import job, step
Expand Down Expand Up @@ -347,14 +348,20 @@ def env(self, python="python3"):
import bench.cli
import click

verbose = bench.cli.verbose

click.secho("Setting Up Environment", fg="yellow")

frappe = os.path.join(self.bench.name, "apps", "frappe")
virtualenv = get_venv_path()
quiet_flag = "" if bench.cli.verbose else "--quiet"
virtualenv = get_virtualenv_path(verbose=verbose)
quiet_flag = "" if verbose else "--quiet"

if not os.path.exists(self.bench.python):
self.run(f"{virtualenv} {quiet_flag} env -p {python}")
if virtualenv:
self.run(f"{virtualenv} {quiet_flag} env -p {python}")
else:
venv = get_venv_path(verbose=verbose)
self.run(f"{venv} env")

self.pip()

Expand Down
30 changes: 18 additions & 12 deletions bench/utils/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,25 @@ def get_env_cmd(cmd, bench_path="."):
return os.path.abspath(os.path.join(bench_path, "env", "bin", cmd))


def get_venv_path():
venv = which("virtualenv")

if not venv:
current_python = sys.executable
with open(os.devnull, "wb") as devnull:
is_venv_installed = not subprocess.call(
[current_python, "-m", "venv", "--help"], stdout=devnull
)
if is_venv_installed:
venv = f"{current_python} -m venv"
def get_virtualenv_path(verbose=False):
virtualenv_path = which("virtualenv")

if not virtualenv_path and verbose:
log("virtualenv cannot be found", level=2)

return virtualenv_path

return venv or log("virtualenv cannot be found", level=2)

def get_venv_path(verbose=False):
current_python = sys.executable
with open(os.devnull, "wb") as devnull:
is_venv_installed = not subprocess.call(
[current_python, "-m", "venv", "--help"], stdout=devnull
)
if is_venv_installed:
return f"{current_python} -m venv"
else:
log("virtualenv cannot be found", level=2)


def update_node_packages(bench_path=".", apps=None):
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ python-crontab~=2.4.0
requests
semantic-version~=2.8.2
setuptools
virtualenv