MYK
MYK

Reputation: 3017

How do I use --no-deps in a pyproject.toml?

I have a pyproject.toml file with some python packages.

It has a section like:

dependencies = [
    'pandas == 1.4.3',
    'streamlit == 1.11.1',
    ...
]

I then usually install these dependencies using

python -m pip install .[dependencies]

I need to install a new package that has a conflict in one of its dependencies. I checked, and the "conflict" is superficial - ie. the maintainers of the new package just "forgot" to update the requirements.txt to allow pandas>=1.4.

I can do this by running python -m pip install {new_package} --no-deps

But is there any way to do this within the pyproject.toml file?

Upvotes: 13

Views: 755

Answers (1)

HernanATN
HernanATN

Reputation: 746

Yes, you can!

by leveragin pip's direct references with the --no-deps flag, inside pyproject.toml directly.

Your dependencies entry should look something like:

dependencies = [
    'pandas == 1.4.3',
    'streamlit == 1.11.1',
    '{{NEW_PACKAGE}} @ git+https://github.com/{{USER}}/{{NEW_PACKAGE}}.git#egg={{NEW_PACKAGE}} --no-deps',
]

This is kinda hacky tho, as it avoids PyPi.

A more robust solution albeit more involed woulde be to define the problematic deps separatelly using optional-dependencies:

[project]
dependencies = [
    'pandas == 1.4.3',
    'streamlit == 1.11.1',
]

[project.optional-dependencies]
main = [
    'pandas == 1.4.3',
    'streamlit == 1.11.1',
]

problematic = [
    'new-package'
]

and then installing them separatelly:

> python -m pip install .[main]
> python -m pip install .[problematic] --no-deps

For convenience, you could wrapp both install commands in a custom bash/ps1 script:

Bash

python -m pip install .[main] && python -m pip install .[problematic] --no-deps

Powershell

python -m pip install .[main]; python -m pip install .[problematic] --no-deps

Upvotes: 0

Related Questions