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

Fix crashes with higher logging levels #10537

Merged
merged 1 commit into from
Dec 5, 2021

Conversation

pradyunsg
Copy link
Member

This can be reproduced just by running the test suite locally, for me -- though I haven't been able to identify what in my new setup is different. 🤷🏽

_________________________________________ test_finder_installs_pre_releases_with_version_spec _________________________________________
[gw6] darwin -- Python 3.9.6 /Users/pradyunsg/Developer/pip/.nox/test-3-9/bin/python

    def test_finder_installs_pre_releases_with_version_spec() -> None:
        """
        Test PackageFinder only accepts stable versioned releases by default.
        """
        req = install_req_from_line("bar>=0.0.dev0", None)
        links = ["https://foo/bar-1.0.tar.gz", "https://foo/bar-2.0b1.tar.gz"]
    
        finder = make_test_finder(links)
>       found = finder.find_requirement(req, False)

tests/unit/test_finder.py:461: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.nox/test-3-9/lib/python3.9/site-packages/pip/_internal/index/package_finder.py:875: in find_requirement
    best_candidate_result = self.find_best_candidate(
.nox/test-3-9/lib/python3.9/site-packages/pip/_internal/index/package_finder.py:857: in find_best_candidate
    candidates = self.find_all_candidates(project_name)
.nox/test-3-9/lib/python3.9/site-packages/pip/_internal/index/package_finder.py:819: in find_all_candidates
    paths = [url_to_path(c.link.url) for c in file_candidates]
.nox/test-3-9/lib/python3.9/site-packages/pip/_internal/index/package_finder.py:819: in <listcomp>
    paths = [url_to_path(c.link.url) for c in file_candidates]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

url = 'https://foo/bar-2.0b1.tar.gz'

    def url_to_path(url: str) -> str:
        """
        Convert a file: URL to a path.
        """
>       assert url.startswith(
            "file:"
        ), f"You can only turn file: urls into filenames (not {url!r})"
E       AssertionError: You can only turn file: urls into filenames (not 'https://foo/bar-2.0b1.tar.gz')

.nox/test-3-9/lib/python3.9/site-packages/pip/_internal/utils/urls.py:30: AssertionError

Anyway, this fixes my test runs locally on nox -s test-3.9 -- -n auto, which... it would be nice to have that. :)

@pradyunsg pradyunsg added C: tests Testing and related things skip news Does not need a NEWS file entry (eg: trivial changes) labels Oct 3, 2021
@pradyunsg
Copy link
Member Author

Given that this is debugging logic, I'm not super inclined to add both adds tests for this -- mostly because I'm able to produce this without any special flags on the current main branch.

@uranusjr
Copy link
Member

uranusjr commented Oct 6, 2021

Higher verbose level, lower log level 🙂

This was causing issues in running the test suite locally at higher
verbosity levels, since this block causes errors when passed a URL.
Comment on lines +821 to +824
try:
paths.append(candidate.link.file_path)
except Exception:
paths.append(candidate.link.url) # it's not a local file
Copy link
Member

Choose a reason for hiding this comment

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

Why not just always log a URL instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Logging the filename is clearer, IMO.

@pradyunsg pradyunsg merged commit bbc7021 into pypa:main Dec 5, 2021
@pradyunsg pradyunsg deleted the fix-misbehaving-test branch December 5, 2021 11:55
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C: tests Testing and related things skip news Does not need a NEWS file entry (eg: trivial changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants