proud-dentist-22844
01/31/2024, 12:11 AM[python-infer].use_rust_parser because I was getting a bunch errors I couldn't make sense of.
Now I'm updating to 2.18, so I want to re-enable that. Is there additional debug output I can get from the rust parser? I've got ALOT of error messages like this:
The target st2common/st2common/util/pack.py imports `.`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['contrib/core/__init__.py', 'contrib/examples/lib/__init__.py', 'tools/__init__.py'].
The file is different in each message, but the list of targets that "own" . is the same.
These files do not have any relative imports, so I don't know what it means by the file imports.`` - Any suggestions on how to debug this?proud-dentist-22844
01/31/2024, 1:11 AM.
..
I have string imports enabled, with min dots = 1.
And I found my note about debugging that:
pants python-dump-source-analysis --analysis-flavor=raw_dependency_inference <path(s) to file(s)> | jq '.[].resolved'proud-dentist-22844
01/31/2024, 1:37 AM# pants: no-infer-dep, but the rust parser is still picking up the string.proud-dentist-22844
01/31/2024, 1:44 AM[python-infer].ignored_unowned_imports=[".", ".."] but that is not used in the "ambiguous dependencies" code path.proud-dentist-22844
01/31/2024, 2:13 AM\ char.
https://github.com/pantsbuild/pants/blob/2.18.x/src/rust/engine/dep_inference/src/python/mod.rs#L325-L328proud-dentist-22844
01/31/2024, 2:49 AMbroad-processor-92400
01/31/2024, 11:57 AMbitter-ability-32190
01/31/2024, 12:51 PMbitter-ability-32190
01/31/2024, 12:52 PMproud-dentist-22844
01/31/2024, 5:18 PMbitter-ability-32190
01/31/2024, 5:19 PMbitter-ability-32190
01/31/2024, 5:20 PMproud-dentist-22844
01/31/2024, 5:20 PM. or .. modules, so it is saying the import is ambiguous.bitter-ability-32190
01/31/2024, 5:21 PMproud-dentist-22844
01/31/2024, 5:21 PMbitter-ability-32190
01/31/2024, 5:21 PMproud-dentist-22844
01/31/2024, 5:22 PMbitter-ability-32190
01/31/2024, 5:23 PMbitter-ability-32190
01/31/2024, 5:23 PMproud-dentist-22844
01/31/2024, 5:24 PMbitter-ability-32190
01/31/2024, 5:24 PMproud-dentist-22844
01/31/2024, 5:28 PM.
4 files have the string ..
My asdf.foobar string did not cause a warning.proud-dentist-22844
01/31/2024, 5:31 PM. and .. to the list of unownable modules?proud-dentist-22844
01/31/2024, 5:54 PMDEFAULT_UNOWNED_DEPENDENCIES is not consulted until after the ambiguous dependency warning is raised.
Besides, adding . or .. to it would not help because it is used like this:
elif import_name.split(".")[0] in DEFAULT_UNOWNED_DEPENDENCIES:
I tried adding it to [python-infer].ignored_unowned_imports, but that also did not help, since that doesn’t get checked until a couple rules later in the rule graph (also after the ambiguous dependency warnings).
So, where would such special casing go?bitter-ability-32190
01/31/2024, 6:00 PMbitter-ability-32190
01/31/2024, 6:01 PMproud-dentist-22844
01/31/2024, 6:01 PMasdf.foobar. But pants thinks three modules own .proud-dentist-22844
01/31/2024, 6:02 PM19:38:50.41 [WARN] The target st2client/st2client/commands/action.py imports `.`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['contrib/core/__init__.py', 'contrib/examples/lib/__init__.py', 'tools/__init__.py'].
Please explicitly include the dependency you want in the `dependencies` field of st2client/st2client/commands/action.py, or ignore the ones you do not want by prefixing with `!` or `!!` so that one or no targets are left.
Alternatively, you can remove the ambiguity by deleting/changing some of the targets so that only 1 target owns this module. Refer to <https://www.pantsbuild.org/v2.18/docs/troubleshooting#import-errors-and-missing-dependencies>.bitter-ability-32190
01/31/2024, 6:02 PMproud-dentist-22844
01/31/2024, 6:03 PM. ? Esp in a project that doesn't use relative imports.bitter-ability-32190
01/31/2024, 6:04 PMproud-dentist-22844
01/31/2024, 6:14 PM. are roots, but that’s only 3 of the 36 roots in the repo, so I’m not sure that tells me anything.proud-dentist-22844
01/31/2024, 6:27 PM. and ...
There is an __init__.py file in only 5 of the roots (all empty files). Of the 2 roots that do not “own” ., 1 does not have any other python files, and the other 1 is in a different resolve.
So, source roots that include an __init__.py file and at least one other python file all own ..proud-dentist-22844
01/31/2024, 6:48 PMmodule = module_from_stripped_path(stripped_f)
if set(module) == {"."}:
# Even if a source root has an __init__.py file,
# it should not own "." or ".." or similar.
continueproud-dentist-22844
01/31/2024, 7:02 PM. module is via the string imports.
I'm confident that we should exclude strings like . and .., but I'm not sure if there's ever a reason to look up roots that have python files. So, I still like protecting the string imports as I'm not sure the implications of preventing anything from owning the . module 😕bitter-ability-32190
01/31/2024, 7:33 PMproud-dentist-22844
01/31/2024, 7:33 PM