diff options
author | James Polley <jp@jamezpolley.com> | 2015-09-22 09:20:15 +1000 |
---|---|---|
committer | Sachi King <nakato@nakato.io> | 2015-10-07 15:28:43 +1100 |
commit | 36a2bf130999f06562b5eb063e1c49ae2d6e35a7 (patch) | |
tree | 6758cab5642aa600c3f3a19216d4abcff1972bcb | |
parent | 58ee65d68c12b3aebf7a4e7e75cebc8b04c8598d (diff) | |
download | pbr-36a2bf130999f06562b5eb063e1c49ae2d6e35a7.tar.gz |
Handle the case where cmd.distribution has no pbr attribute1.8.1
This can arise if pbr has been installed indirectly (for instance,
because a package depends on mock which requires pbr) - pbr will be
running, but the cmd.distribution object has no pbr attribute. In this
case, pbr code should not run.
Change-Id: Ib7db0c8ab78e3cb700671f6a123ec603b4dbfdbe
Closes-bug: 1493735
Co-Authored-By: Sachi King <nakato@nakato.io>
-rw-r--r-- | pbr/pbr_json.py | 2 | ||||
-rw-r--r-- | pbr/tests/test_integration.py | 76 |
2 files changed, 77 insertions, 1 deletions
diff --git a/pbr/pbr_json.py b/pbr/pbr_json.py index beaa076..a72e490 100644 --- a/pbr/pbr_json.py +++ b/pbr/pbr_json.py @@ -20,7 +20,7 @@ from pbr import git def write_pbr_json(cmd, basename, filename): - if not cmd.distribution.pbr: + if not hasattr(cmd.distribution, 'pbr') or not cmd.distribution.pbr: return git_dir = git._run_git_functions() if not git_dir: diff --git a/pbr/tests/test_integration.py b/pbr/tests/test_integration.py index 6000bca..c22fa21 100644 --- a/pbr/tests/test_integration.py +++ b/pbr/tests/test_integration.py @@ -13,12 +13,15 @@ import os.path import shlex +import sys import fixtures import testtools +import textwrap import virtualenv from pbr.tests import base +from pbr.tests.test_packaging import TestRepo PIPFLAGS = shlex.split(os.environ.get('PIPFLAGS', '')) PIPVERSION = os.environ.get('PIPVERSION', 'pip') @@ -27,6 +30,7 @@ REPODIR = os.environ.get('REPODIR', '') WHEELHOUSE = os.environ.get('WHEELHOUSE', '') PIP_CMD = ['-m', 'pip'] + PIPFLAGS + ['install', '-f', WHEELHOUSE] PROJECTS = shlex.split(os.environ.get('PROJECTS', '')) +PBR_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..')) def all_projects(): @@ -148,3 +152,75 @@ class TestIntegration(base.BaseTestCase): python = venv.python self.useFixture(base.CapturedSubprocess( 'install-e', [python] + PIP_CMD + ['-e', path])) + + +class TestInstallWithoutPbr(base.BaseTestCase): + + @testtools.skipUnless( + os.environ.get('PBR_INTEGRATION', None) == '1', + 'integration tests not enabled') + def test_install_without_pbr(self): + # Test easy-install of a thing that depends on a thing using pbr + tempdir = self.useFixture(fixtures.TempDir()).path + # A directory containing sdists of the things we're going to depend on + # in using-package. + dist_dir = os.path.join(tempdir, 'distdir') + os.mkdir(dist_dir) + self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir), + allow_fail=False, cwd=PBR_ROOT) + # testpkg - this requires a pbr-using package + test_pkg_dir = os.path.join(tempdir, 'testpkg') + os.mkdir(test_pkg_dir) + with open(os.path.join(test_pkg_dir, 'setup.py'), 'wt') as f: + f.write(textwrap.dedent("""\ + #!/usr/bin/env python + import setuptools + setuptools.setup( + name = 'pkgTest', + tests_require = ['pkgReq'], + test_suite='pkgReq' + ) + """)) + with open(os.path.join(test_pkg_dir, 'setup.cfg'), 'wt') as f: + f.write(textwrap.dedent("""\ + [easy_install] + find_links = %s + """ % dist_dir)) + repoTest = self.useFixture(TestRepo(test_pkg_dir)) + repoTest.commit() + # reqpkg - this is a package that requires pbr + req_pkg_dir = os.path.join(tempdir, 'reqpkg') + pkg_req_module = os.path.join(req_pkg_dir, 'pkgReq/') + os.makedirs(pkg_req_module) + with open(os.path.join(req_pkg_dir, 'setup.py'), 'wt') as f: + f.write(textwrap.dedent("""\ + #!/usr/bin/env python + import setuptools + setuptools.setup( + setup_requires=['pbr'], + pbr=True + ) + """)) + with open(os.path.join(req_pkg_dir, 'setup.cfg'), 'wt') as f: + f.write(textwrap.dedent("""\ + [metadata] + name = pkgReq + """)) + with open(os.path.join(req_pkg_dir, 'requirements.txt'), 'wt') as f: + f.write(textwrap.dedent("""\ + pbr + """)) + with open(os.path.join(req_pkg_dir, 'pkgReq/__init__.py'), 'wt') as f: + f.write(textwrap.dedent("""\ + print("FakeTest loaded and ran") + """)) + repoReq = self.useFixture(TestRepo(req_pkg_dir)) + repoReq.commit() + self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir), + allow_fail=False, cwd=req_pkg_dir) + # A venv to test within + venv = self.useFixture(Venv('nopbr', install_pbr=False)) + python = venv.python + # Run the depending script + self.useFixture(base.CapturedSubprocess( + 'nopbr', [python] + ['setup.py', 'test'], cwd=test_pkg_dir)) |