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 #1664: Include path in error message when version is missing #1706

Merged

Conversation

cjerdonek
Copy link
Member

Fixes #1664.

@cjerdonek
Copy link
Member Author

cjerdonek commented Feb 24, 2019

@pypa/setuptools-developers On this PR, would you be okay with me making also the argument passed to ValueError be a single string instead of the two arguments ValueError(msg, self)?

tmpl = "Missing 'Version:' header and/or %s file"
raise ValueError(tmpl % self.PKG_INFO, self)

This will make the exception easier to read for users because it won't introduce additional escaping of slashes in the path due to calling repr() on the string.

@pganssle
Copy link
Member

Thanks for this PR; I haven't had a chance to review it carefully though, but it looks very thorough!

On this PR, would you be okay with me making also the argument passed to ValueError be a single string instead of the two arguments ValueError(msg, self)?

Hm, I find it a little weird when errors set an args tuple instead of a string as the message anyway, so I don't have a big problem with changing it conceptually, the question is whether anyone is using the fact that it currently raises a tuple?

Might be a little overboard, but maybe we could do this for "best of both worlds"?

class MissingVersionError(ValueError):
    def __repr__(self):
        return "%s(%s, %s)" % (self.__class__.name + self.args)

Haven't looked at this too much, maybe it should be something like InvalidMetadataError instead, but you get my drift - keep the result of .args the same and make the REPR look however you want.

@cjerdonek
Copy link
Member Author

Okay, thanks, @pganssle. I'll think about it what I can do here to preserve that aspect, along the lines you suggest.

I was already planning to propose a new ValueError exception type as a follow-on PR (because it would e.g. let pip handle errors more gracefully without having to risk catching all ValueError objects). It requires a bit more consideration which is why I wanted to propose it separately, but I can start thinking about that here.

@cjerdonek cjerdonek force-pushed the issue-1664-include-metadata-location branch from 0ed96f2 to af2eb35 Compare February 25, 2019 11:10
@cjerdonek
Copy link
Member Author

cjerdonek commented Feb 25, 2019

Okay, I gave this a bit of thought. To keep the scope of this PR limited, I'll keep everything the same here like the type of the args passed to ValueError and only add the path to the string portion (as in my original PR). In a follow-on PR we can discuss and settle on creating a new exception type (since that will involve some bikeshedding, etc).

In the meantime, I adjusted the tests I created to also check that the args passed to ValueError have the expected type (str for the first one, and a particular Distribution sub-type for the second one). Those tests will come in handy for the follow-on PR.

How does that sound?

@cjerdonek cjerdonek force-pushed the issue-1664-include-metadata-location branch 3 times, most recently from e0928af to f1c7d2a Compare February 25, 2019 13:15
@pganssle
Copy link
Member

@cjerdonek I'm fine with either thing, tightly scoped PR or bigger one. I think your proposed course of action is prudent.

It seems like there's a test failure on Windows. Hard for me to tell what's going on there, but I think it's related to the fact that windows uses backslashes for path separators, and if you're testing against the repr, you're getting something double-escaped.

@cjerdonek cjerdonek force-pushed the issue-1664-include-metadata-location branch 2 times, most recently from e461e21 to d737332 Compare February 25, 2019 17:34
@cjerdonek
Copy link
Member Author

It seems like there's a test failure on Windows.

Oops, it was working before, and I didn't check after my last force-push. (I had reversed two positional arguments metadata_path and expected_text when calling check_version_missing().)

It is ready now.

Copy link
Member

@pganssle pganssle left a comment

Choose a reason for hiding this comment

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

This seems like a lot of internal changes for a fairly minor convenience feature, but I do think a lot of what you have done is just a bit of refactoring of existing methods in a way that is independent of the necessary change (boy scout rule), so I think that's mostly fine.

Other than that, I have left a few specific comments in-line. Sorry for the delay in this review.

pkg_resources/__init__.py Outdated Show resolved Hide resolved
pkg_resources/__init__.py Outdated Show resolved Hide resolved
pkg_resources/tests/test_pkg_resources.py Show resolved Hide resolved
pkg_resources/tests/test_pkg_resources.py Outdated Show resolved Hide resolved
pkg_resources/tests/test_pkg_resources.py Outdated Show resolved Hide resolved
pkg_resources/tests/test_pkg_resources.py Outdated Show resolved Hide resolved
pkg_resources/tests/test_pkg_resources.py Outdated Show resolved Hide resolved
@cjerdonek cjerdonek force-pushed the issue-1664-include-metadata-location branch from 4b84ef7 to 0764bfb Compare March 7, 2019 17:00
@cjerdonek
Copy link
Member Author

Thanks for all of your comments, @pganssle. I've updated the PR with all of your suggested changes.

@cjerdonek
Copy link
Member Author

Hi @pganssle, just pinging you on this. I answered the question that you asked before, and also included another test case in response to your question.

Copy link
Member

@pganssle pganssle left a comment

Choose a reason for hiding this comment

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

OK, this looks good. I would like to re-word the changelog a bit, but I'll do that as part of the merge. Thanks @cjerdonek and sorry again for the delay in approving/merging this.

@pganssle pganssle force-pushed the issue-1664-include-metadata-location branch from 01565aa to 33f7e98 Compare March 31, 2019 22:07
@cjerdonek
Copy link
Member Author

cjerdonek commented Mar 31, 2019

You might want to reference #6177 and/or #6283 on pip’s tracker as well.

@pganssle pganssle force-pushed the issue-1664-include-metadata-location branch from 33f7e98 to e92f16f Compare March 31, 2019 22:30
@pganssle
Copy link
Member

pganssle commented Mar 31, 2019

@cjerdonek Thanks, updated the commit message. Not sure why the pypy job is failing. Seems unrelated? Hopefully restarting the job enough times will work.

@cjerdonek
Copy link
Member Author

Yes, seems unrelated. Are other PR’s failing?

@cjerdonek
Copy link
Member Author

Could the PR need to be rebased? (not sure if master is auto-merged prior to running tests)

@pganssle
Copy link
Member

@cjerdonek I rebased it when I was messing around with the commit history, though I think Travis does auto-merge the base branch if possible.

I have occasionally seen intermittent multi-threading issues like this in pypy in the past. I seem to remember that they were resolved upstream, though, so maybe this is something different.

Related to pip's github issue pypa/pip#6194.

This has come up in pip's issue tracker (github) multiple times:

  - pypa/pip#6177
  - pypa/pip#6283
  - pypa/pip#6194
@pganssle pganssle force-pushed the issue-1664-include-metadata-location branch from e92f16f to 80ec85c Compare April 3, 2019 14:37
@pganssle pganssle merged commit 8d4e4bc into pypa:master Apr 3, 2019
@pganssle
Copy link
Member

pganssle commented Apr 3, 2019

Thanks @cjerdonek, sorry for the delays and that last hiccup!

@cjerdonek
Copy link
Member Author

Thank you, @pganssle! 🎉This will help users a lot by letting them quickly locate and diagnose problematic installs.

@cjerdonek cjerdonek deleted the issue-1664-include-metadata-location branch April 3, 2019 14:59
@pganssle
Copy link
Member

pganssle commented Apr 3, 2019

@cjerdonek This is included in the 40.9.0 release - hot off the presses!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants