Hi all. We're trying to setup Pants in our compani...
# general
p
Hi all. We're trying to setup Pants in our companies extremely convoluted Python repo. So the repo currently consists of different micro-services each with its own PyProject.toml file (we are using Poetry) and then there is a main PyProject.toml file outside of the services folder which we use in our CI pipeline (running tests etc). For testing, instead of each service containing its own tests, all tests are located in a tests folder and are supposed to use the main PyProject.toml file. The issue is that when I try running ./pants test <path-to-test-file> it is unable to correctly identify a single root and gives an error like:
Copy code
The target lib/modules/serviceA/controller.py imports `sqlalchemy.text`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['services/serviceA:poetry#SQLAlchemy', 'services/serviceB:poetry#SQLAlchemy', 'services/serviceC:poetry#SQLAlchemy'].
This is actually just a warning but ultimately it leads to an error like:
Copy code
ModuleNotFoundError: No module named 'flask_sqlalchemy'
I think somehow I need to specify that all tests need to use only the main PyProject.toml file but I'm not sure how I do that. Currently I'm setting my source as:
Copy code
[source]
marker_filenames = ["pyproject.toml"]
Please advise on how I can go about solving this problem. Thanks in advance.
e
Have a look here: https://www.pantsbuild.org/docs/python-third-party-dependencies#multiple-lockfiles The keyword you're missing in your search is "resolve" and Pants supports multiple resolves. It sounds like you have 1 resolve per project plus 1 extra one for tests. You need to explicitly configure Pants to know about each resolve I think. I don't know much more about resolves than that, but folks who do should be along on Monday with more details if you're still stuck then.
👍🏽 1
👍 1
p
Thanks a lot. I think this is exactly what I need.
b
As an alternative to multiple resolves, we handled a similar migration from many-poetries to pants by having one resolve, and only importing the 'main' pyproject.toml that had all the required dependencies (via path dependencies to each subproject, and/or copying their requirements) and have progressively moved to not use/remove the project pyproject.tomls at all (as we switched all required functionality into pants). We don't have pants load dependencies from each of the subproject's
pyproject.toml
: there is only one `poetry_requirements`/`python_requirements` target in our whole repo. This does force pants to be using everything the same versions of all dependencies across all projects, though.
🙌 1