Merge ~cjwatson/ols-charm-deps:pip-install-code-dir into ols-charm-deps:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 4a649436a8ef9f1af64f469e2b7542b22937cff3
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/ols-charm-deps:pip-install-code-dir
Merge into: ols-charm-deps:master
Diff against target: 78 lines (+51/-5)
2 files modified
layer/ols/lib/ols/base.py (+13/-5)
layer/ols/unit_tests/test_ols.py (+38/-0)
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+381664@code.launchpad.net

Commit message

Tell pip to install code dir if it has setup.py

Description of the change

It's sometimes useful to have entry points in the code directory's setup.py that install scripts: for example, lp-signing does this. Support this by adding the code directory to pip's arguments, provided that a setup.py exists there.

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/layer/ols/lib/ols/base.py b/layer/ols/lib/ols/base.py
index 357ad0a..df9d984 100644
--- a/layer/ols/lib/ols/base.py
+++ b/layer/ols/lib/ols/base.py
@@ -374,11 +374,19 @@ def create_virtualenv(wheels_dir, codedir, python_exe):
374 requirements = os.path.join(codedir, 'requirements.txt')374 requirements = os.path.join(codedir, 'requirements.txt')
375375
376 hookenv.log('Installing from local wheelhouse.')376 hookenv.log('Installing from local wheelhouse.')
377 subprocess.check_call(['%s/bin/pip' % env_dir,377 pip_args = [
378 'install',378 '%s/bin/pip' % env_dir,
379 '--no-index',379 'install',
380 '--find-links={}'.format(wheels_dir),380 '--no-index',
381 '-r', requirements])381 '--find-links={}'.format(wheels_dir),
382 '-r', requirements,
383 ]
384 # The payload may have a setup.py. If so, tell pip to install the code
385 # directory as well, so that any entry points configured by the payload
386 # will have corresponding scripts built for them.
387 if os.path.exists(os.path.join(codedir, 'setup.py')):
388 pip_args.append(codedir)
389 subprocess.check_call(pip_args)
382390
383391
384def render_template(template, context):392def render_template(template, context):
diff --git a/layer/ols/unit_tests/test_ols.py b/layer/ols/unit_tests/test_ols.py
index b982636..adef577 100644
--- a/layer/ols/unit_tests/test_ols.py
+++ b/layer/ols/unit_tests/test_ols.py
@@ -489,6 +489,44 @@ class BaseTest(TestCase):
489 call('Installing python packages into the venv'),489 call('Installing python packages into the venv'),
490 call('Installing from local wheelhouse.')])490 call('Installing from local wheelhouse.')])
491491
492 @patch.object(hookenv, 'log')
493 def test_create_virtualenv_with_setup_py(self, log):
494 env_dir = os.path.join(base.code_dir(), 'env')
495 wheels_dir = os.path.join(base.code_dir(), 'wheels')
496 requirements = os.path.join(base.code_dir(), 'requirements.txt')
497 setup_py = os.path.join(base.code_dir(), 'setup.py')
498 os.makedirs(base.code_dir())
499 with open(setup_py, 'w'):
500 pass
501 ps = FakeProcesses()
502 self.useFixture(ps)
503 venv_ok = Mock()
504 venv_ok.return_value = {'returncode': 0}
505 ps.add(venv_ok, name='virtualenv')
506 pip = Mock()
507 pip.return_value = {'returncode': 0}
508 pip_bin = '%s/bin/pip' % (env_dir)
509 ps.add(pip, name=pip_bin)
510
511 base.create_virtualenv(wheels_dir, base.code_dir(),
512 base.python_bin())
513
514 venv_ok.assert_called_once_with({'args': [
515 'virtualenv',
516 '--no-download',
517 '--extra-search-dir=/srv/testservice/code/wheels',
518 '-p', 'python3',
519 '--extra-search-dir', '/srv/testservice/code/wheels',
520 '/srv/testservice/code/env']})
521
522 pip.assert_called_once_with({'args': [
523 pip_bin, 'install', '--no-index',
524 '--find-links={}'.format(wheels_dir), '-r', requirements,
525 base.code_dir()]})
526 log.assert_has_calls([
527 call('Installing python packages into the venv'),
528 call('Installing from local wheelhouse.')])
529
492 def test_render_template(self):530 def test_render_template(self):
493 tmpl = """531 tmpl = """
494 {% if True %}532 {% if True %}

Subscribers

People subscribed via source and target branches