Skip to content

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

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

Closed

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Oct 10, 2023

@AlexWaygood
Copy link
Member

AlexWaygood commented Oct 10, 2023

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))

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Does this work on Windows?

cc @AA-Turner @AlexWaygood

@AlexWaygood
Copy link
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

@AA-Turner
Copy link
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
Copy link
Member

hugovk commented Oct 11, 2023

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
Copy link
Member

AlexWaygood commented Oct 11, 2023

@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?

@erlend-aasland
Copy link
Contributor Author

@AlexWaygood, does 9501fab work on Windows?

@erlend-aasland erlend-aasland added the needs backport to 3.12 only security fixes label Oct 11, 2023
@AlexWaygood
Copy link
Member

@AlexWaygood, does 9501fab work on Windows?

Argh, that's still a no :((

>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

@erlend-aasland
Copy link
Contributor Author

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

@AlexWaygood
Copy link
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

@erlend-aasland
Copy link
Contributor Author

Then let's make those scripts pip installable.

@erlend-aasland erlend-aasland deleted the no-pre-commit-for-you branch October 11, 2023 09:42
@erlend-aasland
Copy link
Contributor Author

Closing; see issue.

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