python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.14k stars 2.25k forks source link

Poetry locks Python2.x constraints for Python3.x project #3917

Closed fj-dt closed 2 years ago

fj-dt commented 3 years ago

Issue

I am using Python3 and I want to install beautifulsoup4==4.9.1. beautifulsoup4==4.9.1 has a dependency called soupsieve. soupsieve has a constraints specifically for Python 2.x version which says soupsieve<2.0.

When I lock beautifulsoup4==4.9.1, I see that Poetry does not find the correct constraints for Python 3.7. It should install soupsieve version 2.x but it installs soupsieve version 1.x.

I double-checked that my venv is using Python 3.x and that Poetry also uses Python 3.x. I also tried with pip, pip-tools and pipenv; they are all locking the right version.

Here's the lock file

[[package]]
name = "beautifulsoup4"
version = "4.9.1"
description = "Screen-scraping library"
category = "main"
optional = false
python-versions = "*"

[package.dependencies]
soupsieve = [
    ">1.2",
    "<2.0",
]

[package.extras]
html5lib = ["html5lib"]
lxml = ["lxml"]

[[package]]
name = "soupsieve"
version = "1.9.6"
description = "A modern CSS selector implementation for Beautiful Soup."
category = "main"
optional = false
python-versions = "*"

[metadata]
lock-version = "1.1"
python-versions = "^3.7"
content-hash = "9fbe508dc2cd47d10bd6f762cf0cb01df11125d7a76860b74d5dc695517dea4f"

[metadata.files]
beautifulsoup4 = [
    {file = "beautifulsoup4-4.9.1-py2-none-any.whl", hash = "sha256:e718f2342e2e099b640a34ab782407b7b676f47ee272d6739e60b8ea23829f2c"},
    {file = "beautifulsoup4-4.9.1-py3-none-any.whl", hash = "sha256:a6237df3c32ccfaee4fd201c8f5f9d9df619b93121d01353a64a73ce8c6ef9a8"},
    {file = "beautifulsoup4-4.9.1.tar.gz", hash = "sha256:73cc4d115b96f79c7d77c1c7f7a0a8d4c57860d1041df407dd1aae7f07a77fd7"},
]
soupsieve = [
    {file = "soupsieve-1.9.6-py2.py3-none-any.whl", hash = "sha256:feb1e937fa26a69e08436aad4a9037cd7e1d4c7212909502ba30701247ff8abd"},
    {file = "soupsieve-1.9.6.tar.gz", hash = "sha256:7985bacc98c34923a439967c1a602dc4f1e15f923b6fcf02344184f86cc7efaa"},
]

Thanks for your help!

dimbleby commented 2 years ago

At 4.9.1, beautifulsoup expressed their soupsieve requirement by executing conditional code in setup.py:

install_requires=["soupsieve>1.2"]
if sys.version_info.major == 2:
    install_requires.append("soupsieve<2.0")

this is hard for poetry to handle, it looks as though it has 'seen' both branches but is not able to realise that one of them is only meant for python 2.

in later releases they moved to markers:

install_requires=[
    "soupsieve >1.2; python_version>='3.0'",
    "soupsieve >1.2, <2.0; python_version<'3.0'",
],

which is much better, and I expect poetry would handle just fine

At this point beautifulsoup has dropped support for python2 altogether and none of this is relevant, I expect it's safe to close this out.

Secrus commented 2 years ago

Yes, this is no longer relevant. Also, a lot has changed since poetry 1.1.5. You can check it with the newest version and if that's still a problem, open a new issue.

dimbleby commented 2 years ago

For what it's worth I expect this would still be a problem with beautifulsoup 4.9.1: it still is hard for poetry to understand setup.py with conditional code.

Encouraging the ecosystem to move to markers - as beautifulsoup already did - is the best way to make this sort of thing more reliable.

github-actions[bot] commented 6 months ago

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.