pdm-project / pdm

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

Question: inconsistent resolution order between groups? #2875

Closed inigohidalgo closed 3 weeks ago

inigohidalgo commented 3 weeks ago

Context: we are building various libraries in a monorepo environment, and some of these libraries have dependencies on other libraries in the monorepo.


I understand this behavior isn't directly supported by pdm as has been discussed in other issues, but I had a question about pdm's behavior when resolving dependencies, as it seems like resolutions are non-deterministic when starting from the same pyproject.toml

Say I have a pyproject.toml like so

dependencies = [
    "my-package"
]

[tool.pdm.dev-dependencies]
editable = [
    "-e file:///${PROJECT_ROOT}/../path/to/my-package --dev",
]

This is a package that I am yet to publish to an index, so is not available through the normal pip install my-package, but is available in the path.

Using the command pdm install --frozen-lockfile -v -G editable I am getting inconsistent results: sometimes the installation will proceed correctly, it will first add the editable dependency, so then the direct dependency does not raise an error, but other times it will start from the default dependency group which causes this error

pdm.termui: ======== Start resolving requirements ========
pdm.termui:   my-package
pdm.termui:   -e file:///${PROJECT_ROOT}/../../my-package#egg=my-package
pdm.termui:   python<3.11,>=3.8
pdm.termui:   Adding requirement my-package

And it will fail with pdm.exceptions.CandidateNotFound: Unable to find candidates for my-package. There may exist some issues with the package name or network condition.

I am not asking for native support for this behavior, as I understand it is currently unsupported, but I am trying to see if there is some way to affect the resolution order, as if I was able to force it to look at a specific group first, I would be able to run the CICD pipeline as I would like to.

huxuan commented 3 weeks ago

Is --no-self or --no-default what you are looking for?

inigohidalgo commented 3 weeks ago

thx @huxuan for your answer.

--no-default could work as a workaround for the specific example I posted but the problem is my dependencies array actually includes more packages which are not self-published so I would not be able to install those.

Another workaround is to specify my self-built dependencies in an optional prod dependency group, and not install those in my CI-CD environment, but technically they are not an optional dependency: there should always be a package with that name installed in my environment so it seems wrong to go this way.

I just wanted to make sure I'm not missing any options I could use, but I will understand if the answer is just "your current requirement is not addressed by pdm", as I am aware this is not a common approach to package management.

inigohidalgo commented 3 weeks ago

I belive I can work around this issue just using

pdm install --no-self --no-default --frozen-lockfile -v -G editable
python -m pip install .

I was originally trying to do pdm install --prod instead of pip but pdm was not recognizing that there was already an installed version whereas pip recognizes it.

Thanks to pyproject.toml interoperability, this is a satisfactory solution for my workflow so I am closing the issue.

Thank you for your help @huxuan and thanks again to the maintainers for all the work on pdm, I've been using it for nearly 2 years to great success in my CI/CD pipelines.

frostming commented 3 weeks ago

Because you didn't give a name to the editable dependency and PDM can't override the default dependency correctly, try changing it to:

-e file:///${PROJECT_ROOT}/../../my-package#egg=my-package