fierce-fall-70380
02/04/2025, 3:12 AMfierce-fall-70380
02/04/2025, 3:13 AM--- a/pants.toml
+++ b/pants.toml
@@ -19,7 +19,7 @@ repo_id = "3B1D361B-E9F1-49A8-B761-03DCC41FD58E"
[source]
# The Python source root is the repo root. See <https://www.pantsbuild.org/docs/source-roots>.
-root_patterns = ["/"]
+root_patterns = ["/", "helloworld/"]
ACAM-M-RWLH:example-python acam$ pants dependents helloworld/greet/greeting.py
23:07:27.68 [INFO] Initializing scheduler...
23:07:27.70 [INFO] Initializing Nailgun pool for 20 processes...
23:07:29.65 [INFO] Scheduler initialized.
23:07:29.74 [WARN] Pants cannot infer owners for the following imports in the target helloworld/greet/greeting_test.py:tests:
* helloworld.greet.greeting.Greeter (line: 4)fierce-fall-70380
02/04/2025, 3:14 AM"/" still exists as a source root, that the dependency inference should still be able to find helloworld.greet.greeting.Greeter ? Changing the ambiguity_resolution setting doesn't make a difference either...fierce-fall-70380
02/04/2025, 3:36 AMโโโ foo
โ โโโ app.py
โ โโโ test
โ โโโ base.py
โ โโโ test_foo
โ โโโ test_foo.py
โโโ bar
โ โโโ app.py
โ โโโ test
โ โโโ base.py
โ โโโ test_bar
โ โโโ test_bar.py
โโโ baz
โ โโโ app.py
โ โโโ test
โ โโโ base.py
โ โโโ test_baz
โ โโโ test_baz.py
Some of the test_{*}.py scripts do imports like from base ... while others do from test.base .... Therefore, I'm trying to set it up so e.g. both foo/ and foo/test/ are valid source roots. This seems to confuse Pants -- I get errors like:
23:31:43.93 [WARN] Pants cannot infer owners for the following imports in the target foo/test/test_foo/test_foo.py:tests:
* test.base.Foobar (line: 4)
If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/2.25/docs/using-pants/troubleshooting-common-issues#import-errors-and-missing-dependencies> for common problems.fierce-fall-70380
02/04/2025, 3:36 AMsquare-psychiatrist-19087
02/04/2025, 2:07 PMtest_{*}.py scripts do imports like from base ... while others do from test.base .... Therefore, I'm trying to set it up so e.g. both foo/ and foo/test/ are valid source roots.
IMHO it's a very confusing practice and you should fix your imports to be consistent and use single source rootelegant-florist-94385
02/04/2025, 5:05 PMfierce-fall-70380
02/04/2025, 5:06 PMelegant-florist-94385
02/04/2025, 5:06 PMfierce-fall-70380
02/04/2025, 5:06 PMfierce-fall-70380
02/04/2025, 5:06 PMelegant-florist-94385
02/04/2025, 5:09 PMsrc/python/foo and src/python/bar, then you have source.root_patterns=["/src/python"] and you can do from foo import util or `from bar.base import main_func`etc. Maybe that's related to what you're seeing?fierce-fall-70380
02/04/2025, 5:10 PMmarker_filenames and root_patterns.fierce-fall-70380
02/04/2025, 5:11 PM