hukkin / mdformat

CommonMark compliant Markdown formatter
https://mdformat.rtfd.io
MIT License
459 stars 46 forks source link

ModuleNotFoundError: No module named 'pkg_resources' #442

Closed vincentqb closed 1 month ago

vincentqb commented 2 months ago

Describe the bug

After installing mdformat with pre-commit install, the first commit raises an error.

Relates to https://github.com/pre-commit/pre-commit/issues/2122

Reproduce the bug

Here's an error message I ran into with this configuration:

- repo: https://github.com/executablebooks/mdformat
  rev: 0.7.17
  hooks:
  - id: mdformat
    additional_dependencies:
    - mdformat-gfm  # use github flavor markdown
    - mdformat-black  # format python code block with black
    - mdformat-beautysh  # format bash code block with beautysh
$ pre-commit install
...
mdformat.................................................................Failed
- hook id: mdformat
- exit code: 1

Traceback (most recent call last):
  File "/home/vincent/.cache/pre-commit/repole_rylg8/py_env-python3.12/bin/mdformat", line 5, in <module>
    from mdformat.__main__ import run
  File "/home/vincent/.cache/pre-commit/repole_rylg8/py_env-python3.12/lib/python3.12/site-packages/mdformat/__init__.py", line 4, in <module>
    from mdformat._api import file, text
  File "/home/vincent/.cache/pre-commit/repole_rylg8/py_env-python3.12/lib/python3.12/site-packages/mdformat/_api.py", line 10, in <module>
    from mdformat._util import EMPTY_MAP, NULL_CTX, build_mdit, detect_newline_type
  File "/home/vincent/.cache/pre-commit/repole_rylg8/py_env-python3.12/lib/python3.12/site-packages/mdformat/_util.py", line 12, in <module>
    import mdformat.plugins
  File "/home/vincent/.cache/pre-commit/repole_rylg8/py_env-python3.12/lib/python3.12/site-packages/mdformat/plugins.py", line 20, in <module>
    CODEFORMATTERS: Mapping[str, Callable[[str, str], str]] = _load_codeformatters()
                                                              ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vincent/.cache/pre-commit/repole_rylg8/py_env-python3.12/lib/python3.12/site-packages/mdformat/plugins.py", line 17, in _load_codeformatters
    return {ep.name: ep.load() for ep in codeformatter_entrypoints}
                     ^^^^^^^^^
  File "/home/vincent/miniconda/envs/dotpy/lib/python3.12/importlib/metadata/__init__.py", line 205, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vincent/miniconda/envs/dotpy/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vincent/.cache/pre-commit/repole_rylg8/py_env-python3.12/lib/python3.12/site-packages/mdformat_beautysh/__init__.py", line 1, in <module>
    from beautysh import Beautify
  File "/home/vincent/.cache/pre-commit/repole_rylg8/py_env-python3.12/lib/python3.12/site-packages/beautysh/__init__.py", line 9, in <module>
    import pkg_resources  # part of setuptools
    ^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'pkg_resources'

List your environment

wsl python 3.12.5

vincentqb commented 2 months ago

It seems to work if I add each additional dependencies one after the other (amending the commit each time).

KyleKing commented 2 months ago

Hi @vincentqb, the issue is actually with “beautysh” (https://github.com/lovesegfault/beautysh/issues/248). The current workaround is to add “setuptools” as a pre-commit dependency until beautysh is updated for Python 3.12

hukkin commented 1 month ago

I'm closing, as mdformat (or mdformat-beautysh) isn't to blame here.