Skip to content

warning: VIRTUAL_ENV ignored #36

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

Closed
danielhollas opened this issue Jan 10, 2025 · 8 comments · Fixed by astral-sh/uv#11251 or #43
Closed

warning: VIRTUAL_ENV ignored #36

danielhollas opened this issue Jan 10, 2025 · 8 comments · Fixed by astral-sh/uv#11251 or #43

Comments

@danielhollas
Copy link
Contributor

When running uv 0.5.16 using this pre-commit hook I get the following warning:

warning: `VIRTUAL_ENV=/home/hollas/.cache/pre-commit/repovyb9qrvk/py_env-python3.12` does not match the project environment path `.venv` and will be ignored

I understand why the warning is there, but I suspect it could be quite confusing for new users. It would be great if this warning could be somehow disabled when uv is run within pre-commit virtual environment.

@danielhollas
Copy link
Contributor Author

Maybe something like a hidden uv option --ignore-activated-virtualenv that would get rid of the warning?

@zanieb
Copy link
Member

zanieb commented Feb 1, 2025

How is the uv command being invoked? Can the VIRTUAL_ENV variable just be cleared?

@danielhollas
Copy link
Contributor Author

How is the uv command being invoked? Can the VIRTUAL_ENV variable just be cleared?

I don't think so. :-( If I just naively modify the hook entry here

entry: uv lock

to

 entry: VIRTUAL_ENV= uv lock 

pre-commit will fail even before the actual invocation since it does a bunch of cmd normalization that assumes that the first entry argument is an executable. e.g.

https://github.com/pre-commit/pre-commit/blob/aba1ce04e70162ca48b12f809ceffb253b788fe6/pre_commit/xargs.py#L150

@zanieb
Copy link
Member

zanieb commented Feb 3, 2025

I think you'd use env -u (pre-commit/pre-commit#2367 (comment))

❯ export VIRTUAL_ENV=foo
❯ /bin/bash -c 'echo "$VIRTUAL_ENV"'
foo
❯ env -u VIRTUAL_ENV /bin/bash -c 'echo "$VIRTUAL_ENV"'

@danielhollas
Copy link
Contributor Author

Ah, sorry, should have searched better. But as the last commenter on that issue mentions, is that portable?

I briefly went through theany related iasues on the pre-commit issue tracker and haven't seen a workaround that would be portable (but my knowledge of how Windows does things is minimal so I might be wrong)

@zanieb
Copy link
Member

zanieb commented Feb 3, 2025

I'm not sure, but that seems like a pre-commit issue? Not letting people set environment variables in a cross-platform way seems problematic and I'm hesitant to go out of my way to account for that.

I suppose if I land astral-sh/uv#11189 I can add a --no-active option which would silence the warning.

@danielhollas
Copy link
Contributor Author

danielhollas commented Feb 4, 2025 via email

@danielhollas
Copy link
Contributor Author

@zanieb I think this issue should be re-opened until #43 get's merged and released (I guess until next uv version is cut)

zanieb pushed a commit that referenced this issue Feb 24, 2025
Add `--no-active` option to `uv-sync` to ignore the pre-commit virtual
env. Closes #36.

As far as I can tell, the other hooks don't support/need this option,
but would like that confirmed.

### Testing

To test this PR, add the following to `.pre-commit-config.yaml`

```
  - repo: https://github.com/danielhollas/uv-pre-commit    
    rev: fc377b7
    hooks:    
    - id: uv-sync                                                                                                                         
      verbose: true
      stages: [pre-commit]
```

and run

```console
pre-commit run -a uv-sync
```

No warning should be printed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants