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:
This PR fixes the "--new" flag functionality when using rpmautospec:
set_releaseargument to SpecFile.newVersion method (set toFalsewhen rpmautospec is detected,Trueotherwise)Releasevalue ofset_releaseis set to TrueSome other small modernizations and lint fixes:
main()function to fix scopes and shadowed namesThe
if __name__ == "__main__"check implies that this file was intended to be importable, but thesys.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
optswas no longer a variable with global scope, soopts.datestampandopts.legacy_datestampneeded to be passed as arguments to theSpecFile.addChangelogEntrymethod.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: :
--newflag: does nothing--newflag: sets Version, but not Release, and does not add a changelog entry--newflag: increments Release and adds changelog entry--newflag: sets Version, resets Release to1%{?dist}, and adds a changelog entryNote 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: