pdm-project / pdm

A modern Python package and dependency manager supporting the latest PEP standards
https://pdm-project.org
MIT License
7.94k stars 402 forks source link

Allow exclusion of dependencies #1316

Closed mxab closed 10 months ago

mxab commented 2 years ago

Is your feature request related to a problem? Please describe.

We have the problem that some python libraries have a lot of dependencies that are actually optional but not marked as such and come with the regular installation.

For example RASA which is a cool library for intent detection but they simply added all dependencies as main dependencies https://github.com/RasaHQ/rasa/blob/main/pyproject.toml#L65

This means when I install this I get besides the actual core libraries dependencies to e.g. a telegram client lib or a mongodb library This does not only increase the size of your final application but also introduces potential security or licenses alerts

Describe the solution you'd like

It would be great if there would be similar to the [tool.pdm.overrides] feature a [tool.pdm.excludes] section where I can exclude certain dependencies Would be great if this would not only allowing blacklisting that dependency but also then prevents the resolution of the dependency of this depenency if they are not required by other dependencies

e.g.:

[tool.pdm.excludes]
pyTelegramBotAPI=<not sure if a version makes sense here>
pawamoy commented 2 years ago

That would be nice indeed. I think Python devs have been wanting a "dependency opt-out" mecanism for a long time. Ideally libraries like RASA would make use of extras to provide optional libraries. I understand the burden it is to support optional libraries but I also can't stand having to, for example, install click in production because uvicorn requires it. I'd personally make heavy use of such a dependency exclusion feature :+1: Shortening the resolution by ignoring excluded deps would be a plus, though I'd take the feature even without it.

One thing though is that you have to make sure the package you're using does not import all its submodules, otherwise you'll get an import error anyway, so excluding deps would probably not work for many packages.

T145 commented 10 months ago

Bump

Though I'd make the field tool.poetry.dependencies.exclude since include is implicit in the base field.

TheKnightCoder commented 6 months ago

how to exclude on pdm build command? I've added this to the toml and although it remove from the .lock it doesn't remove from the build

[tool.pdm.resolution] excludes = ["pyarrow", "numpy", "pyarrow-hotfix"]

frostming commented 6 months ago

how to exclude on pdm build command?

In short, you can't. PDM doesn't have control on the core-metadata contained in the build artifact.

You'll need [tool.pdm.resolution] in the destination project to install your project.