Search code examples
dependency-managementpython-poetry

How do I specify that I want a dependency on all but a specific platform with Poetry?


I have a project which depends on wxPython. Previously, we've been using Hatch to manage the project, but we are now considering switching to Poetry for various reasons. With Hatch, it was possible to specify that a dependency should be installed on all platforms but a specific one like so:

wxpython>=4.2.1 ; platform_system != 'Linux'

Looking through the Poetry docs, I can't find anything similar. All I can find is how to restrict a dependency to a specific platform, but here I want to do all but one specific platform.


Solution

  • Environment markers can be used to accomplish this. Here is what a more or less equivalent line that's compatible with Poetry could look like:

    wxpython = { version = "4.2.1", markers = "sys_platform != 'linux'", source = "pypi" }