-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Allow passing a virtual environment to ruff analyze graph
#17743
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
Conversation
Summary -- Fixes #16598 by adding the `--python` flag to `ruff analyze graph`, which adds a `PythonPath` to the `SearchPathSettings` for module resolution. For the [albatross-virtual-workspace] example from the uv repo this updates the output from the initial issue: ```shell > ruff analyze graph packages/albatross { "packages/albatross/check_installed_albatross.py": [ "packages/albatross/src/albatross/__init__.py" ], "packages/albatross/src/albatross/__init__.py": [] } ``` To include both the the workspace `bird_feeder` import _and_ the third-party `tqdm` import in the output: ```shell > myruff analyze graph packages/albatross --python .venv { "packages/albatross/check_installed_albatross.py": [ "packages/albatross/src/albatross/__init__.py" ], "packages/albatross/src/albatross/__init__.py": [ ".venv/lib/python3.12/site-packages/tqdm/__init__.py", "packages/bird-feeder/src/bird_feeder/__init__.py" ] } ``` Note the hash in the uv link! I was temporarily very confused why my local tests were showing an `iniconfig` import instead of `tqdm` until I realized that the example has been updated on the uv main branch, which I had locally. Test Plan -- A new integration test with a stripped down venv based on the `albatross` example. [albatross-virtual-workspace]: https://github.com/astral-sh/uv/tree/aa629c4a54c31d6132ab1655b90dd7542c17d120/scripts/workspaces/albatross-virtual-workspace
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
Can you test what happens if you provide an invalid path?
Ah good idea, I ran into a couple of these while trying to set up the working test. Is this what you expected?
I think that looks pretty reasonable. Something like It's also important that the flag name matches red-knot, which I'm guessing you were also thinking about here! |
I mainly wanted to make sure that ruff doesn't panic (I wasn't sure if there are any unwraps). I assume
You give me too much credit 😅 |
* main: [red-knot] Refactor: no mutability in call APIs (#17788) [red-knot] Fix panic for `tuple[x[y]]` string annotation (#17787) [red-knot] Implicit instance attributes in generic methods (#17769) doc: Add link to `check-typed-exception` from `S110` and `S112` (#17786) Fix module name in ASYNC110, 115, and 116 fixes (#17774) [red-knot] More informative hover-types for assignments (#17762) [syntax-errors] Use consistent message for bad starred expression usage. (#17772) red_knot_server: add auto-completion MVP Allow passing a virtual environment to `ruff analyze graph` (#17743) Bump 0.11.8 (#17766) [`flake8-use-pathlib`] Fix `PTH104`false positive when `rename` is passed a file descriptor (#17712)
Summary
Fixes #16598 by adding the
--python
flag toruff analyze graph
, which adds aPythonPath
to theSearchPathSettings
for module resolution. For the albatross-virtual-workspace example from the uv repo, this updates the output from the initial issue:To include both the the workspace
bird_feeder
import and the third-partytqdm
import in the output:Note the hash in the uv link! I was temporarily very confused why my local tests were showing an
iniconfig
import instead oftqdm
until I realized that the example has been updated on the uv main branch, which I had locally.Test Plan
A new integration test with a stripped down venv based on the
albatross
example.