Variable amounts of whitespace
wenkokke opened this issue · 1 comments
Code formatters may sometimes insert whitespace, e.g., to align columns in a configuration file.
Would it be possible to allow, e.g., \s+
in the bumpver configuration files, to match variable amounts of whitespace, similar to the addition of ^
and $
?
It might be possible, I'm not sure. The thing about the pattern syntax is, that it is used both for search and also for the replacement string. For ^
and $
this worked well, as we can generate the replacement string by just stripping them off.
The current logic works completely independently of the content to which the replacement is applied.
# remove regex chars
result = result.replace(r"^", r"")
result = result.replace(r"$", r"")
# unescape braces
result = result.replace(r"\[", r"[")
result = result.replace(r"\]", r"]")
for part, part_value in used_parts:
result = result.replace(part, part_value)
So, in order to implement this, the logic would need to change so that
- every replacement is generated specifically for the line which it is replacing.
- the pattern syntax must be implemented in a way that allows us to capture dynamic parts of the content, for example by wrapping the
\s+
in a capture group syntax(\s+)
and then extracting it from a regex match object.
It would be a good idea to also validate every generated replacement, by making sure the search pattern matches it. Otherwise I'd be worried that we replace a version string with something that won't be matched in a later update.
Overall this does not seem to be worth it for me to put in the effort, but I'll be happy to give feedback on and accept a PR.