peterjc / flake8-black

flake8 plugin to run black for checking Python coding style
MIT License
165 stars 10 forks source link

Release 0.2.0 breaks compatibility with Poetry package manager #23

Closed mazimi closed 4 years ago

mazimi commented 4 years ago

This issue is related to https://github.com/peterjc/flake8-black/commit/c47339228727c9a15e7b21e7c94d5fb44b29fa1f

When adding the flake8-black package either via poetry add flake8-black or by adding it to pyproject.toml, you get this error:

[SolverProblemError]
Because no versions of flake8-black match >0.2.0,<0.3.0
 and flake8-black (0.2.0) depends on black (*), flake8-black (>=0.2.0,<0.3.0) requires black (*).
So, because no versions of black match *
 and <project-name> depends on flake8-black (^0.2.0), version solving failed.

If I pin to the prior version, poetry add flake8-black=0.1.2 I get the correct result:

% pip freeze
...
black==19.10b0
...

The recent change to allowing any release version of black prevents any pre-release version from being installed due to https://github.com/psf/black/issues/517 that's been previously mentioned. IMO the correct behavior would be to specify the minimum compliant black pre-release version and allow the latest version to be installed by the package manager and be compliant with PEP 440. If there's a preference to keep the current behavior to support Pipenv users until https://github.com/pypa/pipenv/issues/3928 is resolved - feel free to close this issue and it would be helpful to note that the current workaround for Poetry users is to add the following line in your pyproject.toml:

[tool.poetry.dev-dependencies]
...
black = { version = "*", allow-prereleases = true }
...

This is not ideal since sub-dependencies shouldn't need to be specified in pyproject.toml.

peterjc commented 4 years ago

Is is unfortunate that right now pipenv doesn't like flake8-black saying "black >= 19.3b0" (my issue #18/#21) while poetry doesn't like it saying just "black" (any version).

I agree, it would be nice if black dropped their pre-release tag because it is just causing trouble with many different packaging environments. This corner of PEP440 seems under tested, so something good is coming from this at least.

Do you know if there an equivalent poetry bug for it failing to pick the latest version of black in this circumstance? i.e. Their equivalent of https://github.com/pypa/pipenv/issues/3928 - the closest I found was https://github.com/python-poetry/poetry/issues/2413 which is a bit different as it isn't via a dependency.

In any case, I would strongly recommend your project explicitly pin the version of black yourself. With a large codebase even the recent versions of black introduce changes. As a poetry user, is that an acceptable workaround? If so, I can document that.

peterjc commented 4 years ago

Or, another workaround is just pin "flake8-black == 0.1.2" - and we can both hope the next Black release makes life easier ;)

mazimi commented 4 years ago

I believe Poetry is compliant with PEP 440 and there is no bug to report with Poetry in this case - it's Pipenv that's not compliant.

It's not ideal to pin the version of black or flake8-black since it prevents updates. The best resolution for Poetry users is to explicitly allow pre-releases for only the black package by adding this to their pyproject.toml file:

[tool.poetry.dev-dependencies]
...
black = { version = "*", allow-prereleases = true }

This has the benefit of getting the latest flake8-black and black releases. As I mentioned, it's not ideal to specify sub-dependencies in pyproject.toml but it's the least painful solution that satisfies most users.

Thanks again for your work on this plugin, it simplifies workflow and CI. 🙏

peterjc commented 4 years ago

I would expect poetry to take the latest version of black in this context, but I think we'd both agree PEP440 could be much clearer on this.

While I suggest pinning black for stability, if you keep on top of it having the latest black is also viable - I try to do that with my own projects.

I think I need to add something to the flake8-black documentation, although I would rather point at some black documentation for all the workarounds needed because they still only have pre-releases on PyPI.

peterjc commented 4 years ago

I've put something in the README file, please don't hesitate to suggest any improvements (either here or on a new issue), but marking this as closed now. Thank you.