-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Improve how we run pyright in CI #10258
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
@erictraut, are the CI failures expected here? Maybe I misunderstood the solution you were recommending for typeshed in microsoft/pyright#5109. It looks as though pyright isn't picking up the PEP-561 packages installed into a virtual environment when the virtual environment is specified via |
I don't see an obvious problem with this. The import failures are related to |
typeshed/.github/workflows/tests.yml Lines 153 to 160 in 7df870f
We know they are installed successfully because of the output of typeshed/.github/workflows/tests.yml Lines 161 to 164 in 7df870f
https://github.com/python/typeshed/actions/runs/5169903229/jobs/9312454028?pr=10258 |
It doesn't look like the
https://github.com/python/typeshed/actions/runs/5170067467/jobs/9312734659?pr=10258 From my reading of the docs for pyright-action, it doesn't look like there's any way of switching off the |
This reverts commit 3745cd8.
I forgot that the action is using Hmm, it looks correct to me. I've never used the I've tried the steps locally (creating a local |
I've barely rolled out of bed so haven't looked at this yet (besides typing on my phone), but I'm guessing the problem here are the quotes. The action executes pyright directly (via fork) and so the quotes showing up in the GHA log are on fact being passed literally in argv, whereas normally a shell would have stripped them and escaped their contents. If you drop the quotes, I'm betting it will work. That being said, I will go and add in the shorthand for the new flags, and also fix quotes in args; my intended behavior of extra-args was that quotes worked. |
Thanks @jakebailey, looks like dropping the quotes fixed the issue with pyright not picking up the packages installed into the virtual environment! However, looks like we still have a different error where pyright is now not recognising typeshed's VERSIONS file. @erictraut, could the Line 3 in 7df870f
|
Just to note it, this is also probably a bug in the action; the intent is that when a flag is set that prevents JSON from working (e.g. |
The VERSIONS file was recently updated to set the max version of some stubs to Python 3.11. This includes It looks like the CI script is running If I'm correct in my analysis and these pyright errors are legitimate, then why didn't we see these errors prior to this PR? I have a theory that I'm still investigating. The original import resolution logic in pyright was very precise. If the import couldn't be found using any of the configured paths, it results in an import resolution error. A couple of years ago, we (actually, Jake) added code to make this a bit more forgiving. Pyright now attempts to find a reasonable import by walking up the directory structure starting from the location of the file that's doing the import and stopping at the root of the project. It appears that this "fuzzy import" mechanism was masking these import resolution errors prior to this PR. I haven't yet determined why this behavior changed when using |
This is nearly correct, but there's an important detail that's missing from this analysis. Take the first error in CI here, for example:
Pyright is correctly identifying here (from our VERSIONS file) that EDIT: we might be saying the same thing in different ways here, re-reading your message. The behaviour we get without using |
The How does this work with other type checkers? |
Yeah, makes sense, and I realised shortly after posting my previous message that this was probably what you were saying. What's interesting, as you say, is that without the
We run mypy via a custom Python script in CI. The script parses our VERSIONS file to determine which files to pass to mypy. Here's some of the logic that goes into that: Lines 168 to 190 in 7df870f
I don't really want to move to a |
I can't remember off the top of my head how we handle the VERSIONS file when running pytype in CI, but I think we do it in a similar way to mypy. We don't run pyre in CI at the moment (and never have in the past). |
@AlexWaygood, pyright already has some auto-exclude logic for typical projects. For example, it auto-excludes |
…at are not "in scope" for the current python version are auto-excluded from the project. This applies only if the `typeshedPath` is set to `.`. This addresses python/typeshed#10258.
Thanks very much @erictraut, that's really helpful! I'll mark this PR as deferred until the next pyright release. |
I'm nearly done updating pyright-action to fix the previous bugs, but one thing I might acutally suggest if you're using virtual environments is to just activate the environment in a previous step and let PATH control what pyright does. That's closer to what people working on typeshed will be doing and means you don't have to pass the option for each pyright invocation. Something like: - run: echo "$PWD/.venv/bin" >> $GITHUB_PATH Stuck right at the top would "activate" the venv for the further steps (and you could eliminate a whole bunch of This is somewhat similar to what I suggest for poetry: jakebailey/pyright-action#10 (comment) |
@jakebailey nice, I would never have thought of that -- works great, thank you very much! |
I just published pyright action 1.6.0, which should fix the Of course, there's no need for any of those fixes in this PR anymore. 😄 |
@erictraut, it doesn't look like microsoft/pyright@2c97966 is having any impact on which files are excluded in our CI here. (We're now using the latest version of pyright in the CI for this PR.) Is there something else I need to do to take advantage of the new feature? |
You shouldn't need to do anything else to take advantage of the new feature. The fact that When I run pyright manually on typeshed (the latest main branch), I don't see the errors that are produced in CI. I'm using the same command that the github action is emitting, so I'd expect the behavior to be the same.
My only theory is that it has to do with a difference in platforms. I'm running on a Mac, and the CI script is probably running on Linux. That means the CI script is using a case-sensitive file system. But I've reviewed my code, and I think I'm using normalized paths in my implementation, so case sensitivity shouldn't matter. If you happen to be using Linux locally, perhaps you could try running the above command-line and see what results you get. |
I tried on Linux, checking out this PR:
(And a lot more errors)
|
I found the source of the problem. It was a bug in the feature I added. A subtle initialization ordering issue caused pyright to use the VERSIONS file in the packaged copy of typeshed rather than the typeshed stubs specified in I convinced myself that the new feature was working fine in my local testing because I had a Python 3.11 venv selected, and it was able to resolve these deprecated modules ( Apologies for the mix-up. I have a fix ready to check in, and I've done a bunch of testing to confirm that it works. I'll commit the change later today. The pylance team is actively working on their weekly sync with pyright, and I don't want to get in their way. |
Here's the pyright commit that addresses this. It will be included in next week's pyright release (1.1.314). |
Thanks @erictraut and @jakebailey for your help here! Looks like everything's green on this PR with the latest pyright version. |
Use the new
--pythonpath
command-line argument, instead of the--venv-path
command-line argument in combination with thevenv
configuration setting. This is simpler, and also means that we don't need to hardcode the name of our virtual environment in ourpyrightconfig.json
files (which annoyed @Akuli in #10121). The--venv-path
argument is also deprecated.