peritus / bumpversion

Version-bump your software with a single command
https://pypi.python.org/pypi/bumpversion
MIT License
1.5k stars 147 forks source link

UnicodeEncodeError when there is an existing setup.cfg file with non-ascii characters #105

Closed e3krisztian closed 9 years ago

e3krisztian commented 9 years ago

It was my first use (attempt):

$ pip install --user bumpversion
Downloading/unpacking bumpversion
  Downloading bumpversion-0.5.3-py2.py3-none-any.whl
Installing collected packages: bumpversion
Successfully installed bumpversion
Cleaning up...
$ bumpversion -h
Traceback (most recent call last):
  File "/home/kr/.local/bin/bumpversion", line 11, in <module>
    sys.exit(main())
  File "/home/kr/.local/lib/python2.7/site-packages/bumpversion/__init__.py", line 695, in main
    config.write(log_config)
  File "/usr/lib/python2.7/ConfigParser.py", line 412, in write
    key = " = ".join((key, str(value).replace('\n', '\n\t')))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 7: ordinal not in range(128)

Checking what can be the problem in bumpversion/__init__.py, around line 695 the candidate problem source is that I have run it in a project directory with an existing setup.cfg:

$ file setup.cfg 
setup.cfg: C++ source, UTF-8 Unicode text

and it is indeed a utf-8 file, with non-ascii characters (my accented name) in it. It is a project that was originally packaged with pbr - had declarative packaging definition.


Temporary workaround: I have created a .bumpversion.cfg file and now it shows the help.

peritus commented 9 years ago

Good find! Can you try updating configparser (pip install configparser, the version that ships with python 2.7 is too old to handle utf-8 properly here, i think) ?

e3krisztian commented 9 years ago

After installing a configparser it works! (I have renamed .bumpversion.cfg for the check)

peritus commented 9 years ago

Then we're probably out of luck fixing this bug in bumpversion. Python 3 includes the updated version of configparser (the one that handles utf-8 correctly), so it will fade away with more people moving towards Python 3.

Have fun with bumpversion!

e3krisztian commented 9 years ago

This was quick!

I'll surely remember this configparser vs ConfigParser issue. It was just shocking at first that it does not even print the help on a recent-ish ubuntu for me (14.04.2 LTS). Fortunately it is not a blocker.

I will use bumpversion as I am quite sure it is the currently best solution for inserting versions into projects! Thanks!

coredumperror commented 9 years ago

Isn't it possible to add configparser as a dependency for bumpversion?

peritus commented 9 years ago

@coredumperror Yes, that would certainly be possible. However, currently bumpversion doesn't have a single dependency and I'd like to treat an updated version of configparser as optional.

The best approach here is probably to catch UnicodeDecodeErrors when using the old ConfigParser and print an error message along the lines of "Can't read the config file because you're using non-ascii characters and didn't update configparser. Use pip install -U configparser to fix" ?