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

CI / tox: Update and speed up pyright #36443

Closed
wants to merge 12 commits into from

Conversation

mkoeppe
Copy link
Contributor

@mkoeppe mkoeppe commented Oct 10, 2023

We bring tox -e pyright and the pyright invocation that is part of the CI "Build & Test" back in sync:

  • They are now both pinned to today's latest pyright version
  • node.js is provisioned via https://pypi.org/project/pyright/ and never accepts a preinstalled node version
  • node.js is configured to provide sufficient heap size. This reduces the runtime dramatically as pyright no longer has to fight with the garbage collector and eliminates spurious out of memory conditions.
  • Both run on the entire source tree.

This is done so that even if the output of pyright may be incomprehensible to developers, at least there are no gratuitous differences between what's shown on CI and what is shown locally.

Also done as part of this ticket: A limited effort to get rid of some warnings, just enough to establish that it would be premature to create problem matchers that annotate these warnings in the source code. Most of the warnings are meaningless and distracting noise because pyright is struggling with too many aspects of the Sage source code: lazy imports, methods in ParentMethods, ElementMethods, etc.

📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

⌛ Dependencies

Copy link
Collaborator

@kwankyu kwankyu left a comment

Choose a reason for hiding this comment

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

Working fine.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Oct 11, 2023

Thank you!

Copy link
Contributor

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

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

Sadly it doesn't really work. It now runs the check only on a subset of the files (the instructions in the tox file are obsolete).
Moreover, I don't think its a good idea to install a node package via an additional tour over tox + pip. I also would like to keep some version constraint to prevent that this test fails due some new releases. If you want to keep it up to date, add a simple rennovate config https://docs.renovatebot.com/modules/manager/regex/

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Oct 11, 2023

It now runs the check only on a subset of the files (the instructions in the tox file are obsolete).

Well, that this had fallen out of sync was a bug. Do we really want to run it on all files?

(Edit: Changed in 8bf3bcb)

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Oct 11, 2023

I also would like to keep some version constraint to prevent that this test fails due some new releases.

Please suggest a version constraint

(Edit: I've pinned it to what's current as of today in 81e1afa)

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Oct 11, 2023

I don't think its a good idea to install a node package via an additional tour over tox + pip.

It's better because we're reusing what is already configured, so it can't fall out of sync as it had.

@tobiasdiez
Copy link
Contributor

I don't think its a good idea to install a node package via an additional tour over tox + pip.

It's better because we're reusing what is already configured, so it can't fall out of sync as it had.

Well, the tox version is still not working.

If you want to simplify the setup, you can use https://github.com/marketplace/actions/run-pyright. Also has the advantage that it registers annotation matchers.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Oct 13, 2023

the tox version is still not working

Thanks, I see that.

@mkoeppe mkoeppe force-pushed the tox_pyright_update branch from 81e1afa to ccf8a20 Compare October 22, 2023 02:22
@@ -22,4 +22,7 @@
"reportUndefinedVariable": "warning",
"reportOptionalOperand": "warning",
"reportMissingImports": "warning",
"reportPrivateImportUsage": "warning",
// Suppress because it flags our standard pattern @staticmethod __classcall__(cls, ...)
Copy link
Contributor

Choose a reason for hiding this comment

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

comments in json files are sadly not possible. the common workaround I've seen is to add them as another field, i.e. reportSelfClsParameterName.comment (not sure if it works here or if pyright complains)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a Microsoft extension ("JSONC"), see https://github.com/microsoft/node-jsonc-parser

@@ -103,20 +103,9 @@ jobs:
MAKE: make -j2 --output-sync=recurse
SAGE_NUM_THREADS: 2

- name: Set up node to install pyright
Copy link
Contributor

@tobiasdiez tobiasdiez Oct 22, 2023

Choose a reason for hiding this comment

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

I still think that this way of installing pyright is better. I also don't get the consistency argument (as it comes down to calling pyright without any other arguments). Tox just installs (and calls) pyright in a very convoluted way. And this is exemplified by the memory issues. What to you think about using https://github.com/jakebailey/pyright-action? Also has the advantage of adding problem matchers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I [...] don't get the consistency argument (as it comes down to calling pyright without any other arguments).

