install-pre-commit-hook.rst 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. Install Pre-commit Hook for ESP-IDF Project
  2. ===========================================
  3. :link_to_translation:`zh_CN:[中文]`
  4. Required Dependency
  5. -------------------
  6. Python 3.8.* or above. This is our recommended Python version for ESP-IDF developers.
  7. If you still have Python versions not compatible, update your Python versions before installing the pre-commit hook.
  8. Install ``pre-commit``
  9. ----------------------
  10. Run ``pip install pre-commit``
  11. Install ``pre-commit`` Hook
  12. ---------------------------
  13. 1. Go to the ESP-IDF project directory.
  14. 2. Run ``pre-commit install --allow-missing-config -t pre-commit -t commit-msg``. Install hook by this approach will let you commit successfully even in branches without the ``.pre-commit-config.yaml``
  15. 3. pre-commit hook will run automatically when you are running ``git commit`` command
  16. Uninstall ``pre-commit`` Hook
  17. -----------------------------
  18. Run ``pre-commit uninstall``
  19. What Is More?
  20. -------------
  21. For detailed usage, please refer to the documentation of pre-commit_.
  22. .. _pre-commit: https://pre-commit.com/
  23. Common Problems For Windows Users
  24. ---------------------------------
  25. ``/usr/bin/env: python: Permission denied.``
  26. If you are in Git Bash, please check the python executable location by run ``which python``.
  27. If the executable is under ``~/AppData/Local/Microsoft/WindowsApps/``, then it is a link to Windows AppStore, not a real one.
  28. Please install Python manually and update this in your ``PATH`` environment variable.
  29. Your ``USERPROFILE`` contains non-ASCII characters
  30. ``pre-commit`` may fail when initializing an environment for a particular hook when the path of ``pre-commit``'s cache contains non-ASCII characters. The solution is to set ``PRE_COMMIT_HOME`` to a path containing only standard characters before running pre-commit.
  31. - CMD: ``set PRE_COMMIT_HOME=C:\somepath\pre-commit``
  32. - PowerShell: ``$Env:PRE_COMMIT_HOME = "C:\somepath\pre-commit"``
  33. - git bash: ``export PRE_COMMIT_HOME="/c/somepath/pre-commit"``