How do I specify optional dependencies with a hyphen or underscore in pyproject.toml?

51 Views Asked by At

I have the following section in my pyproject.toml:

[tool.setuptools.dynamic.optional-dependencies]
some_extra = {file = ["requirements-some-extra.txt"]}

However, when I try to install the package with said extra like so:

pip install -e "./package[some_extra]"

Then I get a warning from pip:

WARNING: package 0.0.1 does not provide the extra 'some-extra'

At the same time, it is also not allowed to use hyphens in the pyproject.toml key. I tried

[tool.setuptools.dynamic.optional-dependencies]
some-extra = {file = ["requirements-some-extra.txt"]}

but the key needs to be a valid python identifier.

What am I doing wrong?

Just a note: When not using a separator symbol, it all works fine, but I feel like it should be possible to use one.

1

There are 1 best solutions below

1
Anderson Bravalheri On

One possibility is that pip is warning about the lack of normalisation in the extras name. This is a relatively recent deployment (in setuptools-years), mandated by PEP 685, and that has not yet been fully implemented in setuptools.

I suspect that a newer version of setuptools will automatically do the normalisation, however, as you mentioned, setuptools validation of pyproject.toml has not yet been updated to consider PEP 685. Have you tried to use the latest version of setuptools in [build-system] requires?


Another possibility is that pip wants you to write package[some-extra] in the pip install command.