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

CI: Call local python pre-commit scripts via shell #92556

Closed
wants to merge 1 commit into from

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented May 30, 2024

Alternative to #90634 and #90662

This is a slightly hacky but fully-functional workaround for allowing local pre-commit python scripts to be fully multi-platform. Because we can only provide a static entry point, this PR converts said entry point to a new shell script wrapper: misc/scripts/python.sh. This script's job is to evaluate several Python alias calls to see if they exist on the user's path; if a match is found, that alias is used to call the provided arguments directly.

Also assigns proper arguments for doc-status, as I learned in local testing that it required a similar argument setup as make-rst. Both of these now call said arguments via args instead of extending off entry.

@Repiteo Repiteo added this to the 4.3 milestone May 30, 2024
@Repiteo Repiteo requested a review from a team as a code owner May 30, 2024 15:53
@akien-mga
Copy link
Member

Are shell scripts a reliable entry point on Windows?

I wonder if the entry point should actually be a Python script with /usr/bin/env python shebang, with code that's compatible with both Python 2 and Python 3, and can be used to find the right python3 binary to call like your shell script does.

@Repiteo
Copy link
Contributor Author

Repiteo commented May 30, 2024

It's reliable insofar as pre-commit also utilizes shell scripts; if a Windows instance couldn't support this script, it wouldn't support pre-commit outright. If a Windows user is using Git, they've almost certainly got a means of running shell scripts. In any case, Windows users are the roadblock regardless; they're the only ones that don't have python3 defined by default.

Still, doesn't hurt to double-check. @chrisl8 @nlupugla were both Windows users that tested the other PRs, their input would be appreciated.

@chrisl8
Copy link
Contributor

chrisl8 commented May 30, 2024

I believe that the reason why pre-commits and other shell scripts work for Windows users is that when you install git on Windows it also installs "git Bash" and associates .sh files with it.

This image is copied from Google, so could be out of date, but here is a reference:
screenshot-of-git-bash-installation

So basically no, Windows cannot run .sh scripts, but any Windows host with git installed should be able to unless the user didn't follow the default git installation path.

Here is a good reference on "Git Bash" that others who land here may find useful:
https://www.gitkraken.com/blog/what-is-git-bash

I'll test this PR and report back, and I agree that others should test too. The Windows landscape is not as consistent as Linux/MacOS when it comes to git and shell availability.

@chrisl8
Copy link
Contributor

chrisl8 commented May 30, 2024

Testing

TL;DR: Mixed results. Seems better with this PR, but not perfect. I'm not sure if this is the same issue or a new one though, as the "Python was not found" messages go away, and some things work that did not before.

Current Master latest

PS D:\> gh repo clone godotengine/godot
Cloning into 'godot'...
remote: Enumerating objects: 704698, done.
remote: Counting objects: 100% (275/275), done.
remote: Compressing objects: 100% (186/186), done.
remote: Total 704698 (delta 128), reused 168 (delta 89), pack-reused 704423
Receiving objects: 100% (704698/704698), 1.28 GiB | 64.47 MiB/s, done.
Resolving deltas: 100% (558240/558240), done.
Updating files: 100% (11084/11084), done.

PS D:\> cd .\godot\
PS D:\godot> pre-commit run --all
clang-format.............................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Passed
mypy.....................................................................Passed
codespell................................................................Passed
make-rst.................................................................Failed
- hook id: make-rst
- 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.

doc-status...............................................................Failed
- hook id: doc-status
- 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.
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.
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.

eslint...................................................................Passed
jsdoc....................................................................Passed
copyright-headers........................................................Failed
- hook id: copyright-headers
- 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.
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.
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.

header-guards............................................................Failed
- hook id: header-guards
- 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.
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.
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.

file-format..............................................................Failed
- hook id: file-format
- 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.
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.
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.

dotnet-format............................................................Failed
- hook id: dotnet-format
- 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.
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.
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.

This PR

PS D:\godot> gh pr checkout 92556
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 0), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), 5.01 KiB | 732.00 KiB/s, done.
From https://github.com/godotengine/godot
 * [new ref]               refs/pull/92556/head -> ci/python-shell-launcher
Switched to branch 'ci/python-shell-launcher'
PS D:\godot> pre-commit run --all
clang-format.............................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Passed
mypy.....................................................................Passed
codespell................................................................Passed
make-rst.................................................................Passed
doc-status...............................................................Passed
eslint...................................................................Passed
jsdoc....................................................................Passed
copyright-headers........................................................Passed
                                                                               header-guards............................................................Failed
                                                                                                                                                              - hook id: header-guards
                                                                                                                                                                                      - exit code: 1

                                                                                                                                                                                                    A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Error code: Bash/Service/0x8007274c
Catastrophic failure
Error code: Bash/Service/E_UNEXPECTED
Catastrophic failure
Error code: Bash/Service/E_UNEXPECTED
Catastrophic failure
Error code: Bash/Service/E_UNEXPECTED
Catastrophic failure
Error code: Bash/Service/E_UNEXPECTED
Catastrophic failure
Error code: Bash/Service/E_UNEXPECTED
Catastrophic failure
Error code: Bash/Service/E_UNEXPECTED
Catastrophic failure
Error code: Bash/Service/E_UNEXPECTED
Catastrophic failure
Error code: Bash/Service/E_UNEXPECTED


file-format..............................................................Passed
                                                                               dotnet-format............................................................Passed

Note that the odd formatting IS what I saw on screen too.

@Repiteo
Copy link
Contributor Author

Repiteo commented May 30, 2024

Shoot; back to the drawing board

@chrisl8
Copy link
Contributor

chrisl8 commented May 30, 2024

@Repiteo

Shoot; back to the drawing board

Well not really, you totally fixed the Python was not found issue, and some checks that didn't run at all before do now.

I can dig into what is causing he Catastrophic failure Error code: Bash/Service/E_UNEXPECTED errors myself in a day or two if it would help.

EDIT: It occurs to me that you didn't understand my testing comment. Did you scroll down and see the results with this PR? The Master run was expected to fail.

@Repiteo
Copy link
Contributor Author

Repiteo commented May 30, 2024

Ah! I did see the second results, but I misread the error as applying to all the cases instead of just one. Okay yeah, its not starting completely from scratch this time.

Looking at how the odd formatting seems to move strictly downward, I'll bet this is somehow tied to a lack of carriage return. But with the wrapper method working, it's possible that this issue could be dodged entirely if the wrapper was applied to something like an scons call instead. Either way, this gives me something to look into!

@Repiteo
Copy link
Contributor Author

Repiteo commented May 31, 2024

Did some timing tests, and this turns out to make the hooks significantly slower. Combined with the above formatting oddities, I'm marking this as a draft for now while I look into alternatives.

@Repiteo Repiteo marked this pull request as draft May 31, 2024 15:23
@chrisl8
Copy link
Contributor

chrisl8 commented May 31, 2024

@Repiteo You might look into akien-mga's idea too:

I wonder if the entry point should actually be a Python script with /usr/bin/env python shebang, with code that's compatible with both Python 2 and Python 3, and can be used to find the right python3 binary to call like your shell script does.

Feel free to ping me with any further testing requests as well.

@Repiteo
Copy link
Contributor Author

Repiteo commented May 31, 2024

Unfortunately it seems that stock MacOS only comes with python3, not python. No matter how you slice it, python doesn't seem to have a 100% consistent name that can be called to by pre-commit

@Repiteo
Copy link
Contributor Author

Repiteo commented Jun 2, 2024

Superseded by #92697

@Repiteo Repiteo closed this Jun 2, 2024
@Repiteo Repiteo deleted the ci/python-shell-launcher branch June 2, 2024 18:32
@AThousandShips AThousandShips removed this from the 4.3 milestone Jun 2, 2024
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