dnanhkhoa / nb_black

A simple extension for Jupyter Notebook and Jupyter Lab to beautify Python code automatically using black.
MIT License
367 stars 41 forks source link

Root cause failure using `conda env export` #32

Open benslack19 opened 3 years ago

benslack19 commented 3 years ago

This was discovered while doing conda env export. It seems to fail when nb_black is installed as described in this string but a solution was discovered. Is it possible you can do this simple fix in the next update?

Manually editing the dependencies for nb_black from

Requires-Dist: yapf (>='0.28') ; python_version < "3.6" Requires-Dist: black (>='19.3') ; python_version >= "3.6"

to

Requires-Dist: yapf (>=0.28) ; python_version < "3.6" Requires-Dist: black (>=19.3) ; python_version >= "3.6"

in /Users/[USERNAME]/opt/anaconda3/envs/[ENVNAME]/lib/python3.6/site-packages/nb_black-1.0.7.dist-info/ resolves the issue as a work-around.

The relevant text was found in the METADATA file in this folder.

adriantre commented 3 years ago

Poetry also gives this warning:

Resolving dependencies... (31.2s)<debug>PackageInfo:</debug> Invalid constraint (yapf>='0.28' ; python_version < "3.6") found in nb-black-1.0.7 dependencies, skipping
<debug>PackageInfo:</debug> Invalid constraint (black>='19.3' ; python_version >= "3.6") found in nb-black-1.0.7 dependencies, skipping
john-sandall commented 2 years ago

This is fixed on master, so using one of the following will resolve the Poetry warning for you.

# Poetry CLI
poetry add 'git+https://github.com/dnanhkhoa/nb_black.git@be0c810503867abc4a5e9d05ba75a16fce57dfee'

# Poetry pyproject.toml
nb-black = {git = "https://github.com/dnanhkhoa/nb_black.git", rev = "be0c810503867abc4a5e9d05ba75a16fce57dfee"}

# pip
pip install 'git+https://github.com/dnanhkhoa/nb_black.git@be0c810503867abc4a5e9d05ba75a16fce57dfee'

Context

This is happening because the PyPI released version of nb-black is using single quotes in the dependency specification in install_requires which is technically invalid but allowed by pip, whilst Poetry sticks strictly to the PEP 508 spec here: https://www.python.org/dev/peps/pep-0508/#complete-grammar

This is a very similar issue to this: https://github.com/Python-Markdown/markdown/pull/1197 (also discussed here https://github.com/python-poetry/poetry/issues/4777).

This was fixed in the nb-black master branch a while back. It would be good to see a new nb-black release to PyPI soon with this fix!