It comes down to not only that, but also to running the same pyright version, on the same Node version.

Tox just installs (and calls) pyright in a very convoluted way. And this is exemplified by the memory issues.

There's nothing convoluted about it. This is how one installs and runs pyright using Python infrastructure without having to rely on a system installation of Node.

And there is nothing mysterious about "memory issues", it is a default heap size of 2 GB, which is too small for our purpose. Here I configure it explicitly so that proper function does not depend on an externally set configuration.

What to you think about using https://github.com/jakebailey/pyright-action? Also has the advantage of adding problem matchers

I looked at it, as you had mentioned it before. As I explained in the PR description, adding Check Warnings for pyright's complaints just makes no sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's nothing convoluted about it. This is how one installs and runs pyright using Python infrastructure without having to rely on a system installation of Node.

Yes, but we have a node environment here, so no need to use the Python infrastructure. I'm aware that its more convenient for the average Python dev to run it that way locally. But that doesn't mean the ci needs to do that way, and in fact the node-setup action is the githuby way of installing node in a github workflow. So please use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in fact the node-setup action is the githuby way of installing node in a github workflow.

No, there's not only "one way" of doing things right.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can also easily disable comments for the pyright action if that's your concern. I would say we should run it twice: once without commenting for all functions, and a second time with comments on type-annotated functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Beyond the scope of this PR.

@@ -22,4 +22,7 @@
"reportUndefinedVariable": "warning",
"reportOptionalOperand": "warning",
"reportMissingImports": "warning",
"reportPrivateImportUsage": "warning",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not fixing the single instance of this error (by properly importing the offending method)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't see the immediate fix, and it did not seem worth it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't remember the names, but sage is importing x from y, and y is importing x from z (without reexporting it). So just import x from z.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't even have such a thing as a convention of what reexports should look like in Sage. So warning instead of error is quite appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here y is an external library. So sage was accessing a non-public api. I think this is a good catch and should be fixed properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't plan to work on this import. If you want to fix stuff, just open a PR.

@@ -0,0 +1,3 @@
# This type-stub file helps pyright understand the decorator @lazy_attribute.

lazy_attribute = property
Copy link
Contributor

Choose a reason for hiding this comment

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

But this is not the correct type, right? lazy_attribute just happens to have the same typing as property (at the moment). In this case, just replace it by https://github.com/python/typeshed/blob/b9640005eb586afdbe0a57bac2b88a7a12465069/stdlib/builtins.pyi#L1237-L1254

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done in 05e34ef

@github-actions
Copy link

Documentation preview for this PR (built with commit 05e34ef; changes) is ready! 🎉

@mkoeppe mkoeppe changed the title CI / tox: Update pyright CI / tox: Update and speed up pyright Oct 22, 2023
@mkoeppe mkoeppe requested a review from tobiasdiez October 23, 2023 13:34
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 28, 2023
…nbound' warnings

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->
Just a single commit split out from sagemath#36443 to facilitate review.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36516
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 29, 2023
…nbound' warnings

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->
Just a single commit split out from sagemath#36443 to facilitate review.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36516
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 29, 2023
…nbound' warnings

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->
Just a single commit split out from sagemath#36443 to facilitate review.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36516
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
@mkoeppe
Copy link
Contributor Author

mkoeppe commented Oct 31, 2023

Closing as it has been replaced by #36515

@mkoeppe mkoeppe closed this Oct 31, 2023
vbraun pushed a commit to vbraun/sage that referenced this pull request Nov 1, 2023
…yright

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

Split out from sagemath#36443 to facilitate review.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36517
Reported by: Matthias Köppe
Reviewer(s): Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Nov 2, 2023
…yright

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

Split out from sagemath#36443 to facilitate review.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36517
Reported by: Matthias Köppe
Reviewer(s): Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Nov 5, 2023
…yright

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

Split out from sagemath#36443 to facilitate review.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36517
Reported by: Matthias Köppe
Reviewer(s): Tobias Diez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants