What is the suggested resolution when the name of ...
# general
c
What is the suggested resolution when the name of an in-repo plugin conflicts with a package name? I've written an
ariadne
plugin and
jinja2
plugin to infer some dependencies when using these libraries. I'm following Building in-repo plugins with Pants so that I can write tests for my plugins. But if I add the path to my plugins to the
[source]
part of my
pants.toml
, I start seeing errors like the following.
Copy code
The target path/to/first_party.py imports `ariadne.make_executable_schema`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['//:requirements#ariadne', 'pants-plugins/ariadne/__init__.py'].

Please explicitly include the dependency you want in the `dependencies` field of path/to/first_party.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.11/docs/troubleshooting#import-errors-and-missing-dependencies>.
It would be a huge headache to manually do what the error message suggests for every
BUILD
file. One alternative I'm thinking is publishing these in-repo plugins to PyPI, and then referencing them in our codebase, but that has the downside of slowing down the iteration cycle šŸ˜ž
h
can you call your plugin
pants_plugins.ariadne
? What is the file path currently to your
register.py
?
c
Copy code
src/
ā”œā”€ā”€ BUILD
ā”œā”€ā”€ pants.toml
ā”œā”€ā”€ first_party/
ā”‚   ā””ā”€ā”€ ...
ā””ā”€ā”€ pants-plugins/
    ā”œā”€ā”€ ariadne/
    ā”‚   ā”œā”€ā”€ goals/
    ā”‚   ā”‚   ā””ā”€ā”€ ...
    ā”‚   ā”œā”€ā”€ dependency_inference/
    ā”‚   ā”‚   ā””ā”€ā”€ ...
    ā”‚   ā””ā”€ā”€ register.py
    ā””ā”€ā”€ jinja2
        ā”œā”€ā”€ goals/
        ā”‚   ā””ā”€ā”€ ...
        ā”œā”€ā”€ dependency_inference/
        ā”‚   ā””ā”€ā”€ ...
        ā””ā”€ā”€ register.py
Are you suggesting to nest an additional intermediate directory, like
pants-plugins/pants_plugins/ariadne
? If I do that, where does the
register.py
go?
h
yep exactly, but you can call the intermediate directory whatever you'd like
register.py
will be nested. The
backend_package
will become
my_plugins.ariadne
and
my_plugins.jinja2
for example. (You want to make sure you still have
[source].root_patterns
set to
/pants-plugins
for this to work)
c
Something like this? Note that there's nothing inside
pants-plugins
besides a single nested
pants_plugins
directory.
Copy code
src/
ā”œā”€ā”€ ...
ā””ā”€ā”€ pants-plugins/
    ā””ā”€ā”€ pants_plugins/
        ā”œā”€ā”€ ariadne/
        ā”‚   ā”œā”€ā”€ ...
        ā”‚   ā””ā”€ā”€ register.py
        ā””ā”€ā”€ jinja2/
            ā”œā”€ā”€ ...
            ā””ā”€ā”€ register.py
Then, in `pants.toml`:
Copy code
[sources]
root_patterns = [
  ..,
  "pants-plugins",
]
h
yep! Like that. You might need to add
__init__.py
files places also
c
Ah, right. šŸ™‚ Thanks!