Search code examples
pythonwindowspython-poetrypackage-management

How do I ensure that a dependency only gets installed on Windows with Poetry?


I'm developing a Python application using Poetry as project management tool, and I have a dependency which I only want to install on Windows. PEP 425 says the following on the matter:

The platform tag is simply distutils.util.get_platform() with all hyphens - and periods . replaced with underscore _.

If I run distutils.util.get_platform() on a 64-bit Windows host, I get this:

>>> import distutils
distutils.utils.get_platform()
'win-amd64'

So far so good. I now have the platform tag for 64-bit Windows. The issue is that I don't want to specifically specify 64-bit Windows but rather Windows in general as the dependency should be installed on all variants of Windows. For Linux, this tag is just "linux", and macOS is "darwin", but I can't seem to find any examples for Windows.

What value should I pass to $ poetry add --platform to ensure that a dependency only gets installed on Windows? Or, is there a better way to do it?


Solution

  • After trying different possibilities, the one thing that worked was this:

    $ poetry add --platform=win32
    

    I don't know why it wants win32 specifically, but this makes Poetry install the dependency even on 64-bit Windows, while also not attempting to install it on Linux.