nice-park-16693
03/31/2023, 4:48 PM❯ pants test ::
......
Engine traceback:
in `test` goal
in Run Pytest - pants/plugins/mypkg/something/else/foo_test.py:tests
in Resolve transitive targets
in Resolve direct dependencies of target - pants/plugins/mypkg/something/else/foo_test.py:tests
in Inferring Python dependencies by analyzing source
UnownedDependencyError: Pants cannot infer owners for the following imports in the target pants/plugins/mypkg/something/else/foo_test.py:tests:
* mypkg.something.else.foo.FooClass (line: 11)
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/v2.15/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
My code looks something like this:
# pants/plugins/mypkg/BUILD
pants_requirements(name="pants", resolve="pants-plugins")
# pants/plugins/mypkg/something/else/BUILD
python_sources(resolve="pants-plugins")
python_tests(name="tests", resolve="pants-plugins")
# pants/plugins/mypkg/something/else/foo.py
does something interesting
# pants/plugins/mypkg/something/else/foo_test.py
tests something interesting
# pants/plugins/mypkg/something/else/register.py
registers my plugin
# pants.toml
[GLOBAL]
pants_version = "2.15.0"
pythonpath = ["%(buildroot)s/pants/plugins"]
backend_packages.add = [
...
"pants.backend.plugin_development",
"mypkg.something.else", # my plugin gives me a new backend
]
nice-park-16693
04/03/2023, 9:15 AMpants.toml
, I had:
[source]
root_patterns = [
"pants/plugins",
...
]
and my file locations for the plugins were things like:
pants/plugins/mypkg/pants/plugins/myplugin/register.py
The nested pants/plugins
directory (part of my package naming) understandably causes issues for pants. Changing my root_patterns
to "/pants/plugins"
(with a leading /
) resolves the issues I was seeing.