Is there some way to handle python extras nicely? ...
# general
l
Is there some way to handle python extras nicely? For example we have
strawberry-graphql = {version = "^0.185.1", extra=["asgi"]}
, but when importing
strawberry.asgi
packages from the extra group are missing and I need to add eg.
python_sources(dependencies=["//:reqs#starlette"])
r
You might have to do some module mapping In this case it should look something like
Copy code
poetry_requirements(
    name="poetry",
    module_mapping={"asgi": ["strawberry.asgi"]},
)
l
Thanks, this does fix the python_sources part, but I still need the explicit starlette requriement in requirements file
r
is starlette a transitive dependency? or you do provide it as an explicit requirement in your pyprojec.toml/requirements.txt?
Either you need to add it to some extra (if that's the case) or you add it your requirements.txt/pyproject.toml
l
starlette is part of strawberry.asgi https://github.com/strawberry-graphql/strawberry/blob/main/pyproject.toml#L120 and i get the error when i do import
strawberrya.asgi
as that pulls it in
b
Hm, I thought optional dependencies enabled by extras should work… given they don’t seem to, you can tell pants that any use of
strawberry
also needs
starlette
by adding that dependency relationship in the
poetry_requirements
target generator: something like
overrides={“strawberry-graphql”: {“dependencies”: [“//:reqs#starlette”]}}
This is same process as adding a
setuptools
dependency later in the mapping link @refined-addition-53644 provided above
l
Awesome. Overrides does work, although its a bit annoying extra (extra) step 🙂 Also are you guys open to adding more default overrides? I have 2 setup now that I could open a PR to mainstream
Copy code
module_mapping={
        "UnleashClient": ["UnleashClient"],
        "django-postgres-extra": ["psqlextra"]
    },
👍 1
b