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

uv-export behavior #39

Open
daturkel opened this issue Jan 14, 2025 · 3 comments
Open

uv-export behavior #39

daturkel opened this issue Jan 14, 2025 · 3 comments

Comments

@daturkel
Copy link

Hi, thanks for this helpful pre-commit plugin.

One thing I noticed was that uv-export is marked as "passed" even if it generates a brand new requirements file. I'd expect it to only pass if it creates no new changes, and to fail (and force me to add requirements then recommit) otherwise. Is there a way to enable that behavior?

Thanks!
Dan

@danielhollas
Copy link

"passed" even if it generates a brand new requirements file.

Do you have that file checked in your repo? I think pre-commit should automatically detect if a file under version control was changed during hook execution and fail the hook accordingly. But I might be wrong...

@daturkel
Copy link
Author

It's possible that when I first set up pre-commit I didn't have requirements.txt checked in. I do now and just tried to reproduce the issue and could not reproduce it—committing a change to the lock file triggered the uv export action, which "failed" and thus blocked the commit (adding an unstaged change to requirements for me to stage).

In that case, this may have been user error!

@ohiliazov
Copy link

ohiliazov commented Feb 8, 2025

I would expect the uv-export hook to run and fail if there are changes in uv.lock or .pre-commit-config.yaml, and when requirements.txt is modified:

uv-export..................................................................Failed
- hook id: uv-export
- files were modified by this hook

Initially, I thought the hook always passed incorrectly, but it turned out that requirements.txt wasn’t checked in—my mistake! However, I noticed that adding the --no-hashes argument makes the hook stop working entirely and always pass, regardless of changes.

I really love uv—it’s an amazing tool! I’d be super grateful for any insights or suggestions regarding this behavior. Thank you!

Update: To answer my own message, this is the correct way to set up the hook to use --no-hashes:

  - repo: https://github.com/astral-sh/uv-pre-commit
    rev: 0.5.29
    hooks:
      - id: uv-lock
      - id: uv-export
        args:
          - --no-hashes
          - --output-file=requirements.txt

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

3 participants