Skip to content

Commit e0af0a5

Browse files
authored
RPM: Fix changelog --bump option (#13)
To compute the bumped release version of a Specfile, the rstrip method was used to remove the dist tag before computing the bump (We don't want to bump the dist tag, el9 to el10 for instance). However, the rstrip version remove a set of character in the totality of the string instead of only the suffix. The removesuffix method is more suitable. Further documentation : https://docs.python.org/3/library/stdtypes.html#str.rstrip
1 parent be79ab5 commit e0af0a5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/rift/RPM.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
from rift import RiftError
4848
from rift.Annex import Annex, is_binary
49+
import rift.utils
4950

5051
RPMLINT_CONFIG_V1 = 'rpmlint'
5152
RPMLINT_CONFIG_V2 = 'rpmlint.toml'
@@ -296,7 +297,9 @@ def update_evr(self):
296297
"""
297298
Update epoch:version-release
298299
"""
299-
self.evr = f"{self.epoch}{self.version}-{self.release.rstrip(self.dist)}"
300+
self.evr = "{}{}-{}".format(self.epoch,
301+
self.version,
302+
rift.utils.removesuffix(self.release, self.dist))
300303

301304
def _inc_release(self, release):
302305
dist = self.dist

lib/rift/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@ def setup_dl_opener(proxy, no_proxy, fake_user_agent=True):
7575
if fake_user_agent:
7676
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
7777
urllib.request.install_opener(opener)
78+
79+
def removesuffix(input_string, suffix):
80+
"""
81+
The removesuffix method was introduced in python 3.9,
82+
to preserve compatibility with older version, this is
83+
a reimplementation
84+
"""
85+
if suffix and input_string.endswith(suffix):
86+
return input_string[:-len(suffix)]
87+
return input_string
88+

0 commit comments

Comments
 (0)