Skip to content

[Build] Run pyright against modified files#14

Merged
hughperkins merged 19 commits intomainfrom
hp/pyright
Jun 10, 2025
Merged

[Build] Run pyright against modified files#14
hughperkins merged 19 commits intomainfrom
hp/pyright

Conversation

@hughperkins
Copy link
Copy Markdown
Collaborator

Issue: #

Brief Summary

Run pyright against modified files

  • first runs pybind11-stubgen
  • for detecting modified files, uses an AI generated script, in python/tools/run_modified_files.py

copilot:summary

Walkthrough

copilot:walkthrough


set -ex

python python/tools/run_modified_files.py --include 'python/*.py' -- pyright
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We can have errors in unmodified files due to modifications elsewhere, can't we?
Is it particularly slow to run everywhere? Otherwise, I'd keep things simple and run it everywhere, or would parallelize instead.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Its' super fast. Speed is not an issue. The 1500 errors that pop up when we run it are.

See https://genesis-ai-company.slack.com/archives/C08JT0YHM2A/p1748974351128939 for more context

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does it keep checking files that have been changed previously, therefore have been fixed, but have not been changed again in the current commit/PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

it checks files that have been modified relative to main.

it won't check files that have been modified previously in main, but not since.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

basically, it proects against breaking new files, and will gradually enforce pyright on any files, as we modify them (and once a file is fixed, the only way to unfix it would be to modify it again, I think?)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think that you can cause typing errors in that file if you modify a dependency in another file (e.g., a type that it uses that is defined in another file). And once a file is fixed, I think we should keep running pyright on it.

An alternative may be to maintain a list of exclusions in the pyright configuration from which we'd gradually remove files, as done in gs-core.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

right now, that would be a list of like 1500 files... Baby steps. We don't even know we can fix even a single file yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with Charles. Not a huge fan of the approach of only checking modified files. But maybe we should remove all this confusing / obsfucated logic once Taichi repo is finally clean.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

For sure yeah. I just can't do everything all at once :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

that would be a list of like 1500 files...

We can also add full directory exclusions, if that is more manageable.

Comment on lines +34 to +36
pip3 install scikit-build

pip install pyright pybind11-stubgen
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we configure this in a pyproject.toml with a dev dependency group so that everyone can use it to set up local dev as well?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I dont think we can use pyproject.toml, though perhaps you know how to configure taichi so we can? Would love to migraate to pyproject.toml

But yes, should probalby add to requirements_dev.txt. I'll do that

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added to reuiqrements_dev.txt

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hmmm, I guess since I'm running a full build anyway, not much excuse for not removing it from the pyright script. I'll try doing that.

Comment thread python/tools/run_modified_files.py Outdated
import fnmatch


def get_changed_files(include_pattern: str) -> List[str]:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I have mixed feelings about adding this complexity. If it's too slow to run everywhere, couldn't we scope actions (e.g., by directory) and trigger only on directory changes. This would seem a more robust and transparent solution to me.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

See other thread.

steps:
# looks like we need to first build the dll...
# easiest way to do that is to build the wheel
# at some point, we should probably have a separate wheel building thing
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I did this for Jiminy in the past. You can find how to do this here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yeah, lets have that as a separate pr please. One step at a time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No problem!

build:
runs-on: ubuntu-22.04
steps:
# looks like we need to first build the dll...
Copy link
Copy Markdown
Contributor

@duburcqa duburcqa Jun 9, 2025

Choose a reason for hiding this comment

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

Actually you should build the DLL, then generate the stubs to get typing working. This is basically what you did actually, and yes it is absolutely necessary. Note that you should bundle the stubs with the wheel for the end-user (actually a developper using taichi) to have proper typing experience out-of-the-box. I did this before for Jiminy here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok, so the pyi bit should be part of the wheel build? Sounds good. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes!

Comment thread tests/python/test_tools_run_modified_files_integration.py Outdated
Comment thread tests/python/test_tools_run_modified_files_integration.py Outdated
Copy link
Copy Markdown

@CharlesMasson CharlesMasson left a comment

Choose a reason for hiding this comment

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

As discussed in comments, I don't find that way we currently run pyright very practical, but if we want to address that in a subsequent PR, we can move forward.

@hughperkins hughperkins enabled auto-merge (squash) June 10, 2025 17:14
@hughperkins hughperkins merged commit 63e537a into main Jun 10, 2025
17 checks passed
@hughperkins hughperkins deleted the hp/pyright branch June 10, 2025 22:00
hughperkins added a commit that referenced this pull request Apr 26, 2026
Convert MatrixField.to_torch / to_numpy to thin calls into
_interop.get_zerocopy_torch / get_zerocopy_numpy.

Adds a single _matrix_view_shape() helper that returns (expected_shape,
as_vector); both to_torch and to_numpy now go through it instead of
duplicating the n / m / keep_dims branching (closes review #13, #14).

Same wins as the ScalarField migration:
- _zerocopy_cache as cached_property (closes review #17)
- automatic registration with pyquadrants.cache_holders (closes #18)
- copy=True now zerocopies + clones (closes #15, #16, #21)
- to_numpy(copy=False) goes through numpy.from_dlpack directly, no torch
  round-trip (closes #6)
- Apple Metal double-sync via the centralised helpers (closes #1, #22, #23)

The redundant reshape after zerocopy stays (DLPack returns the field's flat
n-d shape; numpy/torch users expect the matrix dims appended) but it's now
in one place per method instead of two.
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.

3 participants