question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pre-commit fails when setting up the black environment.

See original GitHub issue

Describe the bug

pre-commit fails when setting up the black environment.

To Reproduce

When using pre-commit with a version of black tagged later than 18.9b0 (including stable or master, the initial setup of the black environment fails with the following output.

[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: Command: ('/home/rae/.cache/pre-commit/reporrf_4ype/py_env-python3.7/bin/python3.7', '/home/rae/.cache/pre-commit/reporrf_4ype/py_env-python3.7/bin/pip', 'install', '.')
Return code: 1
Expected return code: 0
Output:
    Processing /home/rae/.cache/pre-commit/reporrf_4ype
      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 wheel metadata: started
        Preparing wheel metadata: finished with status 'error'
   
Errors:
        ERROR: Command errored out with exit status 1:
         command: /home/rae/.cache/pre-commit/reporrf_4ype/py_env-python3.7/bin/python3.7 /home/rae/.cache/pre-commit/reporrf_4ype/py_env-python3.7/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmp7yzty2sc
             cwd: /tmp/pip-req-build-1ksmcb94
        Complete output (36 lines):
        Traceback (most recent call last):
          File "/home/rae/.cache/pre-commit/reporrf_4ype/py_env-python3.7/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py", line 257, in <module>
            main()
          File "/home/rae/.cache/pre-commit/reporrf_4ype/py_env-python3.7/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py", line 240, in main
            json_out['return_val'] = hook(**hook_input['kwargs'])
          File "/home/rae/.cache/pre-commit/reporrf_4ype/py_env-python3.7/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py", line 110, in prepare_metadata_for_build_wheel
            return hook(metadata_directory, config_settings)
          File "/tmp/pip-build-env-2tuvz0xl/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 156, in prepare_metadata_for_build_wheel
            self.run_setup()
          File "/tmp/pip-build-env-2tuvz0xl/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 142, in run_setup
            exec(compile(code, __file__, 'exec'), locals())
          File "setup.py", line 65, in <module>
            "blackd=blackd:patched_main [d]",
          File "/tmp/pip-build-env-2tuvz0xl/overlay/lib/python3.7/site-packages/setuptools/__init__.py", line 145, in setup
            return distutils.core.setup(**attrs)
          File "/home/rae/.pyenv/versions/3.7.3/lib/python3.7/distutils/core.py", line 108, in setup
            _setup_distribution = dist = klass(attrs)
          File "/tmp/pip-build-env-2tuvz0xl/overlay/lib/python3.7/site-packages/setuptools/dist.py", line 448, in __init__
            k: v for k, v in attrs.items()
          File "/home/rae/.pyenv/versions/3.7.3/lib/python3.7/distutils/dist.py", line 292, in __init__
            self.finalize_options()
          File "/tmp/pip-build-env-2tuvz0xl/overlay/lib/python3.7/site-packages/setuptools/dist.py", line 740, in finalize_options
            ep.load()(self)
          File "/tmp/pip-build-env-2tuvz0xl/overlay/lib/python3.7/site-packages/setuptools/dist.py", line 747, in _finalize_setup_keywords
            ep.load()(self, ep.name, value)
          File "/tmp/pip-build-env-2tuvz0xl/overlay/lib/python3.7/site-packages/setuptools_scm/integration.py", line 17, in version_keyword
            dist.metadata.version = get_version(**value)
          File "/tmp/pip-build-env-2tuvz0xl/overlay/lib/python3.7/site-packages/setuptools_scm/__init__.py", line 150, in get_version
            parsed_version = _do_parse(config)
          File "/tmp/pip-build-env-2tuvz0xl/overlay/lib/python3.7/site-packages/setuptools_scm/__init__.py", line 113, in _do_parse
            "use git+https://github.com/user/proj.git#egg=proj" % config.absolute_root
        LookupError: setuptools-scm was unable to detect version for '/tmp/pip-req-build-1ksmcb94'.
       
        Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.
       
       For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj
        ----------------------------------------
    ERROR: Command errored out with exit status 1: /home/rae/.cache/pre-commit/reporrf_4ype/py_env-python3.7/bin/python3.7 /home/rae/.cache/pre-commit/reporrf_4ype/py_env-python3.7/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmp7yzty2sc Check the logs for full command output.
   
Check the log at /home/rae/.cache/pre-commit/pre-commit.log

A longer log, with export SETUPTOOLS_SCM_DEBUG=1, is here: https://pastebin.com/YfYsxPPC.

I noticed that the following line in black’s setup.py seemed to be involved: "blackd=blackd:patched_main [d]",. When I specified a tagged version of black from just before that line was last edited (18.9b0), the environment setup ran through correctly.

Expected behavior

pre-commit should set up the black environment and then run black on the code to be committed.

Environment (please complete the following information):

  • Version: Anything later than 18.9b0, including stable or master
  • OS and Python version: Linux Mint 19.1 / Python 3.7.3

Does this bug also happen on master?

Yes.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Dec 13, 2019

yes, you can even combine the two as pre-commit install --install-hooks

we’re fixing the root cause in setuptools-scm though so that workaround shouldn’t be necessary indefinitely

1reaction
asottilecommented, Dec 13, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

black as pre-commit hook always fails my commits
What actually happens when I stage a (non-black-compliant) file and try to commit: Black goes ahead and modifies the file to make it...
Read more >
Some Pre-commit git hooks for Python
What we want to use as pre-commit hooks, in this post, are the following tools: black: a Python code formatter. Black. pycln: a...
Read more >
Pre-commit script errors out with "ValueError: time data 'gpg
I will go through the pre-commit script now. ❯ git commit -m "xxx" [INFO] Installing environment for https://github.com/psf/black. [INFO] Once ...
Read more >
Getting Started with Python Pre-commit Hooks
With minimal setup, pre-commit hooks can save you time by avoiding mistaken commits. Pre-commit hooks like black ensure the code you publish ...
Read more >
Automatically format and lint code with pre-commit - Interrupt
super simple setup; easy and flexible configuration; can be installed in a Python virtual environment, which our team was already using. It took ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found