3

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

Sanskar Jethi
  • 544
  • 5
  • 17

3 Answers3

5

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"',
    ]
)
wim
  • 338,267
  • 99
  • 616
  • 750
0

As wim indicated in their comment, https://peps.python.org/pep-0508/ specifies how to write constraints on package requirements.

In addition to restricting the package to a range of versions, you can restrict package installations based on various markers, such as sys_platform for the OS, separated from your other requirements with a semicolon.

I haven't tested this with pyproject.toml, but the following works in setup.cfg:

[options]
install_requires =
    uvloop ; sys_platform != "win32"
shader
  • 801
  • 1
  • 7
  • 25
-1

If you don't want to install on windows, specify like this:

# assuming you're using poetry
uvloop = {version = "^0.16.0", markers = 'sys_platform != "win32"'}
kigawas
  • 1,153
  • 14
  • 27