cool-easter-32542
04/02/2025, 12:26 PMservice1
• service2
They each have their own resolves, so that when service1 updates its version of FastAPI, for example, it doesn't trigger a change in service2.
service1 also contains some shared code that service2 depends on. When trying to set up the dependency directly in Pants, it gives an error:
09:45:37.50 [WARN] Pants cannot infer owners for the following imports in the target service1/file.py:
* dependency 1
* dependency 2
* dependency 3
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.
09:45:37.52 [WARN] The target service2/file.py imports `third party dependency`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['service2#dependency', 'service1#dependency'].
Please explicitly include the dependency you want in the `dependencies` field of service2/file.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/2.25/docs/using-pants/troubleshooting-common-issues#import-errors-and-missing-dependencies>.
I tried to create a python_distribution target for service1 and have service2 depend on that but it resulted in:
Engine traceback:
in `test` goal
NoCompatibleResolveException: The target service2/file.py uses the `resolve` `service2`, but some of its dependencies are not compatible with that resolve:
* src/service1/file.py (service1)
* ....
* ....
All dependencies must work with the same `resolve`. To fix this, either change the `resolve=` field on those dependencies to `service2`, or change the `resolve=` of the target src/service2/file.py. If those dependencies should work with multiple resolves, use the `parametrize` mechanism with the `resolve=` field or manually create multiple targets for the same entity.
For more information, see <https://www.pantsbuild.org/2.25/docs/python/overview/lockfiles#multiple-lockfiles>.
Is there a way to do this? Alternatively, is this just a really bad idea?
pantsbuild/pants