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

Possible to have two re pattern for one line replacement? #190

Closed
unkcpz opened this issue Oct 10, 2022 · 4 comments
Closed

Possible to have two re pattern for one line replacement? #190

unkcpz opened this issue Oct 10, 2022 · 4 comments

Comments

@unkcpz
Copy link
Contributor

unkcpz commented Oct 10, 2022

The bumpver tool is really great but we now can not figure out how to use it for our new version replacement case.
We have a package dependency defined in setup.cfg that needs to update with every release

aiidalab-qe-workchain@https://github.com/aiidalab/aiidalab-qe/releases/download/v22.09.1/aiidalab_qe_workchain-22.9.1-py3-none-any.whl

We defined the pattern as:

[bumpver]
current_version = "v22.09.1"
version_pattern = "v0Y.0M.PATCH[PYTAGNUM]"
commit_message = "Bump version {old_version} -> {new_version}"
commit = True
tag = True
push = True

[bumpver:file_patterns]
setup.cfg =
    aiidalab-qe-workchain@https://github.com/aiidalab/aiidalab-qe/releases/download/{version}/aiidalab_qe_workchain-{pep440_version}-py3-none-any.whl

However, bumpver update --dry-run end up with the error:

WARNING - Invalid patterns for setup.cfg (aiidalab-qe-workchain@https://github.com/aiidalab/aiidalab-qe/releases/download/{version}/aiidalab_qe_workchain-{pep440_version}-py3-none-any.whl)
Traceback (most recent call last):
  File "/home/aiida/.local/bin/bumpver", line 8, in <module>
    sys.exit(cli())
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/aiida/.local/lib/python3.8/site-packages/bumpver/cli.py", line 580, in update
    _, cfg = config.init(project_path='.')
  File "/home/aiida/.local/lib/python3.8/site-packages/bumpver/config.py", line 399, in init
    cfg = parse(ctx, cfg_missing_ok)
  File "/home/aiida/.local/lib/python3.8/site-packages/bumpver/config.py", line 385, in parse
    return _parse_config(raw_cfg)
  File "/home/aiida/.local/lib/python3.8/site-packages/bumpver/config.py", line 305, in _parse_config
    file_patterns = _compile_file_patterns(raw_cfg, is_new_pattern)
  File "/home/aiida/.local/lib/python3.8/site-packages/bumpver/config.py", line 259, in _compile_file_patterns
    for path, patterns in _file_pattern_items:
  File "/home/aiida/.local/lib/python3.8/site-packages/bumpver/config.py", line 243, in _compile_v2_file_patterns
    v2patterns.compile_pattern(version_pattern, raw_pattern)
  File "/home/aiida/.local/lib/python3.8/site-packages/bumpver/utils.py", line 27, in wrapper
    cache[key] = func(*args)
  File "/home/aiida/.local/lib/python3.8/site-packages/bumpver/v2patterns.py", line 221, in compile_pattern
    regexp = _compile_pattern_re(normalized_pattern)
  File "/home/aiida/.local/lib/python3.8/site-packages/bumpver/v2patterns.py", line 214, in _compile_pattern_re
    return re.compile(pattern_str)
  File "/opt/conda/lib/python3.8/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/opt/conda/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/opt/conda/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/opt/conda/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/opt/conda/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/opt/conda/lib/python3.8/sre_parse.py", line 831, in _parse
    raise source.error(err.msg, len(name) + 1) from None
re.error: redefinition of group name 'month' as group 6; was group 2 at position 224

Is that already supported to have two matches in one line? If not how can I set the pattern for the replacement.
Thanks!

@unkcpz
Copy link
Contributor Author

unkcpz commented Oct 10, 2022

With some investigation, the pattern_str used for this case is:

'aiidalab\\-qe\\-workchain@https://github\\.com/aiidalab/aiidalab\\-qe/releases/download/v(?P<year_y>[0-9]{2})\\.(?P<month>1[0-2]|0[1-9])\\.(?P<patch>[0-9]+)(?:(?P<pytag>post|rc|a|b)(?P<num>[0-9]+))?/aiidalab_qe_workchain\\-0Y\\.(?P<month>1[0-2]|[1-9])\\.PATCH(?:PYTAGNUM)?\\-py3\\-none\\-any\\.whl'

I think only the group index needs to be increased to match the position when more than one pattern is used in one line.

@mbarkhau
Copy link
Owner

Nice catch, yes it should be possible to handle this somehow.

@mbarkhau
Copy link
Owner

Fixed with 2022.1019

@unkcpz
Copy link
Contributor Author

unkcpz commented Oct 16, 2022

@mbarkhau thanks a lot for the quick fix. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants