Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Patch revision specification in pyproject.toml breaks creating new venv #4136

Closed
3 tasks done
tigerhawkvok opened this issue Jun 3, 2021 · 7 comments
Closed
3 tasks done
Labels
kind/bug Something isn't working as expected

Comments

@tigerhawkvok
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).

Issue

Similar to #1735 .

I only have one version of Python on this machine, 3.7.8; but the requirement ^3.7.1 throws an error:

image

This can be corrected by removing the patch revision, then later updating pyproject.toml doesn't cause further poetry commands to fail.

@tigerhawkvok tigerhawkvok added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jun 3, 2021
@finswimmer
Copy link
Member

Hello @tigerhawkvok,

can you show the out of which poetry and head $(which poetry)?

fin swimmer

@finswimmer finswimmer added the status/waiting-on-response Waiting on response from author label Jun 11, 2021
@tigerhawkvok
Copy link
Author

head isn't a valid command in my Powershell setup (strangely, because I have most *nix commands), so here are the results from git bash. It's the same poetry which as pure powershell.

image

pkahn@SFPKAHN1 MINGW64 ~
$ which poetry
/c/Users/pkahn/.poetry/bin/poetry

pkahn@SFPKAHN1 MINGW64 ~
$ head $(which poetry)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import glob
import sys
import os

lib = os.path.normpath(os.path.join(os.path.realpath(__file__), "../..", "lib"))
vendors = os.path.join(lib, "poetry", "_vendor")
current_vendors = os.path.join(
    vendors, "py{}".format(".".join(str(v) for v in sys.version_info[:2]))

@tigerhawkvok
Copy link
Author

tigerhawkvok commented Jun 11, 2021

Seems like instead of a string comparison, following PEP 440 Poetry should use something like packaging which is vendored into setuptools and vendored into pip to compare versions:

>>> from packaging import version
>>> version.parse("2.3.1") < version.parse("10.1.2")
True

Pulling the first two tuple elements in sys.version_info will always fail patch revisions, which can break package dependencies when, for example, pandas==1.0.5 requires python to be newer than 3.7.1. Instead:

image

@tigerhawkvok
Copy link
Author

I propose something like this:

from packaging.version import parse as parsePyVersion
from packaging.version import VERSION_PATTERN
from platform import python_version
import re
def validPyVersion(required:str, debug:bool= False) -> bool:
    """
    Compare a match string to the running Python version
    """
    required = str(required)
    # Our running version
    CURRENT_VERSION = parsePyVersion(python_version())
    # The package minimum required version
    versionMatch = re.search(r"^[\^=~]*([0-9](?:\.\d*)?(?:\.[a-z\d]*)?)$", required.strip(), re.IGNORECASE | re.DOTALL | re.MULTILINE)
    if not versionMatch:
        raise ValueError("Invalid version string")
    versionString = versionMatch.group(1)
    versionParts = versionString.split(".")
    COMPARE_VERSION = parsePyVersion(versionString)
    # The next revision up, for the package's specificity
    try:
        if len(versionParts) == 1:
            raise IndexError
        versionSpecificity = versionParts.copy().pop() if len(versionParts) < 3 else versionParts[:-1].pop()
        versionStub = [versionParts[0]]
    except IndexError:
        versionSpecificity = versionString
        versionStub = []
    try:
        nextVersion = int(versionSpecificity) + 1
    except TypeError:
        thisDigitMatch = re.search(r"^(\d+)", versionSpecificity, re.IGNORECASE | re.DOTALL | re.MULTILINE)
        thisDigit = 0 if thisDigitMatch is None else thisDigitMatch.group(0)
        nextVersion = int(thisDigit) + 1
    PACKAGE_LESS_THAN_VERSION = parsePyVersion('.'.join([str(x) for x in versionStub + [nextVersion]]))
    # tidy the match type. Remove `=` as to play nice with
    # some version strings that have extra `=` in them, like pip
    matchType = required.strip().replace(versionString, '')
    if len(matchType) > 1:
        matchType = matchType.replace('=', '')
    if len(matchType) == 0:
        matchType = '=' if len(versionParts) == 3 else "~"
    comparisonMapper = {
        '=': COMPARE_VERSION == CURRENT_VERSION,
        '^': CURRENT_VERSION >= COMPARE_VERSION,
        '~': (CURRENT_VERSION >= COMPARE_VERSION) and (CURRENT_VERSION < PACKAGE_LESS_THAN_VERSION),
    }
    if debug:
        return comparisonMapper[matchType], COMPARE_VERSION, PACKAGE_LESS_THAN_VERSION, CURRENT_VERSION, matchType
    return comparisonMapper[matchType]

image

@finswimmer
Copy link
Member

Hello @tigerhawkvok,

I guess your suggestion refers to this line in the poetry executable?

current_vendors = os.path.join(
    vendors, "py{}".format(".".join(str(v) for v in sys.version_info[:2]))

This is only needed to tell poetry where it can find it's vendored dependencies. And this location depends on the currently activate python minor version.

This has nothing to do with comparing version requirements for dependencies. So it's still unclear why poetry believes you are using python 3.7.0. Can you show the output of python -c "import sys;print(sys.version_info)"?

fin swimmer

@finswimmer
Copy link
Member

I'm closing this because we haven't receive no more information for a long time now.

Feel free to leave a comment if you disagree.

@abn abn removed the status/triage This issue needs to be triaged label Mar 3, 2022
@mkniewallner mkniewallner removed the status/waiting-on-response Waiting on response from author label Jun 11, 2022
Copy link

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

No branches or pull requests

4 participants