nice-lock-2651
11/20/2024, 4:12 PMpsycopg = {extras = ["binary", "pool"], version = "^3.2.3"}
. This works great when I run the app, both when using pants run ...
and using the venv provided by pants export
. However, most of our tests now fail because it doesn't seem to have the psycopg-pool package. I have absolutely no clue how this can happen.
This is the BUILD.pants in the test folder:
python_tests(
name="tests",
resolve="cell-manager",
dependencies=[
":data",
"src/applications/cell_manager:deps",
"src/applications/cell_manager/service:django_settings"
]
)
resources(
name="data",
sources=["data/*"],
)
and this is the BUILD.pants file that creates ``src/applications/cell_manager:dep`
# Copyright 2022 Airborne Composites Automation.
poetry_requirements(
name="cell_manager_requirements",
resolve="cell-manager",
module_mapping={
"django-storages": ["storages"],
"django-cors-headers": ["corsheaders"],
"opencv-python-headless": ["cv2"],
"pytest-lazy-fixture": ["pytest_lazyfixture"],
"django-json-widget": ["django_json_widget"],
"django-reverse-admin" : ["django_reverse_admin"],
"django-test-migrations" : ["django_test_migrations"],
"django-unicorn" : ["django_unicorn"]
},
)
python_sources(
name="deps",
resolve="cell-manager",
dependencies=[
":cell_manager_requirements",
"./static",
"./logs",
"./templates",
"./locale",
"./config:config",
"./service",
"./service:django_settings",
],
)
pex_binary(
name="manage",
resolve="cell-manager",
entry_point="manage.py",
dependencies=[
":deps",
],
restartable=True,
)
pex_binary(
name="uvicorn",
resolve="cell-manager",
entry_point="uvicorn",
dependencies=[
":deps",
],
)
pex_binary(
name="celery-worker",
resolve="cell-manager",
entry_point="celery",
dependencies=["./service:django_settings",]
)
I've tried a few things with the module mapping and and overrides, but can't seem to get it to work. But I guess that might not be needed since it does work for non-test scenario.nice-lock-2651
11/20/2024, 4:16 PMpsycopg-pool
is not listed in the output of pants dependencies src/applications/cell-manager/manage.py
, but the file absolutely has access to itbetter-van-82973
11/20/2024, 4:35 PMpsycopg-pool
as an override dependency of psycopg
inside your poetry_requirements
? Here’s the docs, along with an example of what that looks like from my own BUILD file:
overrides={
"instructor": {
"dependencies": [":poetry#openai", ":poetry#anthropic", ":poetry#cohere"]
},
"logfire": {
"dependencies": [
":poetry#opentelemetry-instrumentation-aiohttp-client",
":poetry#opentelemetry-instrumentation-fastapi",
":poetry#opentelemetry-instrumentation-httpx",
":poetry#opentelemetry-instrumentation-psycopg",
":poetry#opentelemetry-instrumentation-psycopg2",
":poetry#opentelemetry-instrumentation-redis",
":poetry#opentelemetry-instrumentation-sqlalchemy",
]
},
"lancedb": {"dependencies": [":poetry#tantivy"]},
"sqlalchemy": {"dependencies": [":poetry#asyncpg", ":poetry#greenlet"]},
"slack-sdk": {"dependencies": [":poetry#aiohttp"]},
},
This way, you can force the inclusion of psycopg-pool
wherever psycopg
is depended on.better-van-82973
11/20/2024, 4:37 PMpsycopg-pool
package from your poetry_requirements
.nice-lock-2651
11/20/2024, 4:46 PMpoetry_requirements(
name="cell_manager_requirements",
resolve="cell-manager",
module_mapping={
"django-storages": ["storages"],
"django-cors-headers": ["corsheaders"],
"opencv-python-headless": ["cv2"],
"pytest-lazy-fixture": ["pytest_lazyfixture"],
"django-json-widget": ["django_json_widget"],
"django-reverse-admin" : ["django_reverse_admin"],
"django-test-migrations" : ["django_test_migrations"],
"django-unicorn" : ["django_unicorn"]
},
overrides={
"psycopg": {"dependencies": [":cell_manager_requirements#psycopg-pool", ":cell_manager_requirements#psycopg-pool"]}
}
)
I then get the following error:
ValueError: The explicit dependency `src/applications/cell_manager:cell_manager_requirements#psycopg-pool` of the target at `src/applications/cell_manager:cell_manager_requirements#psycopg` does not provide enough address parameters to identify which parametrization of the dependency target should be used.
Target `src/applications/cell_manager:cell_manager_requirements` can be addressed as:
which then lists all my poetry requirements, without the psycopg-pool packagebetter-van-82973
11/20/2024, 4:48 PM"psycopg": {"dependencies": [":cell_manager_requirements#psycopg-pool", ":cell_manager_requirements#psycopg-pool"]}
Why is the psycopg-pool
package included twice here in the dependencies? Additionally, are you using parametrization over multiple resolves / multiple other values?nice-lock-2651
11/20/2024, 4:49 PMnice-lock-2651
11/20/2024, 4:50 PMbetter-van-82973
11/20/2024, 4:51 PMpsycopg-binary
or psycopg-pool
?nice-lock-2651
11/20/2024, 4:52 PMnice-lock-2651
11/20/2024, 4:55 PMpsycopg = {extras = ["binary", "pool"], version = "^3.2.3"}
better-van-82973
11/20/2024, 4:55 PMpsycopg-binary
and psycopg-pool
as explicit dependencies in your pyproject.toml
filenice-lock-2651
11/20/2024, 4:59 PMnice-lock-2651
11/20/2024, 5:00 PMnice-lock-2651
11/20/2024, 5:00 PMnice-lock-2651
11/21/2024, 11:00 AMDjango=^5.1
and when I run the app it uses that version. Also the pants export has django 5.1 in it.
I figured this out by printing pkg_resources.working_set
in one of my tests. With pants test ...
I see django5, while the venv uses django5.1nice-lock-2651
11/21/2024, 11:00 AMnice-lock-2651
11/21/2024, 2:05 PM