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 #21

Closed
SethMMorton opened this issue Jun 20, 2018 · 1 comment
Closed

Comments

@SethMMorton
Copy link
Contributor

(Migrating from peritus/bumpversion#181)

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.

@ekohl
Copy link
Collaborator

ekohl commented Aug 1, 2018

I think your proposal makes sense. Could you come up with a patch?

SethMMorton added a commit to SethMMorton/bump2version that referenced this issue Aug 20, 2018
Setuptools uses the default ConfigParser object when reading
setup.cfg which does interpolation. To be consistent with that format
bumpversion must do the same.

This will close issue c4urself#21.
SethMMorton added a commit to SethMMorton/bump2version that referenced this issue Aug 30, 2018
Setuptools uses the default ConfigParser object when reading
setup.cfg which does interpolation. To be consistent with that format
bumpversion must do the same.

This will close issue c4urself#21.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants