Support specifying project.optional-dependencies
extras on the python_requirements
target.
#19376
Labels
project.optional-dependencies
extras on the python_requirements
target.
#19376
Problem
In Pants 2.16, there is a requirement to specify a lock file for each tool. Currently, this specification is not mandatory, but the requirements field for each tool does not support additional dependencies, such as
flake8-annotations
forflake8
orpyenchant
forpylint
. This limitation exists because of Pants' internal lock files. Additionally, Pants enforces the use of Pants-generated lock files for the tools. While Poetry and Pipenv support grouping requirements, they strangely do not support generating multiple lock files for each group. As a result, when working with our project's repository, we end up with multiple requirements files and corresponding lock files, totaling around 20 files. We decided to address this by placing all the requirements in thepyproject.toml
file using the PEP 621 format and organizing each tool's requirements in a separate group inside theproject.optional-dependencies
section. However, since there are different lock files for each group, we cannot specify this in thepython_requirements
target.Proposed solution
To address this issue, we propose enhancing the
python_requirements
target to allow the selection of a subset of thepyproject.toml
file. Currently, Pants understands optional dependencies and generates a tag for each one. Our suggestion is to add the capability to specify a specific part of thepyproject.toml
file in thepython_requirements
target:However, we acknowledge that this idea conflicts with the installation of requirements using Pip and
pyproject.toml
. According to PEP 621 and similar to theextra_requires
concept in thesetuptools
literature, these optional dependencies should be installed in addition to the main requirements, rather than being separate entities. Perhaps we should consider avoiding the use of theextra
keyword and instead find a more generic approach to solve this issue:Alternative approaches attempted
We have explored alternative lock file generators such as Poetry and Pipenv. While both tools support grouping requirements, they do not support the generation of multiple lock files. Furthermore, Poetry enforces that all requirement groups should be compatible with each other, even if they are optional. These limitations have been discussed in the following GitHub issues: link 1, link 2, and link 3. In addition to the aforementioned problems, Pants mandates the use of Pants-generated lock files for the tools, further complicating the situation.
Despite our attempts, using a single
requirements.txt
andrequirements.lock
file led to conflicts with theimportlib-metadata
library when incorporating new versions offlake8
andsphinx
.Finally, I would greatly appreciate any alternative solutions that can help avoid the proliferation of multiple requirements files and lock files.
The text was updated successfully, but these errors were encountered: