Reinstate our old virtual env check in favor of pip (#12932)

This commit is contained in:
Paulus Schoutsen 2018-03-05 15:51:37 -08:00 committed by GitHub
parent 03225cf20f
commit 38af04c6ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions

View file

@ -39,6 +39,6 @@ def pip_kwargs(config_dir):
kwargs = {
'constraints': os.path.join(os.path.dirname(__file__), CONSTRAINT_FILE)
}
if not pkg_util.running_under_virtualenv():
if not pkg_util.is_virtual_env():
kwargs['target'] = os.path.join(config_dir, 'deps')
return kwargs

View file

@ -7,7 +7,6 @@ import sys
import threading
from urllib.parse import urlparse
from pip.locations import running_under_virtualenv
from typing import Optional
import pkg_resources
@ -17,6 +16,13 @@ _LOGGER = logging.getLogger(__name__)
INSTALL_LOCK = threading.Lock()
def is_virtual_env():
"""Return if we run in a virtual environtment."""
# Check supports venv && virtualenv
return (getattr(sys, 'base_prefix', sys.prefix) != sys.prefix or
hasattr(sys, 'real_prefix'))
def install_package(package: str, upgrade: bool = True,
target: Optional[str] = None,
constraints: Optional[str] = None) -> bool:
@ -37,7 +43,7 @@ def install_package(package: str, upgrade: bool = True,
if constraints is not None:
args += ['--constraint', constraints]
if target:
assert not running_under_virtualenv()
assert not is_virtual_env()
# This only works if not running in venv
args += ['--user']
env['PYTHONUSERBASE'] = os.path.abspath(target)

View file

@ -24,7 +24,7 @@ class TestRequirements:
self.hass.stop()
@mock.patch('os.path.dirname')
@mock.patch('homeassistant.util.package.running_under_virtualenv',
@mock.patch('homeassistant.util.package.is_virtual_env',
return_value=True)
@mock.patch('homeassistant.util.package.install_package',
return_value=True)
@ -43,7 +43,7 @@ class TestRequirements:
constraints=os.path.join('ha_package_path', CONSTRAINT_FILE))
@mock.patch('os.path.dirname')
@mock.patch('homeassistant.util.package.running_under_virtualenv',
@mock.patch('homeassistant.util.package.is_virtual_env',
return_value=False)
@mock.patch('homeassistant.util.package.install_package',
return_value=True)

View file

@ -68,8 +68,8 @@ def mock_env_copy():
@pytest.fixture
def mock_venv():
"""Mock homeassistant.util.package.running_under_virtualenv."""
with patch('homeassistant.util.package.running_under_virtualenv') as mock:
"""Mock homeassistant.util.package.is_virtual_env."""
with patch('homeassistant.util.package.is_virtual_env') as mock:
mock.return_value = True
yield mock