Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support patching pre-commit hooks written in bash #696

Merged
merged 3 commits into from
May 16, 2022
Merged

Conversation

cjolowicz
Copy link
Owner

@cjolowicz cjolowicz added the ci Continuous Integration label May 16, 2022
cjolowicz and others added 3 commits May 16, 2022 16:40
* πŸ”¨ Split conditional

* πŸ”¨ Replace `if not continue` with `if`

* ✨ Add bash version

* πŸ”¨ Add comments with pre-commit version ranges

* πŸ”¨ Extract variable `patches`

* πŸ”¨ Move bash fragment into `patches`

* πŸ”¨ Slide comments

* πŸ”¨ Replace `if...elif` with `for...if...break` loop over `patches`

* πŸ”¨ Do not duplicate `patches` keys

* πŸ”¨ Inline variable `header`

* πŸ”¨ Rename variable `patches` to `headers`

* πŸ”¨ Rename variable `patch` to `header`

* πŸ”¨ Support multiple languages when checking for bindir

* ✨ Support bash when checking for bindir

* πŸ”¨ Slide `bindirs` before loop

* πŸ› Fix over-aggressive quote removal for bindir in bash hooks

* πŸ”¨ Inline variable `bindirs` into `bindirs`

* πŸ’‘ Expand comment

* πŸ”¨ Slide `headers` before loop

* πŸ”¨ Replace `lines[0].startswith` with `hook.read_bytes().startswith`

* πŸ› Do not attempt to decode hooks unless they have a shebang

Retrocookie-Original-Commit: cjolowicz/cookiecutter-hypermodern-python-instance@b2a958a
The patched pre-commit hooks installed by the `pre-commit` Nox session modify
the `PATH` environment variable, using `os.pathsep` to separate prepended paths.
On Git Bash for Windows, `os.pathsep` is a shell-special character and needs to
be quoted. This commit quotes the path separator.

This fixes the following error on Windows when invoking pre-commit from Git:

```
.git/hooks/pre-commit: line 3: C:\Users\User\hypermodern-python\.nox\pre-commit\Scripts: Is a directory
.git/hooks/pre-commit: line 13: dirname: command not found
An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?
```

Retrocookie-Original-Commit: cjolowicz/cookiecutter-hypermodern-python-instance@2d133a0
* fix Windows support by handling sh shebangs from pre-commit

* More specific pattern to detect sh shell
@cjolowicz cjolowicz changed the title ✨ [nox] Support patching pre-commit hooks written in bash Support patching pre-commit hooks written in bash May 16, 2022
@cjolowicz cjolowicz merged commit 740f7c1 into main May 16, 2022
@cjolowicz cjolowicz deleted the ci/pre-commit branch May 16, 2022 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci Continuous Integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants