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

Incompatible with click 8.1.0 (ImportError: cannot import name '_unicodefun' from 'click') #2964

Labels
C: packaging Installation and packaging of Black T: bug Something isn't working

Comments

@stumpylog
Copy link

stumpylog commented Mar 28, 2022

Please use Black 22.3.0 (or newer) which was just released to fix this issue or pin Click to 8.0.0, 8.0.1, 8.0.2, 8.0.3, or 8.0.4.

~ @ichard26 at March 28 3:15 PM EST


So hey y'all, CI is broken eh?

Anyway, we are aware the most recent release of Click, 8.1.0, is breaking Black. This is because Black imports an internal module so Python 3.6 users with misconfigured LANG continues to work mostly properly. The code that patches click was supposed to be resilient to the module disappearing but the code was catching the wrong exception.

To unbreak your CI, please pin Click to 8.0.0, 8.0.1, 8.0.2, 8.0.3, or 8.0.4. We are working on a more longterm fix (probably fixing the patching code or getting rid of it entirely) and will try to get a release out soon.

~ @ichard26 at March 28 2:29 PM EST


Describe the bug

The Github Action step:

- name: Run black
  uses: psf/black@stable
  with:
     options: "--check --diff"
      version: "22.1.0"

fails with the following trackeback:

Traceback (most recent call last):
  File "/home/runner/work/_actions/psf/black/stable/.black-env/bin/black", line 8, in <module>
    sys.exit(patched_main())
  File "src/black/__init__.py", line 1423, in patched_main
  File "src/black/__init__.py", line 1[40](https://github.com/stumpylog/paperless-ngx/runs/5724998040?check_suite_focus=true#step:7:40)9, in patch_click
ImportError: cannot import name '_unicodefun' from 'click' (/home/runner/work/_actions/psf/black/stable/.black-env/lib/python3.8/site-packages/click/__init__.py)

To Reproduce

Run the black action on a Github runner, configured as above.

Expected behavior

The action should only fail if files are not formatted.

Environment

OS: runs-on: ubuntu-20.04
Version: 22.1.0
Action: @stable
Python version: 3.8 I believe

Additional context

@stumpylog stumpylog added the T: bug Something isn't working label Mar 28, 2022
@liranbg
Copy link

liranbg commented Mar 28, 2022

@stumpylog
try with locking click to click==8.0.1

@bradleyhurley
Copy link

I just came here to open a very similar issue.

The issue is caused by the release of click 8.1.0.

Install click==8.0.4

@woodruffw
Copy link
Member

+1: We have a failure in pip-audit here: pypa/pip-audit#249

(click is strictly a subdependency of ours, so pinning it isn't an ideal workaround.)

@ichard26
Copy link
Collaborator

ichard26 commented Mar 28, 2022

Oh wow, Click 8.1.0 drops support for Python 3.6. We will have to either drop 3.6 soon or pin Click up to 8.0.4. very wrong, see below

@ichard26 ichard26 added the C: packaging Installation and packaging of Black label Mar 28, 2022
@ichard26 ichard26 pinned this issue Mar 28, 2022
woodruffw added a commit to pypa/pip-audit that referenced this issue Mar 28, 2022
@scasagrande
Copy link

scasagrande commented Mar 28, 2022

For those that are running black via pre-commit, you can pin click to 8.0.4 via the following:

- repo: https://github.com/psf/black
  rev: 22.1.0
  hooks:
    - id: black
      additional_dependencies: ['click==8.0.4']

Update - new version is available

- repo: https://github.com/psf/black
  rev: 22.3.0
  hooks:
    - id: black

@JelleZijlstra JelleZijlstra changed the title Github Action Fails with ImportError from 'click' Incompatible with click 8.1.0 Mar 28, 2022
@JelleZijlstra
Copy link
Collaborator

We should probably pin to <8.1.0 for now. I can help get a release out later today to do that.

@davidism
Copy link

Why was black importing an internal module? I was not expecting this to be the change that caused issues. Sorry about that.

@woodruffw
Copy link
Member

woodruffw commented Mar 28, 2022

Why was black importing an internal module? I was not expecting this to be the change that caused issues. Sorry about that.

Looks like this is why:

def patch_click() -> None:
    """Make Click not crash on Python 3.6 with LANG=C.
    On certain misconfigured environments, Python 3 selects the ASCII encoding as the
    default which restricts paths that it can access during the lifetime of the
    application.  Click refuses to work in this scenario by raising a RuntimeError.
    In case of Black the likelihood that non-ASCII characters are going to be used in
    file paths is minimal since it's Python source code.  Moreover, this crash was
    spurious on Python 3.7 thanks to PEP 538 and PEP 540.
    """
    try:
        from click import core
        from click import _unicodefun
    except ModuleNotFoundError:
        return

    for module in (core, _unicodefun):
        if hasattr(module, "_verify_python3_env"):
            module._verify_python3_env = lambda: None  # type: ignore
        if hasattr(module, "_verify_python_env"):
            module._verify_python_env = lambda: None  # type: ignore

So funnily enough, this should still work, it's just catching the wrong exception.

woodruffw added a commit to pypa/pip-audit that referenced this issue Mar 28, 2022
)

* pip_audit/dependency_source: match candidate names against project

See: pypa/packaging#527.

Fixes #248.

* pip_audit/dependency_source: remove redundant `is_satisfied_by` test

* test: add tests for vexing sdist parses

* test: update comment

* CHANGELOG: record fixes

* setup: pin `click`

Works around psf/black#2964

* setup: add note about pinned click
@mjpieters
Copy link

The import doesn't raise ModuleNotFoundError, only a plain ImportError, because from click import _unicodefun is used.

The code would need to be changed to import click._unicodefun (and import click.core) or catch the correct exception.

@davidism
Copy link

Well good news at least, that whole patch isn't needed anymore, since Click itself is now at the same point of not raising locale encoding errors. 😄

mjpieters added a commit to aio-libs/yarl that referenced this issue Mar 28, 2022
Move to the stable release and pin click, as black used the wrong exception to
work around a click interaction causing issues. See psf/black#2964
@ProGamerGov
Copy link

This causing black to fail when run on Google Colab right now as well.

mjpieters added a commit to aio-libs/yarl that referenced this issue Mar 28, 2022
Move to the stable release and pin click, as black used the wrong exception to
work around a click interaction causing issues. See psf/black#2964
mjpieters added a commit to aio-libs/yarl that referenced this issue Mar 28, 2022
Move to the stable release and pin click, as black used the wrong exception to
work around a click interaction causing issues. See psf/black#2964
KangOl pushed a commit to odoo/upgrade-util that referenced this issue Oct 5, 2023
Before this commit
The black pre-commit step is broken due to an incompatibility
with a new version of one of its dependencies (click 8.1+).
See: psf/black#2964 (comment)

After this commit
The new version does not have this incompatibility.
This commit bumps the black version to 22.3.0.

Part of odoo/upgrade#3391

Signed-off-by: Christophe Simonis <[email protected]>
nachovizzo added a commit to botsandus/ament_black that referenced this issue Oct 11, 2023
The CI error was fixed in: psf/black#2964
Thus, we need black >22.3.0
nachovizzo added a commit to botsandus/ament_black that referenced this issue Oct 11, 2023
* Add missing test dependency

* pre-commit

* Add pre-commit workflow

* Add CLI test to make sure the package has been properly installed

* Remove ament hooks

* Add missing apt-python dependency

Not sure if it's necessary ...

* Fix CI pre-commit

The CI error was fixed in: psf/black#2964
Thus, we need black >22.3.0
LiamYY pushed a commit to LiamYY/serialization_lib that referenced this issue Oct 26, 2023
Refer to psf/black#2964, this error can be fixed by picking `click` to 8.0.4.

Signed-off-by: TatWai Chong <[email protected]>
Change-Id: If3970e0cd31f2190cacb741530cb38a31c943938
konradha pushed a commit to konradha/ae108-mirror that referenced this issue Nov 6, 2023
- fixes error in CI
- see psf/black#2964
neteler pushed a commit to nilason/grass that referenced this issue Nov 7, 2023
A new version of Click broke Black. The new version of Black fixes the issue.

See also psf/black#2964
ttrei added a commit to ttrei/dotfiles that referenced this issue Dec 17, 2023
ZachSmithus added a commit to ZachSmithus/asciinema that referenced this issue Jan 31, 2024
btbrunotome added a commit to btbrunotome/responses that referenced this issue Apr 22, 2024
* update black according to psf/black#2964
* new black rules do a change on existing files
zxhdaze pushed a commit to canonical/juju-backup-all that referenced this issue Apr 25, 2024
Pre-commit won't allow its yaml file in a separate commit, so the
upgrade to black 22.3.0 is included as well. This is to address
bug 2964 [0] where black fails locally with pre-commit.

[0] psf/black#2964
tianyizheng02 added a commit to pittcsc/PittAPI that referenced this issue May 23, 2024
Update black from 19.10b0 to 24.4.2. black had been broken due to an
ImportError (see psf/black#2964).
tianyizheng02 added a commit to pittcsc/PittAPI that referenced this issue Jun 3, 2024
* Update black

Update black from 19.10b0 to 24.4.2. black had been broken due to an
ImportError (see psf/black#2964).

* Add black to pre-commit

* Add black to GitHub Actions

* Add flake8 to pre-commit

* Update requirements.txt using Pipfile

Ran `pipenv requirements --exclude-markers > requirements.txt` to update
requirements.txt with correct dependencies and versions from Pipfile. I
did this primarily to update the black version (because the previous
version was broken with an ImportError), and I might as well update the
rest of the dependencies as well.

* Add flags to black for GitHub Actions

Add the --check and --diff flags to black within GitHub Actions
workflows so that the workflows fail if files need formatting. Without
these flags, black will "format" the files and exit without error, which
doesn't actually write to the files during workflows.

* Add flags to flake8 and black for pre-commit

Add flags to flake8 and black for pre-commit based on existing flags in
GitHub Actions workflows. This includes selecting for specific flake8
errors and adjusting the max line length. These existing configs are
extremely limited, so they should be broadened to more errors and/or a
more widely accepted max line length.

Also ran black on the entire codebase to satisfy the GitHub workflows.

* Fix typo in black option flag

* Fix formatting errors
bellisk added a commit to bellisk/ckanext-subscribe that referenced this issue Jun 20, 2024
Antiserumgq added a commit to Antiserumgq/asciinema that referenced this issue Aug 14, 2024
mabilton added a commit to mabilton/python-client that referenced this issue Aug 16, 2024
timothy-bartlett added a commit to timothy-bartlett/pip-audit that referenced this issue Aug 22, 2024
…249)

* pip_audit/dependency_source: match candidate names against project

See: pypa/packaging#527.

Fixes #248.

* pip_audit/dependency_source: remove redundant `is_satisfied_by` test

* test: add tests for vexing sdist parses

* test: update comment

* CHANGELOG: record fixes

* setup: pin `click`

Works around psf/black#2964

* setup: add note about pinned click
timothy-bartlett added a commit to timothy-bartlett/pip-audit that referenced this issue Aug 22, 2024
…249)

* pip_audit/dependency_source: match candidate names against project

See: pypa/packaging#527.

Fixes #248.

* pip_audit/dependency_source: remove redundant `is_satisfied_by` test

* test: add tests for vexing sdist parses

* test: update comment

* CHANGELOG: record fixes

* setup: pin `click`

Works around psf/black#2964

* setup: add note about pinned click
IsaiahASmith pushed a commit to IsaiahASmith/foundry-smb3 that referenced this issue Nov 9, 2024
francomattar added a commit to francomattar/Nmypy-pytest that referenced this issue Dec 13, 2024
This picks up the fix for psf/black#2964
nayanzin33sergey added a commit to nayanzin33sergey/Python-pytest-mypy that referenced this issue Dec 18, 2024
This picks up the fix for psf/black#2964
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment