c4urself / bump2version

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

Bump2version fails with the new black code formatter #145

Closed aced125 closed 3 years ago

aced125 commented 4 years ago

Hi,

Bump2version does not work when the new black formatter is on.

It formats all single quotes ' as double quotes ", which in turn causes the formatter to do this:

# setup.py
    ...
    packages=find_packages(include=["sparsemax", "sparsemax.*"]),
    setup_requires=setup_requirements,
    test_suite="tests",
    tests_require=test_requirements,
    url="https://github.com/aced125/sparsemax",
    version="version='0.1.8'",
    zip_safe=False,
)

which in turn causes the egg files to become: (Travis logs below)

/home/travis/virtualenv/python3.8.0/lib/python3.8/site-packages/setuptools/dist.py:468: UserWarning: The version specified ("version='0.1.7'") is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.

  warnings.warn(

warning: no previously-included files matching '__pycache__' found under directory '*'

warning: no previously-included files matching '*.py[co]' found under directory '*'

warning: no files found matching '*.jpg' under directory 'docs'

warning: no files found matching '*.png' under directory 'docs'

warning: no files found matching '*.gif' under directory 'docs'

writing manifest file 'sparsemax.egg-info/SOURCES.txt'

running check

creating sparsemax-version-0.1.7-

creating sparsemax-version-0.1.7-/docs

creating sparsemax-version-0.1.7-/sparsemax

creating sparsemax-version-0.1.7-/sparsemax.egg-info

creating sparsemax-version-0.1.7-/tests

copying files to sparsemax-version-0.1.7-...

copying AUTHORS.rst -> sparsemax-version-0.1.7-

copying CONTRIBUTING.rst -> sparsemax-version-0.1.7-

which causes the Travis build to fail: HTTPError: 400 Client Error: 'version-0.1.7-' is an invalid value for Version. Error: Start and end with a letter or numeral containing only ASCII numeric and '.', '_' and '-'. See https://packaging.python.org/specifications/core-metadata for url: https://upload.pypi.org/legacy/.

The solution for now is to wrap setup.py code in

# fmt: off
setup.py code ...
# fmt: on

however we would prefer a fix from bump2version

florisla commented 4 years ago

It looks like your bump2version configuration does not match properly with the version string.

This causes an incorrect search/replace, like described in #127.

Can you share your bumpversion.cfg or setup.cfg file?

aced125 commented 4 years ago
# setup.cfg
[bumpversion]
current_version = 0.1.0
commit = True
tag = True

[bumpversion:file:setup.py]
search = version='{current_version}'
replace = version='{new_version}'

[bumpversion:file:protoattend/__init__.py]
search = __version__ = '{current_version}'
replace = __version__ = '{new_version}'

[bdist_wheel]
universal = 1

[flake8]
exclude = docs

[aliases]
test = pytest

[tool:pytest]
collect_ignore = ['setup.py']
ekohl commented 4 years ago

Am I reading it correct that black formats it using " but you have setup.cfg configured to use '? If so, then setup.cfg should be changed to use ".

aaronsmith1234 commented 4 years ago

I am having this same issue. Not that its unsolveable, but it does make the use of autoformatters a bit more involved.

aaronsmith1234 commented 4 years ago

Hi all, Using the proposed solution and the setup.cfg below, this issue goes away for major and minor releases, but it still happens for micro releases. Any ideas?

[bumpversion]
current_version = 0.1.0
commit = False
tag = True

[bumpversion:file:setup.py]
search = version="{current_version}"
replace = version="{new_version}"

[bumpversion:file:enterpylink/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

init.py has: __version__ = "0.1.0" setup.py has: version="0.1.0",

after running "bump2version minor" (major performs similarly), the results are as expected: init.py has: __version__ = "0.2.0" setup.py has: version="0.2.0",

However, if I run "bump2version micro", the below is what I see: init.py has: __version__ = "__version__ = "0.1.0"" setup.py has: version="version="0.1.0"",

s-weigand commented 4 years ago

@aaronsmith1234 I didn't know micro was even a valid value for part. Does the same happen if you use bump2version patch?

aaronsmith1234 commented 3 years ago

@s-weigand yes, patch works fine. Don't know where I got micro from, will use patch going forward!

florisla commented 3 years ago

Seems like this is all working as it should. #127 will prevent syntax errors like the original poster encountered.