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 for rye lock #1052

Open
Jeffrey-Lim opened this issue Apr 26, 2024 · 1 comment
Open

Add pre-commit hook for rye lock #1052

Jeffrey-Lim opened this issue Apr 26, 2024 · 1 comment

Comments

@Jeffrey-Lim
Copy link

Jeffrey-Lim commented Apr 26, 2024

Add a pre-commit hook that simply runs rye lock to ensure that requirements.lock is up to date with pyproject.toml. This is supposed to act similarly to the poetry-lock pre-commit hook.

@Jeffrey-Lim
Copy link
Author

I've tried to create a hook myself, but there is no straightforward way. You would expect that you could add a .pre-commit-hooks.yaml file like this:

- id: rye-lock
  name: rye-lock
  description: Run rye lock to update lock files
  entry: rye lock
  language: rust
  pass_filenames: false
  files: ^(.*/)?(requirements(-dev)?\.lock|pyproject\.toml)$

Unfortunately, pre-commit internally runs cargo install --bins --path ., which results in the error error: found a virtual manifest at <path> instead of a package manifest. Running cargo install --bins --path ./rye instead does work, but the pre-commit maintainer is against making --path configurable.

I tried to make a hook that relies on the host installation of rye instead like this:

- id: rye-lock
  name: rye-lock
  description: Run rye lock to update lock files
  entry: rye.exe lock
  language: system
  pass_filenames: false
  files: ^(.*/)?(requirements(-dev)?\.lock|pyproject\.toml)$

This works, but only on Windows, as you need to call rye.exe instead of just rye, so this hook is now platform-dependent.

You could also create a docker file and make use that in a docker pre-commit hook, but I don't think that is a good solution as you would need to install docker on your host machine.

Anyway, I hope that my findings will be a useful starting point for whoever wants to pick up on this.

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

No branches or pull requests

1 participant