summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShahwat Dalal <sdalal29@bloomberg.net>2019-04-23 09:45:21 +0100
committerChandan Singh <chandan@chandansingh.net>2019-05-14 22:50:59 +0000
commit27f4f3b7a2fd22c8c812f0f35b32426afe776444 (patch)
treeb71a7ccd7183f182f35c02efaa6ffd996cbbb98f
parentf79351d65c99757ba5f7806e4b0d9c706fca518e (diff)
downloadbuildstream-27f4f3b7a2fd22c8c812f0f35b32426afe776444.tar.gz
pip_element: Install packages pulled by pip_source
In refrence to https://gitlab.com/BuildStream/buildstream/issues/589. `pip.yaml` now installs pip packages from `/.bst_pip_downloads` if the directory exists.
-rw-r--r--buildstream/plugins/elements/pip.yaml12
-rw-r--r--tests/integration/pip_element.py62
2 files changed, 73 insertions, 1 deletions
diff --git a/buildstream/plugins/elements/pip.yaml b/buildstream/plugins/elements/pip.yaml
index b2b3d3857..294d4ad9a 100644
--- a/buildstream/plugins/elements/pip.yaml
+++ b/buildstream/plugins/elements/pip.yaml
@@ -3,6 +3,14 @@
variables:
pip: pip
+ pip-flags: |
+ %{pip} install --no-deps --root=%{install-root} --prefix=%{prefix}
+ pip-install-package: |
+ %{pip-flags} %{conf-root}
+ pip-download-dir: |
+ .bst_pip_downloads
+ pip-install-dependencies: |
+ if [ -e %{pip-download-dir} ]; then %{pip-flags} %{pip-download-dir}/*; fi
config:
@@ -14,7 +22,9 @@ config:
#
install-commands:
- |
- %{pip} install --no-deps --root=%{install-root} --prefix=%{prefix} %{conf-root}
+ %{pip-install-package}
+ - |
+ %{pip-install-dependencies}
# Commands for stripping debugging information out of
# installed binaries
diff --git a/tests/integration/pip_element.py b/tests/integration/pip_element.py
index 9ef163125..94130d9ab 100644
--- a/tests/integration/pip_element.py
+++ b/tests/integration/pip_element.py
@@ -6,6 +6,7 @@ from buildstream import _yaml
from buildstream.testing import cli_integration as cli
from buildstream.testing.integration import assert_contains
+from tests.testutils import setup_pypi_repo
from tests.testutils.site import HAVE_SANDBOX
@@ -67,3 +68,64 @@ def test_pip_run(cli, datafiles):
result = cli.run(project=project, args=['shell', element_name, '/usr/bin/hello'])
assert result.exit_code == 0
assert result.output == 'Hello, world!\n'
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason='Only available with a functioning sandbox')
+def test_pip_element_should_install_pip_deps(cli, datafiles, setup_pypi_repo):
+ project = str(datafiles)
+ elements_path = os.path.join(project, 'elements')
+ element_name = 'pip/hello.bst'
+
+ # check that exotically named packages are imported correctly
+ myreqs_packages = 'alohalib'
+ dependencies = ['app2', 'app.3', 'app-4', 'app_5', 'app.no.6', 'app-no-7', 'app_no_8']
+ mock_packages = {
+ myreqs_packages: {
+ package: {} for package in dependencies
+ }
+ }
+
+ # set up directories
+ pypi_repo = os.path.join(project, 'files', 'pypi-repo')
+ os.makedirs(pypi_repo, exist_ok=True)
+ os.makedirs(os.path.dirname(os.path.join(elements_path, element_name)), exist_ok=True)
+ setup_pypi_repo(mock_packages, pypi_repo)
+
+ # create pip element
+ element = {
+ 'kind': 'pip',
+ 'variables': {
+ 'pip': 'pip3'
+ },
+ 'depends': [{
+ 'filename': 'base.bst'
+ }],
+ 'sources': [
+ {
+ 'kind': 'tar',
+ 'url': 'file://{}/files/hello.tar.xz'.format(project),
+ # FIXME: remove hardcoded ref once issue #1010 is closed
+ 'ref': 'ad96570b552498807abec33c06210bf68378d854ced6753b77916c5ed517610d'
+ },
+ {
+ 'kind': 'pip',
+ 'url': 'file://{}'.format(os.path.realpath(pypi_repo)),
+ 'packages': [myreqs_packages],
+ }
+ ]
+ }
+ _yaml.dump(element, os.path.join(elements_path, element_name))
+
+ result = cli.run(project=project, args=['source', 'track', element_name])
+ assert result.exit_code == 0
+
+ result = cli.run(project=project, args=['build', element_name])
+ assert result.exit_code == 0
+
+ # get installed packages in sandbox
+ installed_packages = set(
+ cli.run(project=project, args=['shell', element_name, 'pip3', 'freeze']).output.split('\n'))
+ # compare with packages that are expected to be installed
+ pip_source_packages = {package.replace('_', "-") + '==0.1' for package in dependencies + [myreqs_packages]}
+ assert pip_source_packages.issubset(installed_packages)