From b0ccb6efbea33acdb07b3500a07b37c8ffbeae23 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 23 Apr 2021 18:37:03 +0530 Subject: [PATCH] fix: Invoke pip via python Due to "WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly." --- bench/app.py | 8 ++++---- bench/commands/make.py | 4 ++-- bench/utils.py | 15 +++++++-------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/bench/app.py b/bench/app.py index 7ebaf8ff..872270ac 100755 --- a/bench/app.py +++ b/bench/app.py @@ -174,12 +174,12 @@ def install_app(app, bench_path=".", verbose=False, no_cache=False, restart_benc print('\n{0}Installing {1}{2}'.format(color.yellow, app, color.nc)) logger.log("installing {}".format(app)) - pip_path = os.path.join(bench_path, "env", "bin", "pip") + python_path = os.path.join(bench_path, "env", "bin", "python") quiet_flag = "-q" if not verbose else "" app_path = os.path.join(bench_path, "apps", app) cache_flag = "--no-cache-dir" if no_cache else "" - exec_cmd("{pip} install {quiet} -U -e {app} {no_cache}".format(pip=pip_path, quiet=quiet_flag, app=app_path, no_cache=cache_flag)) + exec_cmd("{py_path} -m pip install {quiet} -U -e {app} {no_cache}".format(py_path=python_path, quiet=quiet_flag, app=app_path, no_cache=cache_flag)) if os.path.exists(os.path.join(app_path, 'package.json')): exec_cmd("yarn install", cwd=app_path) @@ -208,7 +208,7 @@ def remove_app(app, bench_path='.'): app_path = os.path.join(bench_path, 'apps', app) site_path = os.path.join(bench_path, 'sites') - pip = os.path.join(bench_path, 'env', 'bin', 'pip') + py = os.path.join(bench_path, 'env', 'bin', 'python') for site in os.listdir(site_path): req_file = os.path.join(site_path, site, 'site_config.json') @@ -218,7 +218,7 @@ def remove_app(app, bench_path='.'): print("Cannot remove, app is installed on site: {0}".format(site)) sys.exit(1) - exec_cmd("{0} uninstall -y {1}".format(pip, app), cwd=bench_path) + exec_cmd("{0} -m pip uninstall -y {1}".format(py, app), cwd=bench_path) remove_from_appstxt(app, bench_path) shutil.rmtree(app_path) run_frappe_cmd("build", bench_path=bench_path) diff --git a/bench/commands/make.py b/bench/commands/make.py index c20b25b3..f47a72e0 100755 --- a/bench/commands/make.py +++ b/bench/commands/make.py @@ -98,5 +98,5 @@ def pip(ctx, args): "Run pip commands in bench env" import os from bench.utils import get_env_cmd - env_pip = get_env_cmd('pip') - os.execv(env_pip, (env_pip,) + args) + env_py = get_env_cmd('python') + os.execv(env_py, (env_py, '-m', 'pip') + args) diff --git a/bench/utils.py b/bench/utils.py index ede9b169..7bb312ba 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -339,13 +339,13 @@ def get_venv_path(): def setup_env(bench_path='.', python='python3'): frappe = os.path.join(bench_path, "apps", "frappe") - pip = os.path.join(bench_path, "env", "bin", "pip") + py = os.path.join(bench_path, "env", "bin", "python") virtualenv = get_venv_path() exec_cmd('{} -q env -p {}'.format(virtualenv, python), cwd=bench_path) if os.path.exists(frappe): - exec_cmd('{} install -q -U -e {}'.format(pip, frappe), cwd=bench_path) + exec_cmd('{} -m pip install -q -U -e {}'.format(py, frappe), cwd=bench_path) def setup_socketio(bench_path='.'): @@ -555,8 +555,8 @@ def set_default_site(site, bench_path='.'): def update_env_pip(bench_path): - env_pip = os.path.join(bench_path, 'env', 'bin', 'pip') - exec_cmd("{pip} install -q -U pip".format(pip=env_pip)) + env_py = os.path.join(bench_path, 'env', 'bin', 'python') + exec_cmd("{env_py} -m pip install -q -U pip".format(env_py=env_py)) def update_requirements(bench_path='.'): @@ -571,14 +571,14 @@ def update_requirements(bench_path='.'): def update_python_packages(bench_path='.'): from bench.app import get_apps - pip_path = os.path.join(bench_path, "env", "bin", "pip") + env_py = os.path.join(bench_path, "env", "bin", "python") print('Updating Python libraries...') update_env_pip(bench_path) for app in get_apps(): print('\n{0}Installing python dependencies for {1}{2}'.format(color.yellow, app, color.nc)) app_path = os.path.join(bench_path, "apps", app) - exec_cmd("{0} install -q -U -e {1}".format(pip_path, app_path), cwd=bench_path) + exec_cmd("{0} -m pip install -q -U -e {1}".format(env_py, app_path), cwd=bench_path) def update_node_packages(bench_path='.'): @@ -965,7 +965,6 @@ def migrate_env(python, backup=False): python = which(python) virtualenv = which('virtualenv') pvenv = os.path.join(path, nvenv) - pip = os.path.join(pvenv, 'bin', 'pip') # Clear Cache before Bench Dies. try: @@ -1006,7 +1005,7 @@ def migrate_env(python, backup=False): venv_creation = exec_cmd('{virtualenv} --python {python} {pvenv}'.format(virtualenv=virtualenv, python=python, pvenv=pvenv)) apps = ' '.join(["-e {}".format(os.path.join("apps", app)) for app in get_apps()]) - packages_setup = exec_cmd('{0} install -q -U {1}'.format(pip, apps)) + packages_setup = exec_cmd('{0} -m pip install -q -U {1}'.format(pvenv, apps)) logger.log('Migration Successful to {}'.format(python)) except: