andreoliwa / nitpick

Enforce the same settings on multiple projects
https://nitpick.readthedocs.io/
MIT License
399 stars 25 forks source link

Pre-commit hook is incompatible with requests_cache==1.0 #514

Closed eremeevfd closed 1 year ago

eremeevfd commented 1 year ago

Expected behavior

Pre-commit hook works without exception

Current behavior


Traceback (most recent call last):
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/bin/nitpick", line 8, in <module>
    sys.exit(nitpick_cli())
             ^^^^^^^^^^^^^
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/nitpick/cli.py", line 103, in fix
    common_fix_or_check(context, verbose, files, False)
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/nitpick/cli.py", line 82, in common_fix_or_check
    for fuss in nit.run(*files, autofix=not check_only):
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/nitpick/core.py", line 63, in run
    yield from chain(
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/nitpick/project.py", line 181, in merge_styles
    from nitpick.style import StyleManager
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/nitpick/style/__init__.py", line 2, in <module>
    from nitpick.style.cache import parse_cache_option
  File "/Users/f.eremeev/.cache/pre-commit/repo3x10obpc/py_env-python3/lib/python3.11/site-packages/nitpick/style/cache.py", line 8, in <module>
    from requests_cache.cache_control import DO_NOT_CACHE, NEVER_EXPIRE
ModuleNotFoundError: No module named 'requests_cache.cache_control'

Steps to reproduce

  1. install nitpick (or upgrade requests_cache to 1.0)
  2. set cache = never in pyproject.toml for nitpick
  3. run pre-commit with nitpick hook
  4. catch exception

Possible Solution

pin requests_cache to <1.0 or update import in this file:

nitpick/style/cache.py
from requests_cache.cache_control import DO_NOT_CACHE, NEVER_EXPIRE

change to:

from requests_cache.policy.expiration import DO_NOT_CACHE, NEVER_EXPIRE

Your environment

For more information, see the CONTRIBUTING guide.

andreoliwa commented 1 year ago

Fixed by https://github.com/andreoliwa/nitpick/pull/518.