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

Bump2version fails with the new black code formatter #145

Closed
aced125 opened this issue May 25, 2020 · 8 comments
Closed

Bump2version fails with the new black code formatter #145

aced125 opened this issue May 25, 2020 · 8 comments
Labels

Comments

@aced125
Copy link

aced125 commented May 25, 2020

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
Copy link
Collaborator

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
Copy link
Author

aced125 commented May 28, 2020

# 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
Copy link
Collaborator

ekohl commented May 28, 2020

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
Copy link

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

@aaronsmith1234
Copy link

aaronsmith1234 commented Aug 24, 2020

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
Copy link

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

@aaronsmith1234
Copy link

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

@florisla
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants