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

Add pre-commit hook #565

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add pre-commit hook #565

wants to merge 1 commit into from

Conversation

amitds1997
Copy link

@amitds1997 amitds1997 commented Oct 30, 2023

Fixes #539

Rust-based pre-commit does not work because pre-commit hardcodes the --path to . which leads to build failure and errors with found a virtual manifest at <path>/Cargo.toml instead of a package manifest. Pre-commit maintainer disagrees with making this configurable so it is not possible to add a rust based hook: pre-commit/pre-commit#2931

@amitds1997 amitds1997 force-pushed the main branch 2 times, most recently from 65784e2 to 05b36fe Compare October 30, 2023 16:18
@@ -0,0 +1,15 @@
- id: selene-system
Copy link
Author

Choose a reason for hiding this comment

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

Rust-based pre-commit does not work because pre-commit hardcodes the --path to . (source) which leads to build failure with error: found a virtual manifest at <path>/Cargo.toml instead of a package manifest.

Pre-commit maintainer disagrees with making --path configurable so it is not possible to add a rust based hook: pre-commit/pre-commit#2931 unless we somehow make it possible to install the binary from root level.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's possible to point entry to a custom install script. But we'd need to handle the caching, unless we distribute the executable directly.

Copy link
Author

@amitds1997 amitds1997 Oct 31, 2023

Choose a reason for hiding this comment

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

I was unsure if we wanted a custom install script just for the pre-commit use case. I can add it if that's something we are okay with.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would depend on how it would look like. Caching binaries by version may not be trivial and we don't get the same advantages language: rust gets, which makes me think it's likely not worth the effort to support this.

Copy link
Author

Choose a reason for hiding this comment

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

Agree. That's why went ahead with only setting up system and docker workflows. Is there some trivial way to make this work by may be a configuration change at our end? I did some preliminary research but did not find much (but then I have not worked with rust ever before).

Choose a reason for hiding this comment

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

Have you looked at how StyLua handles the pre-commit hook?

Copy link
Author

Choose a reason for hiding this comment

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

Their rust workflow works because they do not use workspaces.

The python workflow seems interesting. We can integrate it, but it would depend on a python package (https://pypi.org/project/release-gitter/) to do the release download for us. If that is something we are okay with, I can add it 👍

Copy link
Author

Choose a reason for hiding this comment

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

Added GitHub release based pre-commit hook in 5f1a755

Copy link
Collaborator

@chriscerie chriscerie left a comment

Choose a reason for hiding this comment

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

Need changelog

docs/src/SUMMARY.md Outdated Show resolved Hide resolved
@@ -0,0 +1,15 @@
- id: selene-system
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's possible to point entry to a custom install script. But we'd need to handle the caching, unless we distribute the executable directly.

@amitds1997 amitds1997 requested a review from chriscerie November 2, 2023 06:20
Copy link
Collaborator

@chriscerie chriscerie left a comment

Choose a reason for hiding this comment

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

It looks like pre-commit builds docker with docker build ., which causes the light build to be used. This isn't compatible with roblox projects. It also doesn't seem like pre-commit supports changing the build command, so a rather hacky workaround could be to move the selene-musl build to the last in the dockerfile.

CHANGELOG.md Outdated Show resolved Hide resolved
docs/src/usage/git-hooks-pre-commit.md Outdated Show resolved Hide resolved
auto-merge was automatically disabled December 27, 2023 17:47

Head branch was pushed to by a user without write access

@amitds1997 amitds1997 force-pushed the main branch 3 times, most recently from 8cd3099 to 5f1a755 Compare December 27, 2023 18:45
@amitds1997
Copy link
Author

@chriscerie @jenstroeger Let me know if there's something else needed from my end to get this through.

@chriscerie
Copy link
Collaborator

I’m currently ooo, I’ll take a look at the changes within the next week or so.

@chriscerie
Copy link
Collaborator

@amitds1997 Are you able to upload the builds under your fork's release? I think that's needed to test selene-github.

@amitds1997
Copy link
Author

@amitds1997 Are you able to upload the builds under your fork's release? I think that's needed to test selene-github.

I was able to test it out with this:

  - repo: https://github.com/amitds1997/selene
    rev: d895ab518a9a3fd6e8efe1716fde501dd29fe8ba # The latest commit on the PR branch
    hooks:
      - id: selene-github

Did not face any issues. The reason I think this should work is that it looks for releases under Kampfkarren/selene's releases (see amitds1997/selene/pyproject.toml#L6). Are you seeing any particular error?

@chriscerie
Copy link
Collaborator

Are you seeing any particular error?

It works when I have a local copy of selene, but it's breaking when it's not installed:

selene (GitHub)..........................................................Failed
- hook id: selene-github
- exit code: 1

Executable `selene` not found

You're right about it using git-url to get the upstream repo. Perhaps where it's breaking is it's missing extract-files (https://github.com/JohnnyMorganz/StyLua/blob/main/pyproject.toml#L7) and it's falling back to a local copy of selene if installed?

@IamTheFij
Copy link

Hello. I just started looking into Selene and noticed that this is kind of waiting on me! Sorry about that. I just pushed a new version that should resolve this issue and allow the GitHub install hook to properly download.

@amitds1997 amitds1997 force-pushed the main branch 4 times, most recently from b537deb to 93b27be Compare November 1, 2024 13:57
@amitds1997
Copy link
Author

@chriscerie @jenstroeger With the latest release to release-gitter (thanks @IamTheFij), we have a working solution for pip-based pre-commit installation.

With this, we should have pre-commit support using local exec, docker and pip (python). Let me know if anything else would be needed from my end.

pyproject.toml Outdated
Comment on lines 11 to 14
[tool.release-gitter.map-system]
Darwin = "macos"
Windows = "windows"
Linux = "linux"

Choose a reason for hiding this comment

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

These should no longer be needed. This was common enough that I added it as default values. That said, there is no harm in leaving them.

https://github.com/IamTheFij/release-gitter/blob/main/release_gitter.py#L51

SYSTEM_SYNONYMS: list[list[str]] = [
    ["Darwin", "darwin", "MacOS", "macos", "macOS"],
    ["Windows", "windows", "win", "win32", "win64"],
    ["Linux", "linux"],
]

Copy link
Author

@amitds1997 amitds1997 Nov 2, 2024

Choose a reason for hiding this comment

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

Thanks for the input! Removed this in the latest commit (391b18d).

Copy link

@IamTheFij IamTheFij left a comment

Choose a reason for hiding this comment

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

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for pre-commit hooks?
4 participants