Repository navigation
Platform-specific overrides for environment variables #2024
SummaryHow do I set environment variables based on the platform? DetailsI am building a package which contains a Python C extension which is dynamically linked to a library. In the wheel-building process, there's no issue as the wheel-repair functionality bundles the library into the wheel and modifies the The issue comes from editable installs, whereby the library path environment variable needs to be set. I was expecting something like this would work: [tool.hatch.envs.default.overrides]
platform.linux.env-vars = { LD_LIBRARY_PATH = "{root}/src/pact_ffi:{env:LD_LIBRARY_PATH}" }
platform.macos.env-vars = { DYLD_LIBRARY_PATH = "{root}/src/pact_ffi:{env:DYLD_LIBRARY_PATH}" }
platform.windows.env-vars = { PATH = "{root}/src/pact_ffi;{env:PATH}" }but this produces the following error: Work-aroundThe only workaround at the moment is to set all these variables for all platforms. While that works, it seems suboptimal, especially since Windows' |
Replies: 1 comment
|
[tool.hatch.envs.default.overrides]
platform.linux.env-vars = "LD_LIBRARY_PATH={root}/src/pact_ffi{;}{env:LD_LIBRARY_PATH:}"
platform.macos.env-vars = "DYLD_LIBRARY_PATH={root}/src/pact_ffi{;}{env:DYLD_LIBRARY_PATH:}"
platform.windows.env-vars = "PATH={root}/src/pact_ffi{;}{env:PATH:}"Array form if you want: platform.linux.env-vars = [
{ key = "LD_LIBRARY_PATH", value = "{root}/src/pact_ffi{;}{env:LD_LIBRARY_PATH:}" },
]Docs: https://hatch.pypa.io/latest/config/environment/advanced/#types Pitfall: bare |
env-varsoverrides takeKEY=VALUEstrings (or an array of those), not a TOML table. That is why the map form raisedmust be a string or an array.Array form if you want:
Docs: https://hatch.pypa.io/latest/config/environment/advanced/#types
Pitfall: bare
{env:LD_LIBRARY_PATH}errors if unset. …