pyproject.toml setuptools: How can I specify optional scripts (and modules)?
Asked Answered
D

0

7

I have a python project with some modules, scripts and optional dependencies:

[project.optional-dependencies]
extra = [ "tqdm", "antspyx>=0.4.2", "scikit-image", "mpi4py", "scipy" ]

[project.scripts]
reg = "myproject._cmd.reg:main"
conv = "myproject._cmd.conv:main"

[tool.setuptools.packages.find]
where = ["src"]
include = ["myproject*"]

Now I would like the scripts to be installed, only for pip install myproject[extra]. By now, these scripts are installed even for pip install myproject

It would also be nice to be able to split my modules like this. Modules in src/myproject/extra/ should be installed only for pip install myproject[extra]. If pip install myproject is called, only modules in src/myproject/modules/ should be installed.

So, how can I declare optional modules and optional scripts in pyproject.toml?

Diannediannne answered 17/11, 2023 at 12:39 Comment(2)
I'm facing the same problem and I couldn't find a solution that doesn't require a setup.py file. Have you found something in the meantime?Brabant
Got the same issue here. The setuptools doc talks about extra dependencies and redirects to the entry-points spec, but it seems like setuptools yet doesn't implement that feature. As a workaround you could use something like this in the __init__.py of the sub-package needed the dependency: try: import yourExtraPackage except ImportError: raise SystemExit("ERROR MESSAGE FOR THE USER HERE")Boatbill

© 2022 - 2025 — McMap. All rights reserved.