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
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user