Fix check for running inside venv (#8481)

* Import and use the function from pip instead of defining it
  ourselves.
* Fix tests.
This commit is contained in:
Martin Hjelmare authored and Paulus Schoutsen committed 2017-07-15 07:25:02 -07:00
1 parent 6ca828fd14
commit 543e8bb62e
5 files changed
+36 -24

No files matched your search

+3 -7
View File
@@ -2,11 +2,12 @@
import asyncio
import logging
import os
from subprocess import PIPE, Popen
import sys
import threading
from subprocess import Popen, PIPE
from urllib.parse import urlparse
from pip.locations import running_under_virtualenv
from typing import Optional
import pkg_resources
@@ -36,7 +37,7 @@ def install_package(package: str, upgrade: bool=True,
if constraints is not None:
args += ['--constraint', constraints]
if target:
assert not is_virtual_env()
assert not running_under_virtualenv()
# This only works if not running in venv
args += ['--user']
env['PYTHONUSERBASE'] = os.path.abspath(target)
@@ -70,11 +71,6 @@ def check_package_exists(package: str) -> bool:
return any(dist in req for dist in env[req.project_name])
def is_virtual_env() -> bool:
"""Return true if environment is a virtual environment."""
return hasattr(sys, 'real_prefix')
def _get_user_site(deps_dir: str) -> tuple:
"""Get arguments and environment for subprocess used in get_user_site."""
env = os.environ.copy()