diff options
-rw-r--r-- | doc/source/semver.rst | 2 | ||||
-rw-r--r-- | pbr/core.py | 115 | ||||
-rw-r--r-- | pbr/testr_command.py | 2 | ||||
-rw-r--r-- | pbr/tests/base.py | 15 | ||||
-rw-r--r-- | pbr/tests/test_packaging.py | 9 | ||||
-rw-r--r-- | setup.cfg | 2 | ||||
-rw-r--r-- | tools/integration.sh | 28 |
7 files changed, 108 insertions, 65 deletions
diff --git a/doc/source/semver.rst b/doc/source/semver.rst index af60fea..8b10112 100644 --- a/doc/source/semver.rst +++ b/doc/source/semver.rst @@ -131,7 +131,7 @@ document are to be interpreted as described in `RFC communication of not-yet-released ideas. Example: 1.0.0.dev1. #. git version metadata MAY be denoted by appending a dot separated - identifier immediately following a development version. + identifier immediately following a development or pre-release version. The identifier MUST comprise the character g followed by a seven character git short-sha. The sha MUST NOT be empty. git version metadata MUST be ignored when determining version precedence. Thus diff --git a/pbr/core.py b/pbr/core.py index f622ad0..0aff652 100644 --- a/pbr/core.py +++ b/pbr/core.py @@ -49,7 +49,17 @@ from setuptools import dist from pbr import util -core.Distribution = dist._get_unpatched(core.Distribution) +_saved_core_distribution = core.Distribution + + +def _monkeypatch_distribution(): + core.Distribution = dist._get_unpatched(core.Distribution) + + +def _restore_distribution_monkeypatch(): + core.Distribution = _saved_core_distribution + + if sys.version_info[0] == 3: string_type = str integer_types = (int,) @@ -76,52 +86,59 @@ def pbr(dist, attr, value): not work well with distributions that do use a `Distribution` subclass. """ - if not value: - return - if isinstance(value, string_type): - path = os.path.abspath(value) - else: - path = os.path.abspath('setup.cfg') - if not os.path.exists(path): - raise errors.DistutilsFileError( - 'The setup.cfg file %s does not exist.' % path) - - # Converts the setup.cfg file to setup() arguments try: - attrs = util.cfg_to_args(path) - except Exception: - e = sys.exc_info()[1] - raise errors.DistutilsSetupError( - 'Error parsing %s: %s: %s' % (path, e.__class__.__name__, e)) - - # Repeat some of the Distribution initialization code with the newly - # provided attrs - if attrs: - # Skips 'options' and 'licence' support which are rarely used; may add - # back in later if demanded - for key, val in attrs.items(): - if hasattr(dist.metadata, 'set_' + key): - getattr(dist.metadata, 'set_' + key)(val) - elif hasattr(dist.metadata, key): - setattr(dist.metadata, key, val) - elif hasattr(dist, key): - setattr(dist, key, val) - else: - msg = 'Unknown distribution option: %s' % repr(key) - warnings.warn(msg) - - # Re-finalize the underlying Distribution - core.Distribution.finalize_options(dist) - - # This bit comes out of distribute/setuptools - if isinstance(dist.metadata.version, integer_types + (float,)): - # Some people apparently take "version number" too literally :) - dist.metadata.version = str(dist.metadata.version) - - # This bit of hackery is necessary so that the Distribution will ignore - # normally unsupport command options (namely pre-hooks and post-hooks). - # dist.command_options is normally a dict mapping command names to dicts of - # their options. Now it will be a defaultdict that returns IgnoreDicts for - # the each command's options so we can pass through the unsupported options - ignore = ['pre_hook.*', 'post_hook.*'] - dist.command_options = util.DefaultGetDict(lambda: util.IgnoreDict(ignore)) + _monkeypatch_distribution() + if not value: + return + if isinstance(value, string_type): + path = os.path.abspath(value) + else: + path = os.path.abspath('setup.cfg') + if not os.path.exists(path): + raise errors.DistutilsFileError( + 'The setup.cfg file %s does not exist.' % path) + + # Converts the setup.cfg file to setup() arguments + try: + attrs = util.cfg_to_args(path) + except Exception: + e = sys.exc_info()[1] + raise errors.DistutilsSetupError( + 'Error parsing %s: %s: %s' % (path, e.__class__.__name__, e)) + + # Repeat some of the Distribution initialization code with the newly + # provided attrs + if attrs: + # Skips 'options' and 'licence' support which are rarely used; may + # add back in later if demanded + for key, val in attrs.items(): + if hasattr(dist.metadata, 'set_' + key): + getattr(dist.metadata, 'set_' + key)(val) + elif hasattr(dist.metadata, key): + setattr(dist.metadata, key, val) + elif hasattr(dist, key): + setattr(dist, key, val) + else: + msg = 'Unknown distribution option: %s' % repr(key) + warnings.warn(msg) + + # Re-finalize the underlying Distribution + core.Distribution.finalize_options(dist) + + # This bit comes out of distribute/setuptools + if isinstance(dist.metadata.version, integer_types + (float,)): + # Some people apparently take "version number" too literally :) + dist.metadata.version = str(dist.metadata.version) + + # This bit of hackery is necessary so that the Distribution will ignore + # normally unsupport command options (namely pre-hooks and post-hooks). + # dist.command_options is normally a dict mapping command names to + # dicts of their options. Now it will be a defaultdict that returns + # IgnoreDicts for the each command's options so we can pass through the + # unsupported options + ignore = ['pre_hook.*', 'post_hook.*'] + dist.command_options = util.DefaultGetDict( + lambda: util.IgnoreDict(ignore) + ) + finally: + _restore_distribution_monkeypatch() diff --git a/pbr/testr_command.py b/pbr/testr_command.py index bf36b27..34b02ed 100644 --- a/pbr/testr_command.py +++ b/pbr/testr_command.py @@ -125,7 +125,7 @@ class Testr(cmd.Command): # Use this as coverage package name if self.coverage_package_name: package = self.coverage_package_name - options = "--source %s --parallel-mode" % self.coverage_package_name + options = "--source %s --parallel-mode" % package os.environ['PYTHON'] = ("coverage run %s" % options) logger.debug("os.environ['PYTHON'] = %r", os.environ['PYTHON']) diff --git a/pbr/tests/base.py b/pbr/tests/base.py index 6c31bc9..ce20de1 100644 --- a/pbr/tests/base.py +++ b/pbr/tests/base.py @@ -116,17 +116,24 @@ class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase): k.startswith('pbr_testpackage.')): del sys.modules[k] - def run_setup(self, *args): - return self._run_cmd(sys.executable, ('setup.py',) + args) + def run_setup(self, *args, **kwargs): + return self._run_cmd(sys.executable, ('setup.py',) + args, **kwargs) - def _run_cmd(self, cmd, args=[]): + def _run_cmd(self, cmd, args=[], allow_fail=True, cwd=None): """Run a command in the root of the test working copy. Runs a command, with the given argument list, in the root of the test working copy--returns the stdout and stderr streams and the exit code from the subprocess. + + :param cwd: If falsy run within the test package dir, otherwise run + within the named path. """ - return _run_cmd([cmd] + list(args), cwd=self.package_dir) + cwd = cwd or self.package_dir + result = _run_cmd([cmd] + list(args), cwd=cwd) + if result[2] and not allow_fail: + raise Exception("Command failed retcode=%s" % result[2]) + return result def _run_cmd(args, cwd): diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py index abcc68d..46dd0d5 100644 --- a/pbr/tests/test_packaging.py +++ b/pbr/tests/test_packaging.py @@ -78,8 +78,7 @@ class TestPackagingInGitRepoWithCommit(base.BaseTestCase): super(TestPackagingInGitRepoWithCommit, self).setUp() repo = self.useFixture(TestRepo(self.package_dir)) repo.commit() - self.run_setup('sdist') - return + self.run_setup('sdist', allow_fail=False) def test_authors(self): # One commit, something should be in the authors list @@ -99,8 +98,7 @@ class TestPackagingInGitRepoWithoutCommit(base.BaseTestCase): def setUp(self): super(TestPackagingInGitRepoWithoutCommit, self).setUp() self.useFixture(TestRepo(self.package_dir)) - self.run_setup('sdist') - return + self.run_setup('sdist', allow_fail=False) def test_authors(self): # No commits, no authors in list @@ -119,8 +117,7 @@ class TestPackagingInPlainDirectory(base.BaseTestCase): def setUp(self): super(TestPackagingInPlainDirectory, self).setUp() - self.run_setup('sdist') - return + self.run_setup('sdist', allow_fail=False) def test_authors(self): # Not a git repo, no AUTHORS file created @@ -36,6 +36,8 @@ warnerrors = True [entry_points] distutils.setup_keywords = pbr = pbr.core:pbr +distutils.commands = + testr = pbr.testr_command:Testr [build_sphinx] all_files = 1 diff --git a/tools/integration.sh b/tools/integration.sh index b6021f3..8c2db5e 100644 --- a/tools/integration.sh +++ b/tools/integration.sh @@ -43,7 +43,14 @@ BASE=${BASE:-/opt/stack} REPODIR=${REPODIR:-$BASE/new} # TODO: Figure out how to get this on to the box properly -sudo apt-get install -y --force-yes libxml2-dev libxslt-dev libmysqlclient-dev libpq-dev libnspr4-dev pkg-config libsqlite3-dev libzmq-dev libffi-dev libldap2-dev libsasl2-dev +sudo apt-get install -y --force-yes libxml2-dev libxslt-dev libmysqlclient-dev libpq-dev libnspr4-dev pkg-config libsqlite3-dev libzmq-dev libffi-dev libldap2-dev libsasl2-dev ccache + +# FOR numpy / pyyaml +sudo apt-get build-dep -y --force-yes python-numpy +sudo apt-get build-dep -y --force-yes python-yaml + +# And use ccache explitly +export PATH=/usr/lib/ccache:$PATH tmpdir=$(mktemp -d) @@ -93,7 +100,7 @@ if [ ! -d /etc/apache2/sites-enabled/ ] ; then exit 1 fi -sudo rm /etc/apache2/sites-enabled/* +sudo rm -f /etc/apache2/sites-enabled/* cat <<EOF > $tmpdir/pypi.conf <VirtualHost *:80> ServerAdmin webmaster@localhost @@ -101,8 +108,21 @@ cat <<EOF > $tmpdir/pypi.conf Options Indexes FollowSymLinks </VirtualHost> EOF -sudo mv $tmpdir/pypi.conf /etc/apache2/sites-available/pypi -sudo chown root:root /etc/apache2/sites-available/pypi + +# NOTE(dhellmann): This logic is copied from apache_site_config_for +# devstack/lib/apache with non-Ubuntu OSes left out because we don't +# run this integration test anywhere else for now. +apache_version=$(/usr/sbin/apache2ctl -v | awk '/Server version/ {print $3}' | cut -f2 -d/) +if [[ "$apache_version" =~ ^2\.2\. ]] +then + # Ubuntu 12.04 - Apache 2.2 + apache_conf=/etc/apache2/sites-available/pypi +else + # Ubuntu 14.04 - Apache 2.4 + apache_conf=/etc/apache2/sites-available/pypi.conf +fi +sudo mv $tmpdir/pypi.conf $apache_conf +sudo chown root:root $apache_conf sudo a2ensite pypi sudo service apache2 reload |