STYLE make black local hook run twice as fast
State: closed

- [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.

Since https://ichard26.github.io/blog/2022/05/compiling-black-with-mypyc-part-1/ , `black` runs twice as fast when the wheels are installed, compared with when it's built from source in the pre-commit hook

---

EDIT: CI timings show 53.84s vs 131.85s, so this is more than a 2x improvement

Labels:
name: Code Style
description: Code style, linting, code_checks

Comments:
Just checking: this doesn’t assume anything about my dev encironment?
> Just checking: this doesn’t assume anything about my dev encironment?

that's right!
This could maybe also be implemented by adding `black==22.10.0` to the `additional_dependencies` of the nonlocal `black` hook, so precommit would also install the mypyced module...
> This could maybe also be implemented by adding `black==22.10.0` to the `additional_dependencies` of the nonlocal `black` hook, so precommit would also install the mypyced module...

that doesn't work unfortunately, I get
```
[INFO] Installing environment for https://github.com/python/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/marcogorelli/.cache/pre-commit/repom_n0drrc/py_env-python3.8/bin/python', '-mpip', 'install', '.', 'black==22.10.0')
return code: 1
expected return code: 0
stdout:
    Processing /home/marcogorelli/.cache/pre-commit/repom_n0drrc
      Installing build dependencies: started
      Installing build dependencies: finished with status 'done'
      Getting requirements to build wheel: started
      Getting requirements to build wheel: finished with status 'done'
      Preparing metadata (pyproject.toml): started
      Preparing metadata (pyproject.toml): finished with status 'done'
    
    The conflict is caused by:
        The user requested black 0.1.dev1+g27d2014 (from /home/marcogorelli/.cache/pre-commit/repom_n0drrc)
        The user requested black==22.10.0
    
    To fix this you could try to:
    1. loosen the range of package versions you've specified
    2. remove package versions to allow pip attempt to solve the dependency conflict
    
    
stderr:
    ERROR: Cannot install black 0.1.dev1+g27d2014 (from /home/marcogorelli/.cache/pre-commit/repom_n0drrc) and black==22.10.0 because these package versions have conflicting dependencies.
    ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
    
Check the log at /home/marcogorelli/.cache/pre-commit/pre-commit.log
```
@MarcoGorelli Ah, I guess black uses setuptools_scm or something so non-tagged versions are always dev+stuff (which makes sense). Thanks for giving it a shot!
Thanks @MarcoGorelli