1

I have a library mylib that depends on OpenCV. There are 2 distributions of OpenCV, opencv-python and opencv-python-headless. Either one works for mylib but only one can be installed, so for downstream code that uses OpenCV it is important for consumers to be able to choose which they are getting.

This can be done using 2 optional-dependencies. But then users cannot just install mylib, they must install mylib[opencv-python] or mylib[opencv-python-headless]. The semantics are poor.

[project]
dependencies = []

[project.optional-dependencies]
opencv-python = ["opencv-python"]
opencv-python-headless = ["opencv-python-headless"]

Is there a way I can have a default and say, only install if the extra is not specified? This has good semantics and would better guide naive consumers to what they should use.

[project]
dependencies = [
  "opencv-python-headless; 'opencv-gui' not in extras",
]

[project.optional-dependencies]
opencv-gui = ["opencv-python"]

Although the specification's CFG is very dense, after reviewing environment markers, I have some hope:

Marker Python equivalent Sample values
extra An error except when defined by the context interpreting the specification. test

Does that mean that this idea is left to build backends? I'm using hatchling, but am open to using anything that supports this.

0