Make deps directory persistent over upgrades (#7801)

* Use pip install --user if venv not active

* Set PYTHONUSERBASE to deps directory, when installing with --user
  option.
* Reset --prefix option to workaround incompatability when installing
  with --user option. This requires pip version 8.0.0 or greater.
* Require pip version 8.0.3.
* Do not delete deps directory on home assistant upgrade.
* Fix local lib mount and check package exist.

* Update and add tests

* Fix upgrade from before version 0.46

* Extract function to get user site

* Add function(s) to package util to get user site.
* Use async subprocess for one of the functions to get user site.
* Add function to package util to check if virtual environment is
  active.
* Add and update tests.

* Update version for last removal of deps dir

* Address comments

* Rewrite package util tests with pytest

* Rewrite all existing unittest class based tests for package util as
  test functions, and capitalize pytest fixtures.
* Add test for installing with target inside venv.
This commit is contained in:
Martin Hjelmare authored and Paulus Schoutsen committed 2017-07-13 19:26:21 -07:00
1 parent 5581c6295e
commit ba019c799a
11 files changed
+364 -167

No files matched your search

+10 -2
View File
@@ -7,7 +7,8 @@ import logging
from typing import List
from homeassistant.config import get_default_config_dir
from homeassistant.util.package import install_package
from homeassistant.const import CONSTRAINT_FILE
from homeassistant.util.package import install_package, is_virtual_env
from homeassistant.bootstrap import mount_local_lib_path
@@ -40,7 +41,14 @@ def run(args: List) -> int:
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
for req in getattr(script, 'REQUIREMENTS', []):
if not install_package(req, target=deps_dir):
if is_virtual_env():
returncode = install_package(req, constraints=os.path.join(
os.path.dirname(__file__), os.pardir, CONSTRAINT_FILE))
else:
returncode = install_package(
req, target=deps_dir, constraints=os.path.join(
os.path.dirname(__file__), os.pardir, CONSTRAINT_FILE))
if not returncode:
print('Aborting scipt, could not install dependency', req)
return 1