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

[internal] Leverage PyO3 type conversions #13618

Merged
merged 3 commits into from
Nov 15, 2021

Conversation

Eric-Arellano
Copy link
Contributor

We can let PyO3 write the type conversion code for us, as explained in https://pyo3.rs/v0.15.0/conversions/tables.html. This makes our code simpler to read and also allows us to use py.allow_threads(||) in more places.

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano
Copy link
Contributor Author

Thank you again @mejrs and @davidhewitt, this type of change is awesome!

@@ -110,7 +110,7 @@ def capture_snapshots(
scheduler: PyScheduler,
session: PySession,
path_globs_and_root_tuple_wrapper: _PathGlobsAndRootCollection,
) -> tuple[PySnapshot, ...]: ...
) -> list[PySnapshot]: ...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that PyO3 returns Vec<>, I figured we can lean into it - not worth the eager type conversion to tuple.

.0
.core
.executor
.enter(|| py.allow_threads(|| py_scheduler.0.metrics(&py_session.0)))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The allow_threads is new.

.workunit_store()
.encode_observations()
.map_err(PyException::new_err)?;
let observations = py.allow_threads(|| {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

allow_threads is new

core
.executor
.block_on(future::try_join_all(snapshot_futures))
let snapshot_futures = path_globs_and_roots
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was moved into allow_threads. Same with processing the result

@Eric-Arellano Eric-Arellano enabled auto-merge (squash) November 15, 2021 01:48
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano merged commit 3c9a7ff into pantsbuild:main Nov 15, 2021
@Eric-Arellano Eric-Arellano deleted the dont-store branch November 15, 2021 02:37
tdyas pushed a commit to tdyas/pants that referenced this pull request Nov 15, 2021
Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Great change! Thanks.

@stuhood stuhood mentioned this pull request Nov 18, 2021
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