Poetry: Pre-release `~=` constrains are mis calculated

Created on 6 Jun 2019  路  5Comments  路  Source: python-poetry/poetry

  • [x] I am on the latest Poetry version.
  • [x] 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: Windows
  • Poetry version: 0.12.16
  • Link of a Gist with the contents of your pyproject.toml file: N/A, requires access to a proprietary pypi instance

Issue

My constraints aren't resolving.

A rough look at my dependency tree

  • A: `B = "^0.7.5" via poetry
  • B: "C~=0.2.0dev16" via setup.py

Poetry complains that it cannot resolve B's dependency on C

[SolverProblemError]
Because B (0.7.5) depends on C(>=0.2.0,<0.3.0) which doesn't match any versions, B is forbidden.
So, because no versions of B match >0.7.5,<0.8.0
 and A depends on B (^0.7.5), version solving failed.

I traced the problem down into semver/__init__.py:parse_single_constraint where the constraint

  • ~=0.2.0dev16
    gets compiled into
  • >=0.2.0,<0.3.0

In contrast, the constraint

  • ~=2.0.dev0
    correctly gets compiled into
  • >=2.0.dev0,<3.0.0

The problem seems to be

        if precision == 2:
            low = version
            high = version.stable.next_major
        else:
            low = Version(version.major, version.minor, 0)
            high = version.stable.next_minor

where if the precision is 1 or 3, then the pre-release is dropped from low, disqualifying them from resolving the constraint.

Most helpful comment

As a user, this is a bit frustrating for issues to be automatically closed when the problem is unresponsiveness from the maintainers.

All 5 comments

I'm assuming we could just do low = Version(version.major, version.minor, 0, pre=".".join(str(p) for p in version.prerelease))?

The part that confuses me is why precision being 1 or 3 gets that else clause.

EDIT: Corrected possible fix for the actual names and types

This line conflicts with PEP440 compatible release semantics.

The false negative test:

https://github.com/sdispater/poetry/commit/c55d55a888538dbe8ae0b650997db6f9ef4d0aa9#diff-20f6d1388627d02d179420d26445d183R65

So as I was digging into this, it appears that ~= semantics are broken. ~=3.5.3 should be VersionRange(Version(3, 5, 3), Version(3, 6, 0), True) instead of VersionRange(Version(3, 5, 0), Version(3, 6, 0), True).

@drunkwcodes is that the problem you are highlighting? I'm leaning towards handling that in a separate issue / PR.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

As a user, this is a bit frustrating for issues to be automatically closed when the problem is unresponsiveness from the maintainers.

Was this page helpful?
0 / 5 - 0 ratings