We have already included httpx in requirements.txt...
# general
d
We have already included httpx in requirements.txt. How to make sure that required modules are available while running pants?
w
Can you provide some code, your pants.toml, requirements, etc? I use FastAPI and pants everywhere, and haven't run into any problems off-handedly (but I may have also solved them years ago and forgotten)
You're always able to manually add dependencies to your targets via
dependencies
but often there might be a
module_mapping
that you might need to perform
d
Can you give more details or example how to do module_mapping for dependencies?
d
Python_tests( dependencies=["src/python/test-app:reqs#httpx"], ) I have added above entry in BUILD file for tests target.. But still the same error, did I miss other config?
w
Without any code or config, it's hard to say. Do you
import httpx
anywhere? If so, it should be picked up automatically
r
Httpx is an extra for fastAPI. Use "fastAPI[all]" as your dependency in requirements.txt
w
Yep, but it'll automatically be picked up by the dep graph if it's imported. Trying to see if it's an explicit or implicit usecase, and how it's added to requirements.txt
r
This is implicit in fastapi though. I don't think OP is importing it explictly. I have had this issue in the past. OP can clarify
w
Gotcha, I tend to end up using something like this and it’s automatically picked up
from httpx import AsyncClient
d
Added python required sw lock file in pants.toml and httpx error is resolved. Facing another issue that , app.py need a folder called "fetch" which contains html files. How to tell pants to pick this folder while running pants test?
w
What have you tried?
d
Included below entries in pants.toml under python Module. "enable_resolves = true" resolves = { python-default = " python-default.lock" } [pytest] install_from_resolve = "python-default"
w
sounds like you want to pass those html files in https://www.pantsbuild.org/2.20/docs/using-pants/assets-and-archives
d
Next issue is how to tell pants to take non python code??
w
I'd recommend reading through the documentation: https://www.pantsbuild.org/2.20/docs/using-pants/key-concepts
1
d
I have gone through this material. In my code, I'm trying to mount 'fetch' folder which is not found during pants test. from fastapi.staticfiles import StaticFiles app.mount('/', StaticFiles(directory='fetch', html=True), name='fetch') At this part pants is failing to find fetch directory