- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 652
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
Extract Python dependencies in an intrinsic #18854
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll handle the Django plugin and the dep inference helper union in a separate PR
@@ -109,11 +109,11 @@ def test_normal_imports(rule_runner: RuleRunner) -> None: | |||
ignored1 as alias1, # pants: no-infer-dep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to this file will be most important, as they are potential changes in behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
As mentioned in Slack, I'm fine with beginning to do more of this in-process. As you mentioned, there is nothing stopping someone from writing a native wheel 3rdparty plugin to do the same thing, but this eases distribution/release.
0024d65
to
df2b964
Compare
Whew! Nice comments. Got through 'em |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can only review the Rust code (rather than the big picture of how it fits into Pants). I've also not looked through all the 'resolved' comments, so I might've been repeating some things.
My general comment is: nice!
Broadly speaking though, it feels like there's quite a lot of unwrap
ing. I've commented on some specific ones, but there's also a lot of name.named_child(...).unwrap()
or equivalent. I'd be nervous about this making dep inference fragile to invalid code, or syntax changes, or other unexpected problems, and bringing down the whole pantsd when they fail.
Some alternatives, depending on the situation:
- propagate errors with
?
etc. .expect("<short explanation>")
orunwrap_or_else(|| panic!("foo {some_value} bar"))
to at least give more context- ignore silently or with some logging (e.g. if the code is invalid, just skip over)
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct ParsedPythonDependencies { | ||
pub imports: HashMap<String, (u64, bool)>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using HashMap<&str, ...>
here may not work directly because from .. import abc
might be referring to a module that is never named literally.
I guess this could be std::borrow::Cow<'file_contents, str>
to allow &str
references into the raw file contents when available, but still support dynamically constructed String
s too.
(But, also, not important for this PR.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the build.rs
script is fixed to avoid needing to commit the generated code, I'll shipit. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Oh wait, we still need to port or fallback for the Django deo inference plugin 😅 |
Given this is behind an opt-in flag, maybe that could be follow up: people who are using Django inference can not opt-in for now? |
I made sure we resort to the old behavior if the Django framework is enabled. So we can port in a follow up |
There's a been a few new crates added recently (#18854, #19958), but we didn't update `[workspace].members` and `[workspace].default-members` in `src/rust/engine/Cargo.toml` to match. In addition, the older `protos` and `grpc_util` weren't listed. This syncs up the lists. The lists of `members` and `default-members` now exactly matches, except for `fs/brfs` as commented. They also match the `Cargo.toml`s that exist on disk.
This PR does two things:
dep_inference
. A module inside is dedicated to Python, and leveragestree-sitter
andtree-sitter-python
to parse Parse dependencies.tree-sitter
was chosen because it supports Py2/3, supports other languages, and also is syntax-error-resistant.TImings
Helper script:
Timings follows.
./dirty_files.sh
runs test worst case scenario ( touch every copyright header). I'm on a 64 core machine, so I run as if we only had 8 cores.Findings:
Worst case (completely cold cache)
Best Case (hot cache, but no daemon)