mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Reinstate our old virtual env check in favor of pip (#12932)
This commit is contained in:
parent
03225cf20f
commit
38af04c6ce
@ -39,6 +39,6 @@ def pip_kwargs(config_dir):
|
|||||||
kwargs = {
|
kwargs = {
|
||||||
'constraints': os.path.join(os.path.dirname(__file__), CONSTRAINT_FILE)
|
'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')
|
kwargs['target'] = os.path.join(config_dir, 'deps')
|
||||||
return kwargs
|
return kwargs
|
||||||
|
@ -7,7 +7,6 @@ import sys
|
|||||||
import threading
|
import threading
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from pip.locations import running_under_virtualenv
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
@ -17,6 +16,13 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
INSTALL_LOCK = threading.Lock()
|
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,
|
def install_package(package: str, upgrade: bool = True,
|
||||||
target: Optional[str] = None,
|
target: Optional[str] = None,
|
||||||
constraints: Optional[str] = None) -> bool:
|
constraints: Optional[str] = None) -> bool:
|
||||||
@ -37,7 +43,7 @@ def install_package(package: str, upgrade: bool = True,
|
|||||||
if constraints is not None:
|
if constraints is not None:
|
||||||
args += ['--constraint', constraints]
|
args += ['--constraint', constraints]
|
||||||
if target:
|
if target:
|
||||||
assert not running_under_virtualenv()
|
assert not is_virtual_env()
|
||||||
# This only works if not running in venv
|
# This only works if not running in venv
|
||||||
args += ['--user']
|
args += ['--user']
|
||||||
env['PYTHONUSERBASE'] = os.path.abspath(target)
|
env['PYTHONUSERBASE'] = os.path.abspath(target)
|
||||||
|
@ -24,7 +24,7 @@ class TestRequirements:
|
|||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
@mock.patch('os.path.dirname')
|
@mock.patch('os.path.dirname')
|
||||||
@mock.patch('homeassistant.util.package.running_under_virtualenv',
|
@mock.patch('homeassistant.util.package.is_virtual_env',
|
||||||
return_value=True)
|
return_value=True)
|
||||||
@mock.patch('homeassistant.util.package.install_package',
|
@mock.patch('homeassistant.util.package.install_package',
|
||||||
return_value=True)
|
return_value=True)
|
||||||
@ -43,7 +43,7 @@ class TestRequirements:
|
|||||||
constraints=os.path.join('ha_package_path', CONSTRAINT_FILE))
|
constraints=os.path.join('ha_package_path', CONSTRAINT_FILE))
|
||||||
|
|
||||||
@mock.patch('os.path.dirname')
|
@mock.patch('os.path.dirname')
|
||||||
@mock.patch('homeassistant.util.package.running_under_virtualenv',
|
@mock.patch('homeassistant.util.package.is_virtual_env',
|
||||||
return_value=False)
|
return_value=False)
|
||||||
@mock.patch('homeassistant.util.package.install_package',
|
@mock.patch('homeassistant.util.package.install_package',
|
||||||
return_value=True)
|
return_value=True)
|
||||||
|
@ -68,8 +68,8 @@ def mock_env_copy():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_venv():
|
def mock_venv():
|
||||||
"""Mock homeassistant.util.package.running_under_virtualenv."""
|
"""Mock homeassistant.util.package.is_virtual_env."""
|
||||||
with patch('homeassistant.util.package.running_under_virtualenv') as mock:
|
with patch('homeassistant.util.package.is_virtual_env') as mock:
|
||||||
mock.return_value = True
|
mock.return_value = True
|
||||||
yield mock
|
yield mock
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user