Skip to content

Commit

Permalink
Unset PIP_REQUIRE_VIRTUALENV when running 'pip'
Browse files Browse the repository at this point in the history
If the PIP_REQUIRE_VIRTUALENV environment variable is set, it blocks `pip install` from running without a virtualenv being activated. This broke using `python -m pep517.build` on my project:

```
$ python -m pep517.build .
ERROR: Could not find an activated virtualenv (required).
Traceback (most recent call last):
  File "/Users/chainz/.pyenv/versions/3.8.3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/chainz/.pyenv/versions/3.8.3/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/chainz/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pep517/build.py", line 124, in <module>
    main(parser.parse_args())
  File "/Users/chainz/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pep517/build.py", line 120, in main
    build(args.source_dir, dist, args.out_dir)
  File "/Users/chainz/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pep517/build.py", line 87, in build
    env.pip_install(system['requires'])
  File "/Users/chainz/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pep517/envbuild.py", line 100, in pip_install
    check_call(
  File "/Users/chainz/.pyenv/versions/3.8.3/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/Users/chainz/.pyenv/versions/3.8.3/bin/python', '-m', 'pip', 'install', '--ignore-installed', '--prefix', '/var/folders/kq/02p9h16n7zv_z7bhzmg6y_pm0000gn/T/pep517-build-env-fkh9ckg8', 'setuptools >= 40.6.0', 'wheel']' returned non-zero exit status 3.
```

This change makes pep517 unset the environment variable since its installs are safe to run.
  • Loading branch information
adamchainz committed Jul 10, 2020
1 parent 3f1949a commit a03b4e8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pep517/envbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import toml
import shutil
from subprocess import check_call
import subprocess
import sys
from sysconfig import get_paths
from tempfile import mkdtemp
Expand Down Expand Up @@ -97,11 +97,17 @@ def pip_install(self, reqs):
cmd = [
sys.executable, '-m', 'pip', 'install', '--ignore-installed',
'--prefix', self.path] + list(reqs)
check_call(
env = os.environ.copy()
# Allow pip to operate without an activated virtualenv
env.pop("PIP_REQUIRE_VIRTUALENV", None)
retcode = subprocess.Popen(
cmd,
stdout=LoggerWrapper(log, logging.INFO),
stderr=LoggerWrapper(log, logging.ERROR),
)
env=env,
).wait()
if retcode != 0:
raise subprocess.CalledProcessError(retcode, cmd)

def __exit__(self, exc_type, exc_val, exc_tb):
needs_cleanup = (
Expand Down

0 comments on commit a03b4e8

Please sign in to comment.