Search code examples
pythonrustpypipyo3

How to configure os specific dependencies in a pyproject.toml file [Maturin]


I have a rust and python project that I am building using Maturin(https://github.com/PyO3/maturin). It says that it requires a pyproject.toml file for the python dependencies.

I have a dependency of uvloop, which is not supported on windows and arm devices. I have added the code that conditionally imports these packages. However, I do not know how to conditionally install these packages. Right now, these packages are getting installed by default on every OS.

Here is the pyproject.toml file.

[project]
name = "robyn"
dependencies = [
  "watchdog>=2.1.3,<3",
  "uvloop>=0.16.0,<0.16.1",
  "multiprocess>=0.70.12.2,<0.70.12.3"
]

And the github link, jic anyone is interested: https://github.com/sansyrox/robyn/pull/94/files#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711R21


Solution

  • The syntax for environment markers is specified in PEP 508 – Dependency specification for Python Software Packages. I will show below how to exclude uvloop as a dependency on Windows platform with a marker for platform.system() which returns:

    • "Linux" on Linux
    • "Darwin" on macOS
    • "Windows" on Windows

    Using pyproject.toml:

    [project]
    dependencies = [
        'uvloop ; platform_system != "Windows"',
    ]
    

    Using setup.cfg:

    [options]
    install_requires =
        uvloop ; platform_system != "Windows"
    

    Using setup.py:

    setup(
        install_requires=[
            'uvloop ; platform_system != "Windows"',
        ]
    )