-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Fix missing venv path when running Pyright #19430
Conversation
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.
Welcome to the Pantsbuild Community. This looks like your first PR here.
We are so grateful for each an every contribution, big or small.
So thanks for spending your time and energy making this project better.
If you haven't gotten a reply in a week, feel free to gently comment "bump" to ping the project admins.
If you haven't already, feel free to come say hi on Slack.
If you have questions, or just want to surface this PR, check out the #development
channel.
(If you want to check it out without logging in, check out our Linen mirror)
Thanks again for this PR, and we'll be on the lookout for your next one 😄!
e737f9d
to
cf246c0
Compare
cf246c0
to
405b8a6
Compare
Thanks for tackling this @krishnan-chandra! I do think John's suggestion over in #19368 (comment) is better than mine though - less finicky and brittle. That solution involves running a no-op process in the venv. You do something like:
|
d78f1d5
to
c5fbf49
Compare
Thanks @krishnan-chandra. Can you confirm that the problem reproduces without this latest patch and does not reproduce with it? |
For testing, I was thinking about how best to create a test for this case. I am able to reproduce the original issue (and also clearly show that the fix works) by deleting the cache between test runs: rm -rf ~/.cache/pants/named_caches/pex_root This seems quite intense for a test though, so I'm wondering if there is a way to delete the path of the requirements venv between test runs. I couldn't figure out how to do that using the test harnesses in https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/python/typecheck/pyright/rules_integration_test.py, but I'm sure I'm missing something on the internals there. |
Tests are tricky for this because they involve "regular" Pants running a sandboxed Pants (or parts of one). That inner Pants is the one whose named cache you'd want to blow away. It doesn't live in ~/.cache/pants. In the pyright tests, the relevant testing object is the rule_runner (see here for example). In that set_options() call you can set the option for the named caches location to some temp dir you create, and then nuke that. |
Thanks! I'll take a look at the examples and try to add those tests. In the meantime, are there any other changes that you would like me to make / is there anything else you need before approving the PR? |
No, I think this looks good! And thanks for confirming that it has the desired effect. Just that test (and verifying that the test fails without the patch) and we're good! |
c5fbf49
to
5728c37
Compare
I added a test - it passes, but I can't get it to fail if I cherry-pick the test onto a branch without the fix. Is there anything obvious that I'm doing wrong there / does the named caches dir need to be passed somewhere else? |
8011f30
to
20ce3e9
Compare
src/python/pants/backend/python/typecheck/pyright/rules_integration_test.py
Outdated
Show resolved
Hide resolved
20ce3e9
to
01c0d38
Compare
I've pushed up what I think should be a better test - but again, I can't get this one to fail consistently even though I can definitely get Pants to fail when running against my own monorepo. |
Hmm, this would be absolutely key. If the test doesn't fail without the change then it is not really testing what we think it is... |
Definitely agreed there - I'm not super familiar with Pants internals so it's been a bit challenging to chase down the source of the problem. I'll keep pushing on it. In the meantime, if someone more familiar with the Pyright integration has suggestions, I am all ears :) |
I'll take a look when I get a moment. |
OK, so one thing complicating this test is that it's too simple: Specifically, it doesn't actually require any venv to be present in order to pass. And so it passes regardless of the presence of absence of a venv (the --venvPath not existing is just a pyright warning, not an error). So the next step here is to make the test sufficiently complex to actually require some 3rdparty dep to be present in order to pass. |
Hi @krishnan-chandra , have you had a chance to look at this test again? |
ede8857
to
77d0509
Compare
I did revisit it, and I tried to add some third-party imports to force the venv to materialize. One thing I couldn't quite work out is where to look for the output. Here is my test output: Command: ./pants --keep-sandboxes=always test src/python/pants/backend/python/typecheck/pyright/rules_integration_test.py -- -k test_passing_cache_clear Output:
This makes sense as I largely got the implementation from
And the following command does not yield anything:
|
The Does that make sense? Is that helpful? |
…e cache" This reverts commit 20ce3e9.
dd669af
to
6e5d78d
Compare
Thanks for your diligence here @krishnan-chandra ! |
This fix should address #19368 - I've tested it out locally on my own repo and haven't been able to reproduce the issue so far.
Relevant Slack threads:
https://pantsbuild.slack.com/archives/C046T6T9U/p1687366638498259
https://pantsbuild.slack.com/archives/C046T6T9U/p1688507180323199?thread_ts=1688480012.892699&cid=C046T6T9U
This is my first PR to Pants, so please let me know if there are any steps I forgot!