FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-110652: Fix pre-commit hooks on macOS by erlend-aasland · Pull Request #110653 · python/cpython · GitHub

/ cpython Public

gh-110652: Fix pre-commit hooks on macOS - #110653

Closed
erlend-aasland wants to merge 2 commits into
python:mainfrom
erlend-aasland:no-pre-commit-for-you
Closed

gh-110652: Fix pre-commit hooks on macOS#110653
erlend-aasland wants to merge 2 commits into
python:mainfrom
erlend-aasland:no-pre-commit-for-you

Conversation

erlend-aasland commented Oct 10, 2023
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

AlexWaygood commented Oct 10, 2023
edited
Loading

Copy link
Copy Markdown
Member

This approach doesn't work on Windows, unfortunately, I don't think. I think I'd prefer using a python-language hook, as @hugovk suggested in #109891 (comment) (but see @AA-Turner's comments in #109891 (comment))

hugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Does this work on Windows?

cc @AA-Turner @AlexWaygood

Comment thread .pre-commit-config.yaml Outdated
Comment thread .pre-commit-config.yaml Outdated

Copy link
Copy Markdown
Member

Does this work on Windows?

no:

>pre-commit run --all-files
Run Ruff on Lib/test/....................................................Passed
Run Ruff on Argument Clinic..............................................Passed
check toml...............................................................Passed
check yaml...............................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
Check Python file whitespace.............................................Failed
- hook id: python-file-whitespace
- exit code: 9009

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

Check C file whitespace..................................................Failed
- hook id: c-file-whitespace
- exit code: 9009

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

Sphinx lint..............................................................Passed
Check hooks apply to the repository......................................Passed
Check for useless excludes...............................................Passed

Copy link
Copy Markdown
Member

It isn't well documented, but I had hoped language: script offered the salvation we desire. Sadly; no:

Check Python file whitespace.............................................Failed
- hook id: python-file-whitespace
- exit code: 1

Executable `python3` not found

Check C file whitespace..................................................Failed
- hook id: c-file-whitespace
- exit code: 1

Executable `python3` not found

This is, I think, as the shebang line says #! /usr/bin/env python3 -- if I change it to #! /usr/bin/env python, it passes for me. I'm not sure how to write such a line to choose between python3 or python, though.

A

hugovk commented Oct 11, 2023

Copy link
Copy Markdown
Member

With:

        name: "Check Python file whitespace"
        entry: 'Tools/patchcheck/reindent.py --nobackup --newline LF'

And:

#! /usr/bin/env python

On macOS I get:

Executable `python` not found

AlexWaygood commented Oct 11, 2023
edited
Loading

Copy link
Copy Markdown
Member

@AA-Turner, in #109891 (comment) you commented that using a Python-language hook (rather than a system-language hook, as we have currently) might slow us down unnecessarily, as pre-commit would have to create a venv before the hook would run. But in my experience, the Python-language hooks in the pre-commit-hooks package are plenty fast enough. I think pre-commit might locally cache the venvs it creates, and reuse them in future invocations of the same hook?

Copy link
Copy Markdown
Contributor Author

@AlexWaygood, does 9501fab work on Windows?

erlend-aasland added the needs backport to 3.12 only security fixes label Oct 11, 2023

Copy link
Copy Markdown
Member

@AlexWaygood, does 9501fab work on Windows?

Argh, that's still a no :((

Details
>pre-commit run --all-files
[INFO] Initializing environment for local.
[INFO] Installing environment for local.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
Run Ruff on Lib/test/....................................................Passed
Run Ruff on Argument Clinic..............................................Passed
check toml...............................................................Passed
check yaml...............................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
Check Python file whitespace.............................................Failed
- hook id: python-file-whitespace
- exit code: 9009

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

Check C file whitespace..................................................Failed
- hook id: c-file-whitespace
- exit code: 9009

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

Sphinx lint..............................................................Passed
Check hooks apply to the repository......................................Passed
Check for useless excludes...............................................Passed

Copy link
Copy Markdown
Contributor Author

Sounds like it's a pre-commit bug; their docs says it should work on Windows: https://pre-commit.com/#python

Copy link
Copy Markdown
Member

Sounds like it's a pre-commit bug; their docs says it should work on Windows: https://pre-commit.com/#python

The docs also say this, however, which isn't what we're doing:

The hook repository must be installable via pip install . (usually by either setup.py or pyproject.toml). The installed package will provide an executable that will match the entry – usually through console_scripts or scripts in setup.py.

I'm guessing this is the issue here -- the python-language hooks in the pre-commit-hooks repo are all installed hooks that have their own entry points: https://github.com/pre-commit/pre-commit-hooks/blob/27dcd3fd1dc01d3fdbeb188edb54dddf3d964236/setup.cfg#L31

Copy link
Copy Markdown
Contributor Author

Then let's make those scripts pip installable.

erlend-aasland deleted the no-pre-commit-for-you branch October 11, 2023 09:42

Copy link
Copy Markdown
Contributor Author

Closing; see issue.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL