setup-cfg-fmt icon indicating copy to clipboard operation
setup-cfg-fmt copied to clipboard

Support `file:` for requires statements

Open johnnv1 opened this issue 2 years ago • 3 comments

Setuptools have added support file: for requires statements (as a beta feature)

I don't know if it makes sense to add support for this already, I just noticed it when going to test this feature.

Example

A simple setup.cfg (which works fine):

[metadata]
name = hi
version = 0.1.0
classifiers =
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3 :: Only

[options]
packages = find:
python_requires = >=3.8

[options.extras_require]
dev = file:requirements-dev.txt

Then run $ setup-cfg-fmt setup.cfgt

 [options.extras_require]
-dev = file:requirements-dev.txt
+dev =
+    file:requirements-dev.txt

Then try to install the package (with pip install -e .[dev]), and setuptools will raise an error because can't parse this. Also, if we have a space between : and the filename, setup-cfg-fmt will exclude the filename.

 [options.extras_require]
-dev = file: requirements-dev.txt
+dev =
+    file:

johnnv1 avatar Sep 19 '22 15:09 johnnv1

Currently values under options.extra_requires get rendered as lists. Should dev be special-cased?

mxr avatar Dec 16 '22 21:12 mxr

Sorry nevermind, dev is just an arbitrary name. I realize the issue is in this part of the code https://github.com/asottile/setup-cfg-fmt/blob/acc732d13a11c70e23f887586060c1ee28e0d7f7/setup_cfg_fmt.py#L222-L238 but it's not clear what the right behavior is supposed to be. Is it valid to specify file: requirements-dev.txt in addition to other library dependencies? Or must it be on its own?

mxr avatar Dec 16 '22 21:12 mxr

Hi, I did some tests to explore the correct behaviors, here are my findings.

According to the documents of setuptools 68.2.2,

file: - Value is read from a list of files and then concatenated.


After some testing, I found the following formats are valid

[options]
install_requires = file:requirements.txt
install_requires = file: requirements.txt    ; The <space> after colon is optional
install_requires = file:
    requirements.txt

install_requires = file: requirements.txt, other_requirements.txt
install_requires = file: 
    requirements.txt, other_requirements.txt

The following format is invalid, which causes error when installing the package (with pip install .)

[options]
install_requires = 
    file: requirements.txt, other_requirements.txt

The following format is also invalid. Although it doesn't trigger error when installing, the requirements will not be installed as expected.

[options]
install_requires = 
    requirements.txt
    other_requirements.txt

chien-liu avatar Oct 24 '23 21:10 chien-liu