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 uv-run hook #37

Open
danielhollas opened this issue Jan 10, 2025 · 5 comments · May be fixed by #42
Open

Add uv-run hook #37

danielhollas opened this issue Jan 10, 2025 · 5 comments · May be fixed by #42

Comments

@danielhollas
Copy link
Contributor

We have a small python script with a handful of external dependencies which we want to run as a local pre-commit hook. To ensure that the dependencies are installed, it would be great to use PEP-723 inline script metadata and use uv run --script to execute the script.

Would it be possible to add a uv-run hook that would allow for this?
This would be helpful since we don't want our developer to have to install uv (as much as I love it of course :D), so ideally this would "just work" behind the scenes.

I am happy to submit a PR if that would be helpful.

Thanks!

(if there are other ways to do the thing outlined above I am all ears)

@danielhollas
Copy link
Contributor Author

Related to #14

@danielhollas
Copy link
Contributor Author

@zanieb would you be open to this idea?

@zanieb
Copy link
Member

zanieb commented Jan 28, 2025

What would this look like in practice? (I'm not a pre-commit expert)

@danielhollas
Copy link
Contributor Author

So basically I'd like to change the current local hook (which requires global uv installation) that looks like this in .pre-commit-config.yaml

  - repo: local
    hooks:
    - id: local-python-script
      name: Standalone script with PEP-723 deps    
      entry: uv run ./utils/standalone_script.py --some-option  
      language: system
      pass_filenames: false

to

  - repo: https://github.com/astral-sh/uv-pre-commit
    rev: 0.5.22
    hooks:                                                                                                                         
    - id: uv-run
      name: Standalone script with PEP-723 deps
      args: ['utils/standalone_script.py', '--some-option']

Because of the way uv run works, this would also cover a use case of running a command/script within the virtual environment of the project. The typical use case for this would be running mypy, as described in #14 (comment)

I am also not a pre-commit expert so it's possible there are some issues that I am not seeing, but it looks doable.

@zanieb
Copy link
Member

zanieb commented Jan 30, 2025

That seems reasonable to me.

@danielhollas danielhollas linked a pull request Feb 24, 2025 that will close this issue
1 task
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 a pull request may close this issue.

2 participants