diff --git a/pbr/hooks/commands.py b/pbr/hooks/commands.py index fd757e4c..d9b56b5d 100644 --- a/pbr/hooks/commands.py +++ b/pbr/hooks/commands.py @@ -43,6 +43,7 @@ class CommandsConfig(base.BaseConfig): self.add_command('pbr.packaging.LocalInstallScripts') self.add_command('pbr.packaging.LocalDevelop') self.add_command('pbr.packaging.LocalRPMVersion') + self.add_command('pbr.packaging.LocalDebVersion') 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 fd9ffbef..7ffd6ddf 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -225,6 +225,25 @@ class LocalRPMVersion(setuptools.Command): pass +class LocalDebVersion(setuptools.Command): + __doc__ = """Output the deb *compatible* version string of this package""" + description = __doc__ + + user_options = [] + command_name = "deb_version" + + def run(self): + log.info("[pbr] Extracting deb version") + name = self.distribution.get_name() + print(version.VersionInfo(name).semantic_version().debian_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 7f78adc6..51e27116 100644 --- a/pbr/tests/test_commands.py +++ b/pbr/tests/test_commands.py @@ -57,6 +57,14 @@ class TestCommands(base.BaseTestCase): self.assertIn('Running custom build_py command.', stdout) self.assertEqual(0, return_code) + def test_custom_deb_version_py_command(self): + """Test custom deb_version command.""" + stdout, stderr, return_code = self.run_setup('deb_version') + self.addDetail('stdout', content.text_content(stdout)) + self.addDetail('stderr', content.text_content(stderr)) + self.assertIn('Extracting deb version', stdout) + self.assertEqual(0, return_code) + def test_custom_rpm_version_py_command(self): """Test custom rpm_version command.""" stdout, stderr, return_code = self.run_setup('rpm_version')