Pre-commit script errors out with "ValueError: time data 'gpg: Signature made ... does not match format"

Hey there,
I’m working on my first core contribution and ran in the pre-commit script error shown below. Any ideas? I will go through the pre-commit script now.

❯ git commit -m "xxx"
[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: ('/Users/user/.cache/pre-commit/repoorx8kr7l/py_env-python3/bin/python', '-mpip', 'install', '.')
return code: 1
expected return code: 0
stdout:
    Processing /Users/user/.cache/pre-commit/repoorx8kr7l
      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'

stderr:
        ERROR: Command errored out with exit status 1:
         command: /Users/user/.cache/pre-commit/repoorx8kr7l/py_env-python3/bin/python /Users/user/.cache/pre-commit/repoorx8kr7l/py_env-python3/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/tmppxgjw9tp
             cwd: /private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-req-build-4bmxdj4h
        Complete output (46 lines):
        /private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools_scm/git.py:88: UserWarning: "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-req-build-4bmxdj4h" is shallow and may cause errors
          warnings.warn(f'"{wd.path}" is shallow and may cause errors')
        Traceback (most recent call last):
          File "/Users/user/.cache/pre-commit/repoorx8kr7l/py_env-python3/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
            main()
          File "/Users/user/.cache/pre-commit/repoorx8kr7l/py_env-python3/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
            json_out['return_val'] = hook(**hook_input['kwargs'])
          File "/Users/user/.cache/pre-commit/repoorx8kr7l/py_env-python3/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 133, in prepare_metadata_for_build_wheel
            return hook(metadata_directory, config_settings)
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 166, in prepare_metadata_for_build_wheel
            self.run_setup()
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 150, in run_setup
            exec(compile(code, __file__, 'exec'), locals())
          File "setup.py", line 48, in <module>
            setup(
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
            return distutils.core.setup(**attrs)
          File "/opt/homebrew/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 108, in setup
            _setup_distribution = dist = klass(attrs)
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 434, in __init__
            _Distribution.__init__(self, {
          File "/opt/homebrew/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 292, in __init__
            self.finalize_options()
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 743, in finalize_options
            ep(self)
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 750, in _finalize_setup_keywords
            ep.load()(self, ep.name, value)
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools_scm/integration.py", line 24, in version_keyword
            dist.metadata.version = _get_version(config)
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 173, in _get_version
            parsed_version = _do_parse(config)
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 127, in _do_parse
            version = _version_from_entrypoints(config) or _version_from_entrypoints(
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 65, in _version_from_entrypoints
            version = _call_entrypoint_fn(root, config, ep.load())
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 46, in _call_entrypoint_fn
            return fn(root, config=config)
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools_scm/git.py", line 127, in parse
            node_date = wd.get_head_date() or date.today()
          File "/private/var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/pip-build-env-p2uka2pv/overlay/lib/python3.9/site-packages/setuptools_scm/git.py", line 67, in get_head_date
            return datetime.strptime(date_part, r"%Y-%m-%d").date()
          File "/opt/homebrew/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/_strptime.py", line 568, in _strptime_datetime
            tt, fraction, gmtoff_fraction = _strptime(data_string, format)
          File "/opt/homebrew/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/_strptime.py", line 349, in _strptime
            raise ValueError("time data %r does not match format %r" %
        ValueError: time data 'gpg: Signature made Wed Apr 28 16:50:04 2021 CES' does not match format '%Y-%m-%d'
        ----------------------------------------
    WARNING: Discarding file:///Users/user/.cache/pre-commit/repoorx8kr7l. Command errored out with exit status 1: /Users/user/.cache/pre-commit/repoorx8kr7l/py_env-python3/bin/python /Users/user/.cache/pre-commit/repoorx8kr7l/py_env-python3/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/tmppxgjw9tp Check the logs for full command output.
    ERROR: Command errored out with exit status 1: /Users/user/.cache/pre-commit/repoorx8kr7l/py_env-python3/bin/python /Users/user/.cache/pre-commit/repoorx8kr7l/py_env-python3/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /var/folders/nc/vg00848974ggdcn6gq43qsyhnldw01/T/tmppxgjw9tp Check the logs for full command output.

Check the log at /Users/user/.cache/pre-commit/pre-commit.log
❯ /Users/user/.cache/pre-commit/repoorx8kr7l/pyproject.toml

Found a workaround.

I already had a hunch this might be related to my use of gpg signatures with git. Strange enough I did not commit anything on “Wed Apr 28 16:50:04 2021”.

Same issue and solution: Pre-commit fails when setting up the black environment · Issue #2059 · psf/black · GitHub

This is being solved in GPG Signature causes: Preparing wheel metadata: finished with status 'error' · Issue #548 · pypa/setuptools_scm · GitHub

In the meantime the easiest fix is to run git config log.showSignature false followed by the pre-commit. As the critical part of the pre-commit is only executed once, you can enable signatures again (if you really care)