We created a pre-commit hook for our project. But when we ran that pre-commit on Windows, we got an error:
Check copyright notices...................................................................Failed
- hook id: check-copyright
- exit code: 1
Executable `C:Userstore.cachepre-commitrepoq2jv0lxhpy_env-python3.9Scriptspython.EXE` not found
So, pre-commit lose slashes for Windows machine. How to fix it? In pre-commit script we have #!/usr/bin/env python
shebang, could it be a problem with that?
For Unix-systems everything is ok
.pre-commit-config.yaml
- repo: https://github.com/espressif/check-copyright/
rev: v1.0.0
hooks:
- id: check-copyright
args: ['--ignore', 'tools/ci/check_copyright_ignore.txt', '--config', 'tools/ci/check_copyright_config.yaml']
.pre-commit-hooks.yaml:
- id: check-copyright
name: Check copyright notices
entry: check_copyright.py --verbose --replace
language: python
files: \.(py|c|h|cpp|hpp|ld|s|S)$
require_serial: true
Full repository: https://github.com/espressif/check-copyright
the hook you are using is packaged poorly -- it doesn't properly support windows installations
their usage of scripts
generates a file in the bin directory with a (bogus) shebang:
C:\Users\Anthony\workspace\check-copyright>head -1 venv\Scripts\check_copyright.py
#!C:\Users\Anthony\workspace\check-copyright\venv\Scripts\python.exe
the supported way to make platform-agnostic entrypoints is to utilize console_scripts
:
the easiest fix is to submit a pull request which adjusts their usage of scripts
to instead utilize console_scripts
:
diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml
index dd2ebf1..9ed932b 100644
--- a/.pre-commit-hooks.yaml
+++ b/.pre-commit-hooks.yaml
@@ -1,6 +1,6 @@
- id: check-copyright
name: Check copyright notices
- entry: check_copyright.py --verbose --replace
+ entry: check-copyright --verbose --replace
language: python
files: \.(py|c|h|cpp|hpp|ld|s|S)$
require_serial: true
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 97b5cc6..c5c01bb 100644
--- a/setup.py
+++ b/setup.py
@@ -33,5 +33,6 @@ setuptools.setup(
url=URL,
install_requires=REQUIRES,
py_modules=['check_copyright'],
- scripts=['check_copyright.py']
+ scripts=['check_copyright.py'],
+ entry_points={'console_scripts': ['check-copyright=check_copyright:main']},
)
disclaimer: I created pre-commit