glamorous-river-64734
12/01/2020, 9:47 PMrequirements.txt
files each included in the BUILD
file with the python_requirements()
code. One is called api
and the other is called qa
. Here are their structures:
src/api/
├── BUILD
├── Dockerfile
├── app
│ ├── __init__.py
│ └── api.py
├── main.py
└── requirements.txt
and:
src/processors/qa/
├── BUILD
├── Dockerfile
├── app
│ ├── __init__.py
│ ├── api.py
│ └── qa.py
├── main.py
└── requirements.txt
The qa
one loads all of its requirements from pip great in both mypy runs and repl, but the api
one completely misses installing them.
Both have the same BUILD
file with just the name swapped out:
python_requirements()
python_library(
name="<name here>",
sources=["**/*.py"],
interpreter_constraints=[">=3.6"],
)
Anyone have any ideas why one loads packages and the other doesn’t? Or a handy command I can use to help debug?happy-kitchen-89482
12/01/2020, 9:52 PMhappy-kitchen-89482
12/01/2020, 9:53 PMglamorous-river-64734
12/01/2020, 9:53 PMhappy-kitchen-89482
12/01/2020, 9:53 PMhappy-kitchen-89482
12/01/2020, 9:54 PMrequirements.txt
files?happy-kitchen-89482
12/01/2020, 9:54 PMglamorous-river-64734
12/01/2020, 9:54 PMapi
alot?hundreds-father-404
12/01/2020, 9:55 PM./pants dependencies path/to/app.py
. You should see all first party files + third party requirements used directly in app.py. Are you seeing none, or only missing some?happy-kitchen-89482
12/01/2020, 9:55 PMglamorous-river-64734
12/01/2020, 9:56 PMcelery[redis, librabbitmq]==4.4.0
fastapi==0.49.0
uvicorn==0.11.7
pydantic==1.4
qa/requirements:
transformers[torch]==3.3.1
pytest
fastapi
glamorous-river-64734
12/01/2020, 9:56 PMhappy-kitchen-89482
12/01/2020, 9:56 PMhundreds-father-404
12/01/2020, 9:57 PMhappy-kitchen-89482
12/01/2020, 9:58 PMapi
package's python_library()
, e.g., dependencies=['src/api:celery', 'src/api:uvicorn']
just to see if that helps.glamorous-river-64734
12/01/2020, 9:58 PMsrc/api/app/__init__.py:../api
src/api/app/api.py:../api
src/api/main.py
src/api:uvicorn
src/redthread/redthread/__init__.py:../redthread
src/redthread/redthread/models.py:../redthread
qa dependencies:
src/api:uvicorn
src/processors/qa/app/__init__.py:../qa
src/processors/qa/app/api.py:../qa
src/processors/qa/app/qa.py:../qa
src/processors/qa/main.py
src/processors/qa:transformers
src/redthread/redthread/__init__.py:../redthread
src/redthread/redthread/models.py:../redthread
happy-kitchen-89482
12/01/2020, 9:59 PMqa
depends on src/api:uvicorn
glamorous-river-64734
12/01/2020, 9:59 PMapi
root did find the uvicornglamorous-river-64734
12/01/2020, 10:00 PMhundreds-father-404
12/01/2020, 10:01 PMglamorous-river-64734
12/01/2020, 10:01 PMglamorous-river-64734
12/01/2020, 10:09 PMapi/BUILD
file to:
python_requirements()
python_library(
name="api",
sources=["**/*.py"],
interpreter_constraints=[">=3.6"],
dependencies=[
"src/api:celery",
"src/api:fastapi",
"src/api:uvicorn",
"src/api:pydantic"
]
)
Which leads to a successful repl environment (all libraries importable with the correct versions as laid out in api/requirements.txt
) 🎉glamorous-river-64734
12/01/2020, 10:10 PMhundreds-father-404
12/01/2020, 10:47 PMfastapi
won’t show up with dep inference. You’re defining the requirement in two different places, and Pants’s dependency inference can’t disambiguate which of the two you want to use. It assumes you don’t want both. For fastapi, you’d either need to consolidate around one requirements file, or a shared req file for common deps, or use explicit dependencies for that one
I’m not sure why celery, pydantic, and uvicorn fail for you. I’d love to figure out what’s happening
▶ ./pants dependencies src/api/main.py
src/api:celery
src/api:pydantic
src/api:uvicorn
▶ ./pants dependencies src/processors/qa/main.py
src/processors/qa:pytest
src/processors/qa:transformers
glamorous-river-64734
12/02/2020, 4:03 AMhundreds-father-404
12/02/2020, 5:18 AMhundreds-father-404
12/02/2020, 4:32 PMfastapi
won’t work with dep inference due to two targets for it existing, as noted above
* Both src/api/main.py
and src/processors/qa/main.py
fail to detect imports of the module app.api
. This is expected. Your project has two modules called app.api: src/processors/qa/app/api.py
and src/api/app/api.py
. You correctly set up the “source roots” to be src/processors/qa
and src/api
, which means those paths get stripped from the module name. But now, you have two different files with the same name, and Pants can’t figure out which you want to use. To fix, you’d either need explicit dependencies
, or to change how your imports and source roots are structured - would it be feasible to import processors.qa.app.api
and api.app.api
, rather than app.api
? You’d set the source root pattern to /src
. We recommend the latter, as it gives you namespacing so that there’s zero ambiguity what refers to what
* Inference of celery
is working for ./pants dependencies src/api/app/api.py
* I don’t see any imports of Pydantic, so Pants can’t infer it’s used. Do you expect to import it?
* You import starlette
in src/api/app/api.py
, but it’s not used. Did you mean to include starlette in the requirements.txt?glamorous-river-64734
12/03/2020, 8:47 PMhundreds-father-404
12/17/2020, 9:15 PMnutritious-hair-72580
03/16/2021, 2:21 PMrequirements.txt
with overlapping requirements.
It would be great if this was documented (esp. the gotcha around "it assumes you don't want both")
Happy to raise a ticket if that's appropriate.
It sounds like moving to a single requirements file will work for us in the long run.happy-kitchen-89482
03/16/2021, 2:26 PMrequirements.txt
, although of necessity that will require annotating your targets to say which "universe" of requirements they are allowed to dip into. So if you are able to have a universal set of mutually compatible requirements for your repo, that will always make your life easier, even if we do support more complicated arrangements.happy-kitchen-89482
03/16/2021, 2:28 PMnutritious-hair-72580
03/16/2021, 2:32 PMhappy-kitchen-89482
03/16/2021, 2:35 PMhappy-kitchen-89482
03/16/2021, 11:45 PM-r common-requirements.txt
nutritious-hair-72580
03/17/2021, 10:36 AMhappy-kitchen-89482
03/17/2021, 5:42 PMhappy-kitchen-89482
03/17/2021, 5:42 PMhappy-kitchen-89482
03/17/2021, 5:43 PMrequirements.txt
.happy-kitchen-89482
03/17/2021, 5:43 PMnutritious-hair-72580
03/17/2021, 6:30 PM