diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2015-06-26 12:07:39 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2015-07-02 04:52:14 +0000 |
commit | 826380603382e4aa2d1eb57649da91dd3ba4e0a5 (patch) | |
tree | 6bf8f8a6a38b11e66571f87123ac377310186f5d | |
parent | 5039c9a3f81f5a5ee3fc92c37bebc1c7573a3c74 (diff) | |
download | pbr-826380603382e4aa2d1eb57649da91dd3ba4e0a5.tar.gz |
Expose a 'rpm_version' extra command
Intended usage, getting a rpm *compatible* version number from pbr
from a pbr using python package. Typically this will then get
put into a rpm spec file (what is used to build an rpm) and used to
build an rpm using `rpmbuild` (the thing used to translate rpm spec
files into rpms).
For example: this allows [1][2] (which I am the primary maintainer of
and godaddy, cray, and y! are users of) to get out of the whacky
and/or flakey rpm version number calculation/conversion process (which
previously just worked around by saying only use tags).
[1] https://github.com/stackforge/anvil
[2] https://anvil.readthedocs.org/en/latest/topics/summary.html
Change-Id: I26cd1d6e8aef69d52e8a4f36bd264c690e712ba3
-rw-r--r-- | pbr/hooks/commands.py | 1 | ||||
-rw-r--r-- | pbr/packaging.py | 20 | ||||
-rw-r--r-- | pbr/tests/test_commands.py | 8 |
3 files changed, 29 insertions, 0 deletions
diff --git a/pbr/hooks/commands.py b/pbr/hooks/commands.py index 8e651e6..6de1257 100644 --- a/pbr/hooks/commands.py +++ b/pbr/hooks/commands.py @@ -42,6 +42,7 @@ class CommandsConfig(base.BaseConfig): self.add_command('pbr.packaging.LocalSDist') self.add_command('pbr.packaging.LocalInstallScripts') self.add_command('pbr.packaging.LocalDevelop') + self.add_command('pbr.packaging.LocalRPMVersion') if os.name != 'nt': easy_install.get_script_args = packaging.override_get_script_args diff --git a/pbr/packaging.py b/pbr/packaging.py index ebdfb09..3ab930f 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -28,6 +28,7 @@ import re import sys import pkg_resources +import setuptools from setuptools.command import develop from setuptools.command import easy_install from setuptools.command import egg_info @@ -187,6 +188,25 @@ class TestrTest(testr_command.Testr): testr_command.Testr.run(self) +class LocalRPMVersion(setuptools.Command): + __doc__ = """Output the rpm *compatible* version string of this package""" + description = __doc__ + + user_options = [] + command_name = "rpm_version" + + def run(self): + log.info("[pbr] Extracting rpm version") + name = self.distribution.get_name() + print(version.VersionInfo(name).semantic_version().rpm_string()) + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def have_testr(): return testr_command.have_testr diff --git a/pbr/tests/test_commands.py b/pbr/tests/test_commands.py index c73a9f3..74f50df 100644 --- a/pbr/tests/test_commands.py +++ b/pbr/tests/test_commands.py @@ -56,3 +56,11 @@ class TestCommands(base.BaseTestCase): self.addDetail('stderr', content.text_content(stderr)) self.assertIn('Running custom build_py command.', stdout) self.assertEqual(return_code, 0) + + def test_custom_rpm_version_py_command(self): + """Test custom rpm_version command.""" + stdout, stderr, return_code = self.run_setup('rpm_version') + self.addDetail('stdout', content.text_content(stdout)) + self.addDetail('stderr', content.text_content(stderr)) + self.assertIn('Extracting rpm version', stdout) + self.assertEqual(return_code, 0) |