setuptools: [FR] Improve error feedback for improper one-liner requirement with environment markers in `setup.cfg`

setuptools version

63.2.0

Python version

3.9 and 3.11

OS

Fedora Linux

Additional environment information

No response

Description

Project: https://github.com/thoth-station/micropipenv The line I have a problem with: https://github.com/thoth-station/micropipenv/blob/2127293c4c9fa344fd1535c5189c39ca7ba4594d/setup.cfg#L40

It seems to me that there is a difference between this:

[options.extras_require]
toml = toml;python_version<"3.11"

and this:

[options.extras_require]
toml =
    toml;python_version<"3.11"

Micropipenv version 1.4.0 contains the [toml] definition on a single line and when you try to install micropipenv[toml], it does not work (Python 3.9.13):

Collecting micropipenv[toml]==1.4.0
  Using cached micropipenv-1.4.0-py3-none-any.whl (38 kB)
Requirement already satisfied: pip>=9 in /home/lbalhar/.virtualenvs/micropipenv/lib/python3.9/site-packages (from micropipenv[toml]==1.4.0) (22.2)
Collecting toml
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
ERROR: Could not find a version that satisfies the requirement python-version<"3.11"; extra == "toml" (from micropipenv[toml]) (from versions: 0.0.2)
ERROR: No matching distribution found for python-version<"3.11"; extra == "toml"

the same happens when you use Python 3.11.

But when I use the multiline definition:

[options.extras_require]
toml =
    toml;python_version<"3.11"

it works correctly and omits toml in env with Python 3.11 and installs it if Python<3.11.

When I build a sdist from the package, there is a difference in requires.txt in egg-info directory: single line definition:

pip>=9

[toml]
toml
python_version<"3.11"

two lines:

pip>=9

[toml]

[toml:python_version < "3.11"]
toml

Expected behavior

I’d expect the two definitions mentioned above to behave the same way.

How to Reproduce

You can try to install “micropipenv[toml]==1.4.0” and then you can change the extras_require definition as described above to see that it fixes the problem.

Output

$ tail -n 3 setup.cfg

[options.extras_require]
toml = toml;python_version<"3.11"

$ pip install .[toml]
Processing /home/lbalhar/Software/micropipenv
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: pip>=9 in /home/lbalhar/.virtualenvs/micropipenv/lib/python3.9/site-packages (from micropipenv==1.4.0) (22.2)
Collecting toml
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
ERROR: Could not find a version that satisfies the requirement python-version<"3.11"; extra == "toml" (from micropipenv[toml]) (from versions: 0.0.2)
ERROR: No matching distribution found for python-version<"3.11"; extra == "toml"

## changed the definition

$ tail -n 3 setup.cfg
[options.extras_require]
toml =
    toml;python_version<"3.11"

$ pip install .[toml]
Processing /home/lbalhar/Software/micropipenv
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: pip>=9 in /home/lbalhar/.virtualenvs/micropipenv/lib/python3.9/site-packages (from micropipenv==1.4.0) (22.2)
Collecting toml
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Building wheels for collected packages: micropipenv
  Building wheel for micropipenv (pyproject.toml) ... done
  Created wheel for micropipenv: filename=micropipenv-1.4.0-py3-none-any.whl size=23303 sha256=b645cc71f7404f367dabe8c203cf80025f3080c7d2ac6a929aec3ae5bbab2a6a
  Stored in directory: /tmp/pip-ephem-wheel-cache-zh2n98et/wheels/2a/c1/ee/2caed205bb1a97b553aa44d9a5f1966c5bec9edea862cc2c72
Successfully built micropipenv
Installing collected packages: toml, micropipenv
Successfully installed micropipenv-1.4.0 toml-0.10.2

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (19 by maintainers)

Commits related to this issue

Most upvoted comments

We will try it soon.

Hi @frenzymadness , this is a limitation in terms of setup.cfg that is explained in the docs:

In the extras_require section, values are parsed as list-semi. This implies that in order to include markers, they must be dangling

The rationale is that if you don’t include newlines in the value, the character used to split different requirements is ;.

Oh, I sent my comment before seeing this. I agree that this is a known limitation, however I would argue that it is a trap.

We’ve discussed with @frenzymadness and we belive a warning might be presented when the entire line:

  • contains exactly 1 ;
  • parses as a valid requirement string
  • the part after ; parses as a valid environment marker

WDYT?