Seeing something strange when trying to implement ...
# plugins
Seeing something strange when trying to implement my first plugin. The plugin seems to "work", in that I can use the target it creates in a BUILD file somewhere and it ends up correctly wiring through to existing pants goals (package, publish, and run). However, both the tests I have written alongside my plugin code and the mypy linter fail to run; they both complain about unowned imports in the test code. Does anybody have any suggestions?
Copy code
❯ pants test ::
Engine traceback:
  in `test` goal
  in Run Pytest - pants/plugins/mypkg/something/else/
  in Resolve transitive targets
  in Resolve direct dependencies of target - pants/plugins/mypkg/something/else/
  in Inferring Python dependencies by analyzing source

UnownedDependencyError: Pants cannot infer owners for the following imports in the target pants/plugins/mypkg/something/else/

  * (line: 11)

If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <> for common problems.
My code looks something like this:
Copy code
# pants/plugins/mypkg/BUILD
pants_requirements(name="pants", resolve="pants-plugins")
Copy code
# pants/plugins/mypkg/something/else/BUILD
python_tests(name="tests", resolve="pants-plugins")
Copy code
# pants/plugins/mypkg/something/else/
does something interesting
Copy code
# pants/plugins/mypkg/something/else/
tests something interesting
Copy code
# pants/plugins/mypkg/something/else/
registers my plugin
Copy code
# pants.toml
pants_version = "2.15.0"
pythonpath = ["%(buildroot)s/pants/plugins"]

backend_packages.add = [
  "mypkg.something.else", # my plugin gives me a new backend
this turned out (predictably) to be me being stupid. In
, I had:
Copy code
root_patterns = [
and my file locations for the plugins were things like:
Copy code
The nested
directory (part of my package naming) understandably causes issues for pants. Changing my
(with a leading
) resolves the issues I was seeing.