Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support requirements in pyproject.toml #12100

Closed
1 task done
stefaneidelloth opened this issue Jun 23, 2023 · 8 comments
Closed
1 task done

Support requirements in pyproject.toml #12100

stefaneidelloth opened this issue Jun 23, 2023 · 8 comments
Labels
S: needs triage Issues/PRs that need to be triaged type: feature request Request for a new feature

Comments

@stefaneidelloth
Copy link

stefaneidelloth commented Jun 23, 2023

What's the problem this feature will solve?

I would prefer to put requirements in pyproject.toml instead of using an extra configuration file requirements.txt.
=> Central configuration file

Are there plans to support this in future versions of pip? If not, what speaks against it?

Describe the solution you'd like

Support a command
pip install (would parallel syntax of npm install)
that looks up requirements from pyproject.toml and installs them.

If possible. the syntax for dependencies inside pyproject.toml should be compatible to the one used by hatch (and or poetry):

https://hatch.pypa.io/latest/config/dependency/

https://peps.python.org/pep-0631/

https://python-poetry.org/docs/pyproject#dependencies-and-dependency-groups

Alternative Solutions

pip install -r pyproject.toml

pip install -e .[dev]

Additional context

https://stackoverflow.com/questions/74508024/is-requirements-txt-still-needed-when-using-pyproject-toml

https://hatch.pypa.io/latest/config/dependency/

https://python-poetry.org/docs/pyproject#dependencies-and-dependency-groups

Code of Conduct

@stefaneidelloth stefaneidelloth added S: needs triage Issues/PRs that need to be triaged type: feature request Request for a new feature labels Jun 23, 2023
@asears
Copy link

asears commented Jun 24, 2023

Duplicate of #8049 #11584 and others.

This seems to be a common long standing request. Originally I had this question too, following DRY it seemed like duplication to copy simple requirements to 2 places (pyproject build for other packages, install for my packages).

If not updating the pip project,, it would be good to update documentation/FAQ to identify some methods of using pyproject.toml as the base for compiling and installing requirements based on minimum requirements, and why you may not want to do that and handle them with other methods.

python -m pip install --build -r pyproject

could generate a transitory requirements.txt based on pyproject.toml?

pip-tools and poetry and other tools have this option, it's up to the developer to combine and implement them.
Is there a pip or packaging FAQ? Instead of directing these questions into deep GitHub issues they could be in a FAQ.

https://python-poetry.org/docs/1.4/faq/#why-are-unbound-version-constraints-a-bad-idea
https://chadsmith-software.medium.com/pep-517-and-518-in-plain-english-47208ca8b7a6

Does it make more sense to maintain a requirements.in rather than requirements.txt?
Then there is the question of pinned vs. unpinned requirements.
jazzband/pip-tools#1656

@stefaneidelloth
Copy link
Author

stefaneidelloth commented Jun 24, 2023

Thank you for linking the related issues.

In my use case I do not want to install my project as a python package at all.
I just would prefer to have a central configuration file instead of individual files
for pytest, pylint, ...

a) Switching from pip to hatch, poetry etc. might be an option for me. However, those tools are not included by default and would need to be extra installed. See for example

winpython/winpython#1128

=> I would prefer to use the standard pip tool... supporting pyproject.toml as alternative to requirements.txt.

(Furthermore, poetry is not portable but stores an absolute path to python.exe. )

b) The referenced links seem to suggest special options, e. g. --only-deps: #11440

My suggestion here is to use pip install without any extra argument:

pip install

Currently that command gives the answer

ERROR: You must give at least one requirement to install (see "pip help install")

When using npm install for JavaScritpt projects, the requirements from package.json are installed.

Similarly, I would expect pip install to install the requirements from pyproject.toml to be installed.

@stefaneidelloth
Copy link
Author

stefaneidelloth commented Jun 24, 2023

Just found out, that as a workaround I could use

pip install -e .[dev]

for what I want.

In addition to the dependencies, It requires a name and a version to be specified in pyproject.toml:

[project]
name = 'dummy_project_name'
version = '0.0.1'
dependencies = [
    'cryptography',
]

[project.optional-dependencies]
dev = [
    # linting
    'pylint',
    # formatting
    'black'
]

@sbidoul
Copy link
Member

sbidoul commented Jun 25, 2023

@stefaneidelloth if editables work for you, I think that is the best solution at this point in time.

I'm going to close this issue, as it is amply discussed in #11440.

@stefaneidelloth
Copy link
Author

Is there a way to disable the creation of the egg file inside my src folder or automatically delete it when using

pip install -e .[dev]

?

@uranusjr
Copy link
Member

The egg directory is created by the build backend you use (probably setuptools, most backends I know of don’t do that), and you’d want to talk to them about this instead.

@stefaneidelloth
Copy link
Author

Thank you. The default build backend that is used if I don't specify one, seems to be setuptools. And setuptools creates the unwanted egg file. I would prefer if a "none" backend is used by default, only installing dependencies. I switched to hatchling as build backend, not creating the unwanted egg file any more:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

@stefaneidelloth
Copy link
Author

a) Switching from pip to hatch, poetry etc. might be an option for me. However, those tools are not included by default and would need to be extra installed.

The statement requires = ["hatchling"] seems to address this. Therefore, no need to manually install hatchling before applying it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S: needs triage Issues/PRs that need to be triaged type: feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

4 participants