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

bumpversion and setuptools have differing interpolation behavior #181

Open
SethMMorton opened this issue May 18, 2018 · 2 comments
Open

Comments

@SethMMorton
Copy link

First, thanks for the great tool!

The interpolation behavior of config files by bumpversion and setuptools is not the same. bumpversion uses no interpolation (e.g. configparser.RawConfigParser), but setuptools uses the default interpolation of configparser.ConfigParser, which is "basic interpolation".

In general, this should not be an issue, but because bumpversion supports setting configuration in the setup.cfg file, options that might be interpolated by the parser would not cause an issue if they appear in the .bumpversion.cfg, but suddenly break the install/build process if they are moved to the setup.cfg.

For example, I had the following in my .bumpversion.cfg to automatically insert the date in my CHANGELOG along with the version.

[bumpversion:file:docs/source/changelog.rst]
search = XX-XX-XXXX v. X.X.X
replace = {now:%m-%d-%Y} v. {new_version}

When I moved this into my setup.cfg, bumpversion still works but the following happens when I try to run anything with setup.py.

Traceback (most recent call last):
 ...
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%m-%d-%Y} v. {new_version}'

The obvious solution of escaping the % so that they are not interpolated (e.g. {now:%%m-%%d-%%Y} causes setuptools to not fail, but then bumpversion inserts the literal string "%%m-%%d-%%Y" instead of formatting the date because the percent signs are not treated as needing escaping.

It turns out that other packages have run into this, like pytest: pytest-dev/pytest#3062. This distutils mailing thread also illustrates that the python devs are struggling with if this was a good design decision, but that's a whole other can of worms.

My proposal: When loading from setup.cfg, use configparser.ConfigParser, and when loading from .bumpversion.cfg, use configparser.RawConfigParser.

@espoelstra
Copy link

Does the str.format style of using '{named}{fields}'.format(named=one,fields=many) work instead of the % formatting?

@SethMMorton
Copy link
Author

SethMMorton commented Jan 9, 2019

@espoelstra It is already using str.format. Sending a datetime object through str.format requires the old-style % formatting within the format string - see https://stackoverflow.com/a/22842734/1399279.

So, in my above example, something like the following is what is happening in the code

new_string = '{now:%m-%d-%Y} v. {new_version}'.format(now=datetime.datetime.now(), new_version=new_version_string)

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