Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable amounts of whitespace #183

Open
wenkokke opened this issue Aug 17, 2022 · 1 comment
Open

Variable amounts of whitespace #183

wenkokke opened this issue Aug 17, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@wenkokke
Copy link

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 $?

@mbarkhau
Copy link
Owner

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.

src/bumpver/v2version.py#L436

    # 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

  1. every replacement is generated specifically for the line which it is replacing.
  2. 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.

@mbarkhau mbarkhau added the enhancement New feature or request label Aug 17, 2022
@mbarkhau mbarkhau changed the title [Feature request]: Variable amounts of whitespace Variable amounts of whitespace Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants