Skip to content

Comments

Bugfix:find_best_candidate sort order affects result#1548

Merged
sdispater merged 2 commits intopython-poetry:masterfrom
JBKahn:patch-1
Nov 12, 2019
Merged

Bugfix:find_best_candidate sort order affects result#1548
sdispater merged 2 commits intopython-poetry:masterfrom
JBKahn:patch-1

Conversation

@JBKahn
Copy link
Contributor

@JBKahn JBKahn commented Nov 6, 2019

Description

find_best_candidate picks the 0th element of the list as a default. Since this list includes both invalid and valid items, it's possible to return an invalid item. In this case it was returning a pre-release when pre-releases wren't allowed.

Since this is a bugfix, I did not update the documentation.

Pull Request Check List

This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once, it will save you unnecessary review cycles!

  • Added tests for changed code.
  • Updated documentation for changed code.
    Note: If your Pull Request introduces a new feature or changes the current behavior, it should be based
    on the develop branch. If it's a bug fix or only a documentation update, it should be based on the master branch.

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

@JBKahn JBKahn changed the title respect allow_prereleases update find_best_candidate to not default to a prerelease Nov 6, 2019
@JBKahn

This comment has been minimized.

@nickpresta
Copy link

Here's a bit more context on why we want to make this change (copied from an internal PR):

poetry show --latest grabs all packages and shows the current version and the latest version.

HOWEVER, it seems there is a bug in the --latest behavior that doesn't reject pre-release versions. See the following:

[tool.poetry]
name = "testing-poetry"
version = "0.1.0"
description = ""
authors = ["Nick Presta <[email protected]>"]

[[tool.poetry.source]]
name = "private_pypi"
url = "our_custom_url"

[tool.poetry.dependencies]
python = "^3.8"
next-accounting-utils = {version = "30.2.1", source = "private_pypi"}

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=1.0.0b3"]
build-backend = "poetry.masonry.api"

the lockfile generated is:

[[package]]
category = "main"
description = "Internationalization utilities"
name = "babel"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "2.7.0"

[package.dependencies]
pytz = ">=2015.7"

[[package]]
category = "main"
description = "Python 3.4 Enum backported to 3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4"
name = "enum34"
optional = false
python-versions = "*"
version = "1.1.6"

[[package]]
category = "main"
description = "A set of constants, validation rules and shared tooling for next-accounting."
name = "next-accounting-utils"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*"
version = "30.2.1"

[package.dependencies]
Babel = ">=2.5.3"
enum34 = "<2.0.0"
python-wave-common = ">=0.1.1,<2.0.0"
pytz = ">=2017.2"
six = "<2.0.0"
titlecase = "<1.0.0"

[package.source]
reference = "private_pypi"
type = "legacy"
url = "our_custom_url"

[[package]]
category = "main"
description = "Your project description goes here"
name = "python-wave-common"
optional = false
python-versions = "*"
version = "1.1.0"

[package.dependencies]
six = ">=1.10.0"

[package.extras]
test = ["pytest (3.1.3)", "tox (2.7.0)"]

[package.source]
reference = "private_pypi"
type = "legacy"
url = "our_custom_url"

[[package]]
category = "main"
description = "World timezone definitions, modern and historical"
name = "pytz"
optional = false
python-versions = "*"
version = "2019.3"

[[package]]
category = "main"
description = "Python 2 and 3 compatibility utilities"
name = "six"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*"
version = "1.13.0"

[[package]]
category = "main"
description = "Python Port of John Gruber's titlecase.pl"
name = "titlecase"
optional = false
python-versions = "*"
version = "0.12.0"

[metadata]
content-hash = "e78f0be94888e5b72bca67f12bff58ff8b1e2f8559a2754a4d7a843124b2c00b"
python-versions = "^3.8"

