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

Unable to poetry install twisted trunk and treq #5311

Closed
2 of 3 tasks
DMRobertson opened this issue Mar 14, 2022 · 8 comments · Fixed by #5770
Closed
2 of 3 tasks

Unable to poetry install twisted trunk and treq #5311

DMRobertson opened this issue Mar 14, 2022 · 8 comments · Fixed by #5770
Labels
kind/bug Something isn't working as expected

Comments

@DMRobertson
Copy link

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Fedora 35
  • Poetry version: 1.1.12
  • Pyproject.toml:
    [tool.poetry]
    name = "test"
    version = "0.1.0"
    description = ""
    authors = ["David Robertson <david.m.robertson1@gmail.com>"]
    
    [tool.poetry.dependencies]
    python = "^3.10"
    Twisted = {git = "https://github.com/twisted/twisted.git", branch = "trunk"}
    treq = "^22.2.0"
    
    [tool.poetry.dev-dependencies]
    
    [build-system]
    requires = ["poetry-core>=1.0.0"]
    build-backend = "poetry.core.masonry.api"

Issue

I tried to install twisted trunk and treq as follows:

  • poetry init
  • poetry add git+https://github.com/twisted/twisted.git#trunk
  • poetry add treq

Step three tried to install treq ^22.2.0 which is the newest version. This failed: see add treq.txt.

I find the output hard to read (not helped by Twisted's date-based versioning scheme), but I think what's happening is:

  • treq 22.2.0 requires "Twisted[tls] >= 18.7.0"
  • poetry deduces the set of possible twisted versions: Thus, treq (>=22.2.0,<23.0.0) requires twisted (18.7.0 || 18.9.0 || 19.2.0 || 19.2.1 || 19.7.0 || 19.10.0 || 20.3.0 || 21.2.0 || 21.7.0 || 22.1.0 || 22.2.0).
  • This doesn't include include twisted 22.2.0.post0, the trunk version; I'm guessing this isn't being considered and that's why resolution fails?

I've also tried marking both with allow_prereleases=true but that didn't seem to change any behaviour---I'm guessing this refers to prereleases on PyPI rather than from-git prereleases.

Am I doing something wrong here?

@DMRobertson DMRobertson added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Mar 14, 2022
@Secrus
Copy link
Member

Secrus commented Mar 29, 2022

Did you try installing Twisted from PyPI not from git? Looking at file you provided, My guess would be that post0 confuses poetry solver to treat 22.2.0.post0 as lower version than 22.2.0 that would match requirements of treq.

@abn
Copy link
Member

abn commented Mar 29, 2022

TL;DR you can workaround this by using the following add command for twisted instead.

poetry add --extras tls git+https://github.com/twisted/twisted.git#trunk

The root cause of this behaviour is the retrieval of twisted[tls] from the locked repository.

locked = self._get_locked(dependency)
if locked is None or not dependency.constraint.allows(locked.version):
try:
packages = self._provider.search_for(dependency)
except ValueError as e:
self._add_incompatibility(
Incompatibility([Term(dependency, True)], PackageNotFoundCause(e))
)
return dependency.complete_name

As the tls extra was not activated the solver determines that the package twisted (locked) is not he same as twisted[tls] required.

if not dependency.is_same_package_as(locked):
return None

The complete name check fails.

https://github.com/python-poetry/poetry-core/blob/06f1f326eb512ec836b7f6379851d5fe2ea6eb30/src/poetry/core/packages/specification.py#L75-L76

This leads to the providers (ie. indexes) searched again for the right package with the extra tls. And as the project requires twisted==22.2.0.post0 (a version not available in PyPI, we fail to solve for treq's dependency on twisted[tls].

Think there are a few improvements to be made here. The same package check from core needs to be improved to handle extras.

@callahad
Copy link

callahad commented Apr 7, 2022

Workaround works. Suggest we can close this?

@abn
Copy link
Member

abn commented Apr 9, 2022

Think there is a root cause here that we should address, might leave this open so we can get that fixed.

@radoering
Copy link
Member

As the tls extra was not activated the solver determines that the package twisted (locked) is not he same as twisted[tls] required.

@abn This sounds a bit like #4618

@DMRobertson @callahad Can you try if the issue is still present in poetry 1.2.0b1?

@abn
Copy link
Member

abn commented Apr 10, 2022

Looks like adding treq still fails. But atleast now it states clearly it is a solver bug.

$ poetry add treq
Using version ^22.2.0 for treq

Updating dependencies
Resolving dependencies... (33.2s)

  RuntimeError

  [BUG] not twisted (22.2.0.post0 git rev trunk) is not satisfied.

  at ~/workspace/python-poetry/poetry/src/poetry/mixology/partial_solution.py:206 in satisfier
      202│             # As soon as we have enough assignments to satisfy term, return them.
      203│             if assigned_term.satisfies(term):
      204│                 return assignment
      205│ 
    → 206│         raise RuntimeError(f"[BUG] {term} is not satisfied.")
      207│ 
      208│     def satisfies(self, term: Term) -> bool:
      209│         return self.relation(term) == SetRelation.SUBSET
      210│ 

erikjohnston pushed a commit to matrix-org/synapse that referenced this issue Apr 12, 2022
… hashes (#12439)

The requirements file generated by `poetry export` isn't correctly processed by `pip install -r requirements.txt`. It contains twisted and treq, both pinned to 22.2.0.

When `pip` installs treq, it notices that `Twisted[tls]` is required. It then tries to acquire the latest twisted release, only to fail (because this hash isn't listed in the requirements file).From e.g. https://github.com/matrix-org/synapse/runs/5977154990?check_suite_focus=true

> ```
> #15 9.204 Collecting Twisted[tls]>=18.7.0
> #15 9.205 ERROR: In --require-hashes mode, all requirements must have their versions pinned with ==. These do not:
> #15 9.205     Twisted[tls]>=18.7.0 from https://files.pythonhosted.org/packages/db/99/38622ff95bb740bcc991f548eb46295bba62fcb6e907db1987c4d92edd09/Twisted-22.4.0-py3-none-any.whl#sha256=f9f7a91f94932477a9fc3b169d57f54f96c6e74a23d78d9ce54039a7f48928a2 (from treq==22.2.0->-r /synapse/requirements.txt (line 724))
> #15 ERROR: executor failed running [/bin/sh -c pip install --prefix="/install" --no-warn-script-location -r /synapse/requirements.txt]: exit code: 1
> ```

The underlying pip issue is pypa/pip#9644. A comment notes that one can avoid this behaviour with by `pip install`ing with the `--no-deps` flag. Let us do so.

(At first glance, the problem looks like python-poetry/poetry#5311, but that was a bug in `poetry install`; this is `poetry export`, whose behaviour is fine AFAICS).
@abn abn removed the status/triage This issue needs to be triaged label May 12, 2022
@radoering
Copy link
Member

The issue is not limited to locked repository (poetry lock --no-update or poetry add with existing lock file). It can be triggered without an existing poetry.lock just by running poetry lock with the given pyproject.toml. #5770 seems to solve all of these use cases.

Copy link

github-actions bot commented Mar 1, 2024

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 Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants