Skip to content

Make --skip-existing more robust#510

Merged
sigmavirus24 merged 12 commits intopypa:masterfrom
bhrutledge:robust-skip-existing
Oct 21, 2019
Merged

Make --skip-existing more robust#510
sigmavirus24 merged 12 commits intopypa:masterfrom
bhrutledge:robust-skip-existing

Conversation

@bhrutledge
Copy link
Copy Markdown
Contributor

Fixes #332.

I realize that checking for strings in the response is still brittle, but given the APIs that we support, I don't see how to avoid it. And, the issue said "less brittle". :)

I didn't spend much time on the tests; just copy-pasted from similar tests. Happy to refactor or tidy up.

@bhrutledge bhrutledge requested review from di and sigmavirus24 October 7, 2019 10:40
@codecov

This comment has been minimized.

@bhrutledge
Copy link
Copy Markdown
Contributor Author

I'm surprised by the codecov failure; will investigate.

Comment thread twine/commands/upload.py Outdated
@bhrutledge bhrutledge requested review from di and jaraco October 13, 2019 10:59
@bhrutledge
Copy link
Copy Markdown
Contributor Author

I think this is all set. I made the checks more flexible and readable, fixed the missing coverage due to an incorrect test, and took the opportunity to parametrize tests.

Copy link
Copy Markdown
Member

@di di left a comment

Choose a reason for hiding this comment

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

Just one small nit.

Comment thread twine/commands/upload.py Outdated
@bhrutledge
Copy link
Copy Markdown
Contributor Author

@pypa/twine-maintainers Is it okay if I merge this? I believe it'd be my first merge of a code change, and even though "squash and merge" would be easy to undo, I thought it'd be better to ask permission than forgiveness. 😉

Comment thread twine/commands/upload.py Outdated
response.reason.startswith(msg_400)) or
(response.status_code == 403 and msg_403 in response.text)))
# 403 or 409 status code.
return any([
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So in this case, we generate a list before we can call any which can otherwise be lazy. What if, we choose a lazier way to implement this given tat in with strings can be slow and people expect their CLIs to be quick. (Especially considering text can be a giant HTML page and really really slow to scan through.) In that case, I'd prefer if this looked like:

conditions = [(400, 'already exist', reason), (400, 'updating asset', reason), (403, 'overwrite artifact', text)]
return status == 409 or any(status == status_code and search_for in string for (status_code, search_for, string) in conditions)

any will consume the generator and then we won't unnecessarily scan through a potentially giant document every time we see a 403

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @sigmavirus24. I'm usually all about laziness; just missed it here. I took a different approach in e366401 (that's actually similar to the prior implementation).

@sigmavirus24 sigmavirus24 merged commit 14b2dc1 into pypa:master Oct 21, 2019
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.

Make --skip-existing less brittle

3 participants