Comments (6)
1 seems like a bug. We'll likely have to find the right tree-sitter incantation for that.
2 and 3 are more of a "quirk" than a bug. However, since they aren't valid dotted module names (as far as I know) I think it's safe to also "fix" this quirk.
from pants.
With #20472, only dotted strings that are made up of valid python identifiers will be be considered as possible imports. So, points 2 and 3 should be resolved in pants 2.20 or the 2.19.1 (once released).
To fix the first issue, someone needs to figure out how to deal with concatenated strings with the tree sitter in the dependency parser.
from pants.
Similar to point 2: the rust parser also causes a warning for every file that has either of these strings, neither of which is a valid python module:
.
..
I get that using pants 2.18.2 with this in pants.toml (from the StackStorm project):
[python-infer]
string_imports = true
string_imports_min_dots = 1 # tools/config_gen.py has import strings with only one dot.
unowned_dependency_behavior = "ignore"
ambiguity_resolution = "by_source_root"
use_rust_parser = true
The old parser (in 2.18.x) explicitly required alphanumeric characters before the dot:
The new rust parser, however, seems to only exclude strings with a whitespace or a \
char (assuming I'm reading this rust code correctly):
pants/src/rust/engine/dep_inference/src/python/mod.rs
Lines 325 to 328 in 3632a66
Can we make the rust parser be more selective on which strings might be dependencies? In particular, a string that only consists of .
chars, or maybe any string that ends in .
should be excluded (as that would also catch points 2 and 3: 'a.b.'
and 'retrying...'
).
Maybe with something like this:
if !text.ends_with(".") && !text.contains(|c: char| c.is_ascii_whitespace() || c == '\\') {
self.string_candidates
.insert(text.to_string(), (range.start_point.row + 1) as u64);
}
Oh. That wouldn't work because the detected strings are used for both imports and assets.
So, the additional logic to exclude irrelevant strings would need to go in the python side of things:
So, maybe:
if python_infer_subsystem.string_imports or python_infer_subsystem.assets:
for string, line in native_result.string_candidates.items():
slash_count = string.count("/")
if (
python_infer_subsystem.string_imports
and not slash_count
and not string.endswith(".")
and string.count(".") >= python_infer_subsystem.string_imports_min_dots
):
imports.setdefault(string, (line, True))
if (
python_infer_subsystem.assets
and slash_count >= python_infer_subsystem.assets_min_slashes
):
assets.add(string)
from pants.
Another point (maybe it should be a separate issue, but I'll put it here for now):
The rust parser does not ignore strings on lines like this, even though I put the no-infer-dep
directive on the line:
"runner_module": "tests.test_runner", # pants: no-infer-dep
Maybe the rust parser should check for the pragma before recording each string, from this:
pants/src/rust/engine/dep_inference/src/python/mod.rs
Lines 322 to 328 in 3632a66
to this:
fn visit_string(&mut self, node: tree_sitter::Node) -> ChildBehavior {
let range = node.range();
let text: &str = self.string_at(range);
if !!text.contains(|c: char| c.is_ascii_whitespace() || c == '\\') && !self.is_pragma_ignored(node) {
self.string_candidates
.insert(text.to_string(), (range.start_point.row + 1) as u64);
}
from pants.
@liudonggalaxy Do you get any warnings or errors for your last two points:
- For the string
BASE_PATH = 'a.b.'
, the Rust parser mistakenly treats it as a dependency, unlike the classic parser.- In
print('retrying...')
, the Rust parser incorrectly interprets it as a dependency, while the classic parser does not.
from pants.
mkdir -p pants_inference
pants --python-infer-no-use-rust-parser peek :: > pants_inference/classic_parser.json
pants --python-infer-use-rust-parser peek :: > pants_inference/rust_parser.json
diff pants_inference/classic_parser.json pants_inference/rust_parser.json
Hello,
I didn't observe any warnings or errors, but the following CircleCI test failed in our environment:
mkdir -p pants_inference
pants --python-infer-no-use-rust-parser peek :: > pants_inference/classic_parser.json
pants --python-infer-use-rust-parser peek :: > pants_inference/rust_parser.json
diff pants_inference/classic_parser.json pants_inference/rust_parser.json
To resolve this issue and ensure the CircleCI job passes, we modified the following source code.
BASE_PATH = 'a.b.'
print('retrying...')
->
BASE_PATH ='.'.join(['a', 'b']) + '.'
print('retrying' + '...')
from pants.
Related Issues (20)
- `peek` documentation example output is outdated/incomplete
- `peek` output for target generators like `python_tests` do not include relevant `goals` HOT 3
- "Making subsystems exportable with their default lockfile" docs render funny
- Project specific env vars from host
- `export` goal `py_hermetic_scripts` option docs have misrendered list
- Plugin upgrade guide does not mention changes in 2.18 or later (e.g. `@rule_helper` removal) HOT 1
- pantsd not invalidating cache when file permission changes
- Consistent option hierarchy
- Add exit-non-zero-on-fix support for fix and fmt goals HOT 10
- Pants package command hangs for helm chart with dependency subcharts of the same name HOT 1
- Show Python tool versions in top-level help text and documentation
- Feature request: Allow disabling file handle limit warning HOT 2
- `__defaults__(all=...)` is a future-compatibility hazard for adding new field HOT 4
- Process 'Extract Pants' execution Python' failed with exit code 2, when running in GH actions HOT 3
- Overrides not working with parametrized default HOT 2
- GitHub-hosted `macos-11` runners are deprecated and will be removed on 2024-06-28
- Pants test using a different module version than it's assigned resolve HOT 3
- Values from `__defaults__` are not treated the same as builtin field defaults.
- Lingering TODO about removing `parent_id` in `interface.rs`
- Regression: env vars no longer being parsed correctly in `pants.toml` as of Pants `2.22.0.dev2` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pants.