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

stubtest_third_party.py: Allow running non-listed platforms locally #9173

Merged
merged 9 commits into from
Nov 15, 2022

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Nov 12, 2022

Here is my proposed solution for: #8923 (comment)

This should keep the same behaviour on the CI (although with a more accurate skip message when no platform are listed).

While still allowing to run stubtest locally.

I am not immediatly skipping if platforms are listed but is ran on an "unsupported" platform locally, because of the following edge case:
Say a stub is the same on darwin and linux, but different on windows. You don't want to run the CI for all three, so you may specify platforms = ["linux", "win32"]. But it's still fine to run locally on macos.
image

In this solution, the behaviour is affected by the "CI" environment variable: https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables . But it could be something else like a CLI flag passed by the github action.

@Avasam Avasam changed the title Allow running non-listed platforms locally Stubtest: Allow running non-listed platforms locally Nov 12, 2022
@AlexWaygood
Copy link
Member

Hmm, I'm not a massive fan of the script magically doing something different in CI due to the presence of an environment variable. I like the idea of a CLI flag more.

@Avasam
Copy link
Collaborator Author

Avasam commented Nov 12, 2022

Understandable, I figured that might be the case.

Btw, failure should be fixed by #9176

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea.

Let's say you work on a module that has several supported platforms like psutil. And you want to run several tests locally: for win32, linux, and macos.

Right now there's no way to do it.

With mypy / stubtest you can pass --platform=X as a CLI argument.
Why won't we have the same thing here?

So, if no --platform is passed: we just skip unmatching platforms.
If it is, we use whatever is passed (with a warning that the results might not be accurate).

@AlexWaygood
Copy link
Member

With mypy / stubtest you can pass --platform=X as a CLI argument.
Why won't we have the same thing here?

It doesn't make much sense to pass --platform to stubtest. The whole point of stubtest is that it compares the stub to what's happening at runtime. And stubtest has no idea what the runtime would be like on linux if it's running on Windows.

I have a few nits to sort out (I'll review soon), but I broadly like the design of this PR now.

@sobolevn
Copy link
Member

Yes, it does not make much sense. This is why I've added this part:

If it is, we use whatever is passed (with a warning that the results might not be accurate).

But, it is sometimes better than not being able to run stubtest at all.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I like the design of this PR, as I said. I agree that the least surprising behaviour is if python tests/stubtest_third_party.py foo tests the stubs for foo locally on whatever system you're running on. That's the behaviour we had prior to #8923, and it's the behaviour we should go back to; it's the CI run that should require additional command-line flags.

I think the logic at line 37 can be simplified a bit, and the messages printed can be less verbose -- have offered a suggestion there. I'm also not keen on the name of the flag -- --ci-run isn't very descriptive about what the flag actually does. Maybe --supported-stubs-only?

@@ -167,6 +181,7 @@ def main() -> NoReturn:
parser.add_argument("-v", "--verbose", action="store_true", help="verbose output")
parser.add_argument("--num-shards", type=int, default=1)
parser.add_argument("--shard-index", type=int, default=0)
parser.add_argument("--ci-run", action="store_true")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a short description of what the flag does here, using the help= keyword argument

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on the flag name. It's a principle I need to remind myself more often:
"Don't make code that's environment-specific. Instead give options and let the environment decide".
So instead of having a "ci" flag, I should have a flag that describes this option.

I went with "specified" instead of "supported". For the same reason as the multi-platform PR by sobolevn: It's not necessarily unsupported. It's just not tested (it could simply be redundant).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Specified" is a great choice!

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice — thank you!

@AlexWaygood AlexWaygood changed the title Stubtest: Allow running non-listed platforms locally stubtest_third_party.py: Allow running non-listed platforms locally Nov 15, 2022
@AlexWaygood AlexWaygood merged commit 72d1597 into python:main Nov 15, 2022
@Avasam Avasam deleted the run-non-listed-stubtest-locally branch November 15, 2022 01:53
@Avasam Avasam mentioned this pull request Aug 16, 2023
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

Successfully merging this pull request may close these issues.

4 participants