important-psychiatrist-39230
10/03/2022, 11:08 PMpsycopg2
which have significant burdens for local development (especially on some OSes) while realizing possible wins when the code is deployed.
What I've done in my poetry projects is to have pg8000
setup as a dev dependency and then have a specific extras section for a production only dependency after flagging it as optional.
[tool.poetry.dependencies]
psycopg2 = { version = "~2.9.3", optional = true }
[tool.poetry.dev-dependencies]
pg8000 = "~1.29.1"
[tool.poetry.extras]
production-only = ["psycopg2"]
This has reduced the burden on our developers while maintaining api compatibility and the code is largely unaware of the distinction. (I only have one place where I have to do multiple imports and that's for a try/except block).
From what I can see there's not an obvious way to do a similar dichotomy when using pants and this is a considerable regression that I'm having to weigh. Is there anything I'm missing? Could a plugin enable such a pattern?happy-kitchen-89482
10/04/2022, 12:48 AMhappy-kitchen-89482
10/04/2022, 12:49 AMbitter-ability-32190
10/04/2022, 12:49 AMpex_binary
+ the "prod" depbitter-ability-32190
10/04/2022, 12:49 AMhappy-kitchen-89482
10/04/2022, 12:49 AMhappy-kitchen-89482
10/04/2022, 12:50 AMbitter-ability-32190
10/04/2022, 12:51 AMYou can use the prefixis relevant (and is also relevant for your below thread aboutto transitively exclude a dependency, meaning that even if a target's dependencies include the bad dependency, the final result will not include the value.!!
rich
.
Macros are here: https://www.pantsbuild.org/docs/macrosimportant-psychiatrist-39230
10/04/2022, 3:01 AMenough-analyst-54434
10/04/2022, 3:29 AMpex_binary
targets, for example, that depended on `python_sources`targets that had the dev-only deps baked in.enough-analyst-54434
10/04/2022, 3:35 AMhappy-kitchen-89482
10/04/2022, 5:32 AMenough-analyst-54434
10/04/2022, 5:35 AMhappy-kitchen-89482
10/04/2022, 5:35 AMpg8000
and to use psycopg2 you import from psycopg2
? What does the code that disambiguates the two look like?enough-analyst-54434
10/04/2022, 5:35 AMenough-analyst-54434
10/04/2022, 5:37 AMhappy-kitchen-89482
10/04/2022, 5:38 AMenough-analyst-54434
10/04/2022, 5:39 AMhappy-kitchen-89482
10/04/2022, 5:39 AMhappy-kitchen-89482
10/04/2022, 5:39 AMenough-analyst-54434
10/04/2022, 5:39 AMenough-analyst-54434
10/04/2022, 5:41 AM./pants enter-role dev
and have that stick until you clear the role or enter a new one. Then role aware goals do the right things.enough-analyst-54434
10/04/2022, 5:42 AMhappy-kitchen-89482
10/04/2022, 5:42 AMhappy-kitchen-89482
10/04/2022, 5:42 AMhappy-kitchen-89482
10/04/2022, 5:43 AMenough-analyst-54434
10/04/2022, 5:43 AMenough-analyst-54434
10/04/2022, 5:43 AMenough-analyst-54434
10/04/2022, 5:43 AMbitter-ability-32190
10/04/2022, 10:28 AMimportant-psychiatrist-39230
10/04/2022, 3:58 PMimportant-psychiatrist-39230
10/04/2022, 3:59 PMimportant-psychiatrist-39230
10/04/2022, 4:00 PMtry:
from psycopg2 import NotSupportedError as EngineNotSupportedError
except ImportError:
from pg8000 import NotSupportedError as EngineNotSupportedError
important-psychiatrist-39230
10/04/2022, 4:03 PMpants run
I've been doign that against a pex_binary target
pex_binary(
entry_point="swizzler.main:service",
restartable=True,
)
typing out pants run services/swizzler
is a lot better than me having to type pants run services/swizzler/src/swizzler/main:service
or whatever the source target would beimportant-psychiatrist-39230
10/04/2022, 4:04 PMimportant-psychiatrist-39230
10/04/2022, 4:04 PMpoe dev
and then in prod I'd do poe start
important-psychiatrist-39230
10/04/2022, 4:06 PMdev_dependencies
argument when defining your pex_binary
Then I could do pants dev services/swizzler
?important-psychiatrist-39230
10/04/2022, 4:18 PMlibrary
target that you could do that configuring on and then the pex_binary would read it's properties if it depends on that library.happy-kitchen-89482
10/04/2022, 5:49 PM./pants run services/swizzler/main.py
(or whatever the entry point file is) and that is a lot faster than running the target (running the target is the same as building the pex and then running it)happy-kitchen-89482
10/04/2022, 5:50 PMhappy-kitchen-89482
10/04/2022, 5:50 PMbitter-ability-32190
10/04/2022, 5:51 PMimportant-psychiatrist-39230
10/04/2022, 8:05 PMpants run services/swizzler/src/swizzler/main.py:app
no dev on my side is going to think that's great 😕enough-analyst-54434
10/04/2022, 8:22 PM