[metadata.files]
babel = [
    {file = "Babel-2.7.0-py2.py3-none-any.whl", hash = "sha256:af92e6106cb7c55286b25b38ad7695f8b4efb36a90ba483d7f7a6628c46158ab"},
    {file = "Babel-2.7.0.tar.gz", hash = "sha256:e86135ae101e31e2c8ec20a4e0c5220f4eed12487d5cf3f78be7e98d3a57fc28"},
]
enum34 = [
    {file = "enum34-1.1.6-py2-none-any.whl", hash = "sha256:6bd0f6ad48ec2aa117d3d141940d484deccda84d4fcd884f5c3d93c23ecd8c79"},
    {file = "enum34-1.1.6-py3-none-any.whl", hash = "sha256:644837f692e5f550741432dd3f223bbb9852018674981b1664e5dc339387588a"},
    {file = "enum34-1.1.6.tar.gz", hash = "sha256:8ad8c4783bf61ded74527bffb48ed9b54166685e4230386a9ed9b1279e2df5b1"},
    {file = "enum34-1.1.6.zip", hash = "sha256:2d81cbbe0e73112bdfe6ef8576f2238f2ba27dd0d55752a776c41d38b7da2850"},
]
next-accounting-utils = [
    {file = "next-accounting-utils-30.2.1.tar.gz", hash = "md5:5394f032d798fdf63b8a88fc937dc0fb"},
    {file = "next_accounting_utils-30.2.1-py2.py3-none-any.whl", hash = "md5:9a17d291cb809f4574625d885a8eb4b8"},
]
python-wave-common = [
    {file = "python_wave_common-1.1.0.tar.gz", hash = "md5:e04ceeee0be0a61ae1bbd7716258e0e8"},
]
pytz = [
    {file = "pytz-2019.3-py2.py3-none-any.whl", hash = "sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d"},
    {file = "pytz-2019.3.tar.gz", hash = "sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be"},
]
six = [
    {file = "six-1.13.0-py2.py3-none-any.whl", hash = "sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd"},
    {file = "six-1.13.0.tar.gz", hash = "sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66"},
]
titlecase = [
    {file = "titlecase-0.12.0-py3-none-any.whl", hash = "sha256:95d643a0c08097c02933aced707adfe1c275c335019e8e514dea782a465c5b84"},
    {file = "titlecase-0.12.0.tar.gz", hash = "sha256:84de7a97fb702c400e5ba11c6b30849944b39db12e20fbf4515a23c7538a0611"},
]

when I run poetry show --latest or poetry show --outdated, I get:

$ poetry show --latest
babel                 2.7.0  2.7.0                Internationalization utilities
enum34                1.1.6  1.1.6                Python 3.4 Enum backported to 3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4
next-accounting-utils 30.2.1 31.0.0.dev1570559246 A set of constants, validation rules and shared tooling for next-accounting.
python-wave-common    1.1.0  1.1.0                Your project description goes here
pytz                  2019.3 2019.3               World timezone definitions, modern and historical
six                   1.13.0 1.13.0               Python 2 and 3 compatibility utilities
titlecase             0.12.0 0.12.0               Python Port of John Gruber's titlecase.pl

which is wrong for next-accounting-utils. Furthermore, if I change my version specifier in my pyproject.toml to:

[tool.poetry.dependencies]
python = "^3.8"
next-accounting-utils = {version = "<32.0.0", source = "private_pypi"}

and run poetry update:

$ poetry update
Updating dependencies
Resolving dependencies... (1.6s)

Writing lock file


Package operations: 0 installs, 1 update, 0 removals

  - Updating next-accounting-utils (30.2.1 -> 30.3.0)

which does not update to a pre-release version.

@JBKahn JBKahn changed the title update find_best_candidate to not default to a prerelease Bugfix:find_best_candidate sort order affects result Nov 6, 2019
@JBKahn
Copy link
Contributor Author

JBKahn commented Nov 11, 2019

@sdispater any thoughts?

@sdispater sdispater merged commit 1fe50fe into python-poetry:master Nov 12, 2019
@sdispater
Copy link
Member

Thanks!

@JBKahn JBKahn deleted the patch-1 branch November 12, 2019 18:21
shenek pushed a commit to shenek/poetry that referenced this pull request Dec 31, 2019
@github-actions
Copy link

github-actions bot commented Mar 1, 2024

This pull request 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants