<#17872 Python module mapping with transient depen...
# github-notifications
q
#17872 Python module mapping with transient dependency New discussion created by Jackevansevo I've been having some difficultly with pants trying to infer the owners of an import. Specifically where the library name is nonstandard and transitive. A reproduce-able example is available in a standalone repository Specifically I'm using a library called
ariadne
, which I've placed in a poetry
pyproject.toml
file:
Copy code
[tool.poetry.dependencies]
python = "^3.8"
ariadne = "^0.13.0"
Which itself depends on a library called
graphql-core
, the
graphql-core
package exposes
graphql
(see here) My
BUILD
file (after running
./pants tailor ::
) looks as follows:
Copy code
poetry_requirements(
    name="poetry0",
)

python_sources(
    name="root",
)
I'm running a simple script
Copy code
import ariadne
from graphql.execution import MiddlewareManager

if __name__ == "__main__":
    print("hello world", MiddlewareManager, ariadne)
Running the script gives me:
Copy code
./pants --no-pantsd run main.py

12:03:59.01 [WARN] Pants cannot infer owners for the following imports in the target //main.py:root:

  * graphql.execution.MiddlewareManager (line: 2)

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.14/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
hello world <class 'graphql.execution.middleware.MiddlewareManager'> <module 'ariadne' from '/Users/jack/.cache/pants/named_caches/pex_root/venvs/6be7984cc4edd737a5b88632bd3ebc4b81ac2419/1600009f0b703061a214410767329cc05f8fd614/lib/python3.9/site-packages/ariadne/__init__.py'>
Given
graphql-core
is a dependency of
ariadne
how do I inform
pants
about this dependency? I've unsuccessfully tried the following:
Copy code
poetry_requirements(
    name="poetry0",
    module_mapping={
        "graphql-core": ['graphql'],
    },
)
Would I have to explicitly add this dependency to my
pyproject.toml
or is there another mechanism to map module names I'm no aware of? pantsbuild/pants