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

(🎁) Abillity to constrain transitive dependencies #4991

Closed
2 tasks done
KotlinIsland opened this issue Jan 6, 2022 · 6 comments
Closed
2 tasks done

(🎁) Abillity to constrain transitive dependencies #4991

KotlinIsland opened this issue Jan 6, 2022 · 6 comments
Labels
kind/feature Feature requests/implementations

Comments

@KotlinIsland
Copy link
Contributor

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Feature Request

In Gradle you can constrain transitive dependencies like this:

dependencies {
    implementation("org.apache.httpcomponents:httpclient")
    constraints {
        implementation("org.apache.httpcomponents:httpclient:4.5.3") {
            because("previous versions have a bug impacting this application")
        }
        implementation("commons-codec:commons-codec:1.11") {
            because("version 1.9 pulled from httpclient has bugs affecting this application")
        }
    }
}

In Poetry if I want to constrain a transitive dependency I have to specify the dependency as a direct dependency.

There are several advantages and motivations to specifying constraints over direct dependencies.

I would like to be able to specify constraints, maybe something like:

[tool.poetry.dependencies]
setuptools = { version: "60.2.0", constraint = true }
@KotlinIsland KotlinIsland added kind/feature Feature requests/implementations status/triage This issue needs to be triaged labels Jan 6, 2022
@KotlinIsland
Copy link
Contributor Author

pip supports constraints https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-c

@KotlinIsland
Copy link
Contributor Author

You can kinda get some transitive dependency functionality if you mark the dependency as optional and don't put it in an extra:

[tool.poetry.dependencies]
setuptools = { version: "60.2.0", optional = true }

Or maybe make a "constraints" group:

[tool.poetry.group.constraints]
optional = true

[tool.poetry.group.constraints.dependencies]
setuptools = "60.2.0"

But this isn't a full form solution.

@neersighted neersighted removed the status/triage This issue needs to be triaged label Oct 10, 2022
@neersighted
Copy link
Member

Because Python packaging is flat, Poetry has always taken the stance that if you care about a transient dependency at all (version, source, etc) it's now a top-level dependency, even if you don't import a module in that dependency directly.

I doubt we'll be revisiting that decision anytime soon, and for those that object, the pattern above with optional groups is supported/offers another path.

@neersighted neersighted closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2022
yrro added a commit to yrro/hitron-exporter that referenced this issue Feb 16, 2023
… requesting ipapython's 'ldap' extra

This removes some unused dependencies of ipaclient such as pypng and
qrcode.

Ideally we'd be able to add the 'ldap' extra to 'ipapython' without
promoting it to a direect dependency, however Poetry does not support
this:

> Because Python packaging is flat, Poetry has always taken the stance
> that if you care about a transient dependency at all (version, source,
> etc) it's now a top-level dependency, even if you don't import a module
> in that dependency directly.

<python-poetry/poetry#4991 (comment)>
@KotlinIsland
Copy link
Contributor Author

You can kinda get some transitive dependency functionality if you mark the dependency as optional and don't put it in an extra

the pattern above with optional groups is supported/offers another path.

The optional marker without an extra doesn't seem to make it optional in pip's eyes, see #7787

@jonapich
Copy link
Contributor

jonapich commented Jul 17, 2023

Recently, a transitive dependency upgrade happened that created a conflict and even broke past setups that embraced "best practices" in pinning dependencies:

open-telemetry/opentelemetry-python#3382

This kind of bug means that the current working build stopped working, as well as most/all previous builds (for pip users).

On the same day, we also had problems with 2 top-level dependencies (boto3-stubs and click) that were marked as ^1.26.0 and ^8.1.2 respectively in our pyproject.toml file. Click's 8.1.4 has an issue with types vs mypy and boto3-stubs has a bunch of .postN transitive dependencies that appeared; one of them fails.

Since this is a CLI app and not a library that you're expected to import, we want to ensure to pin transitive dependencies for pip users so that this doesn't happen anymore in the future. A quick way to achieve this would be to use poetry export to generate a requirements.txt file and not include the pyproject.toml file with the package / not use poetry for publishing 😞

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Feature requests/implementations
Projects
None yet
Development

No branches or pull requests

3 participants