#92 bumpspec: fix --new flag when using rpmautospec
Merged by ngompa. Opened by decathorpe.
Unknown source main

Download 92.patch

This PR fixes the "--new" flag functionality when using rpmautospec:

  • refactor logic around rpmautospec detection to make sure we don't exit too soon (before Version is set) or too late (after changelog is mangled)
  • add set_release argument to SpecFile.newVersion method (set to False when rpmautospec is detected, True otherwise)
  • only change Release value of set_release is set to True

Some other small modernizations and lint fixes:

  • move toplevel statements into a main() function to fix scopes and shadowed names

The if __name__ == "__main__" check implies that this file was intended to be importable, but the sys.exit(1) statement on the last line obviously broke that. With no top-level statements except the if-name-is-main-check, this should be fixed now.

This also meant that opts was no longer a variable with global scope, so opts.datestamp and opts.legacy_datestamp needed to be passed as arguments to the SpecFile.addChangelogEntry method.

  • make sure there are no hidden "early exits"

All sys.exit(n) calls were replaced by either 1) integer return values of the main function, or by raised exceptions.


I tested this version in the following scenarios and verified that it does the expected thing :tm: :

  • rpmautospec without setting --new flag: does nothing
  • rpmautospec with --new flag: sets Version, but not Release, and does not add a changelog entry
  • non-rpmautospec without setting --new flag: increments Release and adds changelog entry
  • non-rpmautospec with --new flag: sets Version, resets Release to 1%{?dist}, and adds a changelog entry

Note that I have not tested this with older python versions. I have not used any "new" Python syntax or added any new python stdlib calls, so this should be :sparkle: fine :sparkle:

Fixes https://pagure.io/rpmdevtools/issue/91

:thumbsup:

Pull-Request has been merged by ngompa

Metadata