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

Use packaging.version to check version equality #9085

Merged

Conversation

uranusjr
Copy link
Member

@uranusjr uranusjr commented Nov 1, 2020

Fix #9083. I’m 99.999% sure the fix is correct, but didn’t include a test since it’s late here and I have to get up early tomorrow. I’ll leave this to someone with more time 🙂

Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, just that it needs tests while we still have this fresh in our minds. :)

Copy link
Member

@pfmoore pfmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed this should have a test, but otherwise looks fine. I don't have time to write a test just now, but is it as simple as trying to install a package with version 1.0+local-1?

@pradyunsg
Copy link
Member

So... Looks like I'll be writing the test. :)

@pfmoore
Copy link
Member

pfmoore commented Nov 2, 2020

... or I could get to it this evening... 🙂

@pradyunsg
Copy link
Member

ACK. I'm happy to defer to you. :)

@pfmoore
Copy link
Member

pfmoore commented Nov 2, 2020

I tried this test:

def test_new_resolver_can_install_silly_version(script):
    create_basic_wheel_for_package(
        script,
        "simple",
        "0.1.0+local-1",
    )
    script.pip(
        "install",
        "--no-cache-dir", "--no-index",
        "--find-links", script.scratch_path,
        "simple"
    )
    assert_installed(script, simple="0.1.0+local-1")

but it failed with "ERROR: Requested simple from file:///C:/Users/.../test_new_resolver_can_install_0/workspace/scratch/simple-0.1.0%2Blocal-1-py2.py3-none-any.whl has different version in metadata: '0.1.0+local.1'"

which seems to be getting raised from _check_metadata_consistency. So I think there's more to do here 🙁

@pfmoore
Copy link
Member

pfmoore commented Nov 2, 2020

(To be clear, I don't intend to look at the _check_metadata_consistency issue, as that's a question of the functionality, not writing a test). @uranusjr will you be able to look at this?

@pradyunsg
Copy link
Member

Gotta love when assertions break because people are doing weird things. :)

@pfmoore
Copy link
Member

pfmoore commented Nov 2, 2020

Have I mentioned I hate normalisation? 😉

@uranusjr
Copy link
Member Author

uranusjr commented Nov 2, 2020

is it as simple as trying to install a package with version 1.0+local-1?

Yes, but vague spots in version normalisation means we probably want to test 1.0+local_1, 1.0+local-1, and 1.0+local.1. They currently can be normalised into either 1.0+local.1 or 1.0+local_1 in the wheel’s filename, so there are 6 variants.

but it failed with "ERROR: Requested simple from file:///C:/Users/.../test_new_resolver_can_install_0/workspace/scratch/simple-0.1.0%2Blocal-1-py2.py3-none-any.whl has different version in metadata: '0.1.0+local.1'"

create_basic_wheel_for_package() is missing edge cases in the implementation. simple-0.1.0+local-1-py2.py3-none-any.whl is not a valid wheel name (the - after local must be replaced with _).

@uranusjr
Copy link
Member Author

uranusjr commented Nov 3, 2020

LOL it turns out pkg_resources (and therefore pip) can’t even handle 0.1.0+local-1 correctly.

import importlib.metadata
import subprocess
import sys
import pkg_resources
from tests.lib.wheel import make_wheel

# Metadata uses dash, filename uses dot.
whl = 'simple-0.1.0+local.1-py3-none-any.whl'
make_wheel('simple', '0.1.0+local-1').save_to(whl)

# Install it.
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', f'./{whl}'])

# Prints '0.1.0+local-1' correctly.
print(importlib.metadata.version('simple'))

# Prints '0.1.0+local'... Huh?
print(pkg_resources.working_set.by_key['simple'].version)

When can we switch to importlib.metadata?

@uranusjr uranusjr force-pushed the new-resolver-version-comparison-normalize branch from 00f9234 to d08b4d9 Compare November 3, 2020 08:04
@uranusjr
Copy link
Member Author

uranusjr commented Nov 3, 2020

Test added. I adapted Paul’s implementation to use tests.lib.wheel.make_wheel() for finer control of version string in METADATA and the wheel’s file name.

@pradyunsg
Copy link
Member

When can we switch to importlib.metadata?

ASAP. Let's get 20.3 out the door and yank out entire bits of pip's codebase. :)

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.

pip 20.3b1 bug with --pre for already installed package
4 participants