c4urself / bump2version

Version-bump your software with a single command
https://pypi.python.org/pypi/bump2version
MIT License
1.06k stars 133 forks source link

Issue with Complicated Regex #237

Closed coppolat1 closed 2 years ago

coppolat1 commented 2 years ago

I've come up with a regex to parse out semantic version information from C pre-processor style version definitions. An example of what I'm trying to parse:

/* multiline 
 * Instructions on when to bump Major
 */
#define LIBNAME_VERSION_MAJOR        (2U)

/* Instructions on when to bump minor */
#define LIBNAME_VERSION_MINOR        (11U)

/* Instructions on when to bump patch */
#define LIBNAME_VERSION_PATCH        (0U)

The is the regex. Here's a link to the regex101's builder if you want to try to decode it:

\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<major>\d+)[U]?\)\n\n\/\*[\s\S]*?\*\/*\n(?:\#define)\s.[A-Z_]*\s*\((?P<minor>\d+)[U]?\)\n\n\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<patch>\d+)[U]?\)

TL;DR: This Regex works in Python (see my *.py file) but b2v can't 'parse my current version'

I wrote a python script that uses this regex and successfully finds each of the version numbers in my above example. When I enter this regex into my bumpversion.cfg and run, it sees it as a valid regex, but is not able to find the current version.

See attached .zip that includes aforementioned python script, b2v config, and sample file.

b2v output:

❯ bump2version --dry-run --verbose --new-version 2.12.0 .\sample.txt
Reading config file .bumpversion.cfg:
[bumpversion]
parse = '\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<major>\d+)[U]?\)\n\n\/\*[\s\S]*?\*\/*\n(?:\#define)
\s.[A-Z_]*\s*\((?P<minor>\d+)[U]?\)\n\n\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<patch>\d+)[U]?\)'
current_version = 2.11.0

Evaluating 'parse' option: ''\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<major>\d+)[U]?\)\n\n\/\*[\s\S]*
?\*\/*\n(?:\#define)\s.[A-Z_]*\s*\((?P<minor>\d+)[U]?\)\n\n\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<p
atch>\d+)[U]?\)'' does not parse current version '2.11.0'
Dry run active, won't touch any files.
Evaluating 'parse' option: ''\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<major>\d+)[U]?\)\n\n\/\*[\s\S]*
?\*\/*\n(?:\#define)\s.[A-Z_]*\s*\((?P<minor>\d+)[U]?\)\n\n\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<p
atch>\d+)[U]?\)'' does not parse current version '2.12.0'
New version will be '2.12.0
[regex-issue.zip](https://github.com/c4urself/bump2version/files/7444075/regex-issue.zip)
'
Asserting files  contain the version string...
parse='\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<major>\d+)[U]?\)\n\n\/\*[\s\S]*?\*\/*\n(?:\#define)\s
.[A-Z_]*\s*\((?P<minor>\d+)[U]?\)\n\n\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<patch>\d+)[U]?\)'
current_version=2.11.0
new_version=2.12.0
Would write to config file .bumpversion.cfg:
[bumpversion]
parse = '\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<major>\d+)[U]?\)\n\n\/\*[\s\S]*?\*\/*\n(?:\#define)
\s.[A-Z_]*\s*\((?P<minor>\d+)[U]?\)\n\n\/\*[\s\S]*?\*\/\n(?:\#define)\s.[A-Z_]*\s*\((?P<patch>\d+)[U]?\)'
current_version = 2.12.0

Maybe someone can point me in the right direction? regex-issue.zip