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

#6349 Add support for mirror when downloading files #6679

Merged
merged 21 commits into from Mar 24, 2020

Conversation

uilianries
Copy link
Member

@uilianries uilianries commented Mar 13, 2020

Changelog: Feature: Support mirrors for tools.download and tools.get.
Docs: conan-io/docs#1623

This PR follows the instructions described in #6349 (comment)

Updated the follow methods:

  • tools.download
  • tools.get
  • tools.ftp_download

closes #6349
closes #6246

  • Refer to the issue that supports this Pull Request.
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

Note: By default this PR will skip the slower tests and will use a limited set of python versions. Check here how to increase the testing level by writing some tags in the current PR body text.

uilianries added 2 commits Mar 13, 2020
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries uilianries changed the title Add support for mirror when downloading files #6349 Add support for mirror when downloading files Mar 13, 2020
uilianries added 3 commits Mar 13, 2020
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries uilianries marked this pull request as ready for review Mar 16, 2020
uilianries added 2 commits Mar 16, 2020
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries
Copy link
Member Author

@uilianries uilianries commented Mar 16, 2020

@memsharded the #6679 is ready for review!

conans/client/tools/net.py Outdated Show resolved Hide resolved
conans/client/tools/net.py Outdated Show resolved Hide resolved
conans/client/tools/net.py Outdated Show resolved Hide resolved
conans/test/unittests/util/tools_test.py Outdated Show resolved Hide resolved
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Copy link
Member

@jgsogo jgsogo left a comment

IMO we should allow only one checksum, the same for all the URLs. If you think that's not the case, you will need to convince me 🛡 My point is that it is required to talk about traceability and reproducibility.

conans/client/tools/net.py Outdated Show resolved Hide resolved
conans/test/unittests/util/tools_test.py Outdated Show resolved Hide resolved
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries
Copy link
Member Author

@uilianries uilianries commented Mar 19, 2020

@jgsogo please, take a look again. Now the same checksum should work for all urls. Also, I mocked the Requester, so we don't need the server anymore. Thanks for the idea, it's much simpler now.

conans/client/tools/net.py Outdated Show resolved Hide resolved
conans/test/unittests/util/tools_test.py Outdated Show resolved Hide resolved
uilianries and others added 2 commits Mar 19, 2020
Co-Authored-By: Javier G. Sogo <jgsogo@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
conans/client/tools/net.py Outdated Show resolved Hide resolved
conans/test/unittests/util/tools_test.py Show resolved Hide resolved
uilianries added 2 commits Mar 19, 2020
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@jgsogo jgsogo added this to the 1.24 milestone Mar 20, 2020
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Copy link
Member

@jgsogo jgsogo left a comment

A couple of suggestions

conans/client/tools/net.py Outdated Show resolved Hide resolved
conans/client/tools/net.py Outdated Show resolved Hide resolved
out.warn("Could not download from the url {}.".format(url_it))
if (index + 1) == len(url):
raise ConanException("All {} URLs have failed: {}.".format(len(url),
str(error)))
Copy link
Member

@jgsogo jgsogo Mar 23, 2020

Choose a reason for hiding this comment

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

This is the typical use-case for a for/else loop, but I'm not sure if we want that logic in the codebase.

Copy link
Member

@memsharded memsharded Mar 23, 2020

Choose a reason for hiding this comment

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

I think every failed URL should output the error message too. And the last one, maybe just raise the exception it got?

Copy link
Member Author

@uilianries uilianries Mar 23, 2020

Choose a reason for hiding this comment

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

Almost it, but you point makes more sense. For now it raises a warning message, but I'll raise an error message, and a warning message the the retry.

@@ -122,7 +122,7 @@ def source(self):
""" % http_server.port)
client.save({"conanfile.py": conanfile})
client.run("source .", assert_error=True)
self.assertIn("ConanException: md5 signature failed", client.out)
self.assertIn("ConanException: All 1 URLs have failed: md5 signature failed", client.out)
Copy link
Member

@memsharded memsharded Mar 23, 2020

Choose a reason for hiding this comment

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

I don't like having this error message when you only provide 1 url, it makes the output a bit more confusing to the user.

Copy link
Member Author

@uilianries uilianries Mar 23, 2020

Choose a reason for hiding this comment

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

I see, I'll filter it raise a specific message when there is only one URL.

out.warn("Could not download from the url {}.".format(url_it))
if (index + 1) == len(url):
raise ConanException("All {} URLs have failed: {}.".format(len(url),
str(error)))
Copy link
Member

@memsharded memsharded Mar 23, 2020

Choose a reason for hiding this comment

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

I think every failed URL should output the error message too. And the last one, maybe just raise the exception it got?

uilianries and others added 4 commits Mar 23, 2020
Co-Authored-By: Javier G. Sogo <jgsogo@gmail.com>
Co-Authored-By: Javier G. Sogo <jgsogo@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries
Copy link
Member Author

@uilianries uilianries commented Mar 23, 2020

@memsharded I just updated the error messages, I think it's better now.

uilianries added 2 commits Mar 23, 2020
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries
Copy link
Member Author

@uilianries uilianries commented Mar 23, 2020

UPDATE: Updated documentation conan-io/docs#162

message = "Could not download from the URL {}: {}.".format(url_it, str(error))
if len(url) == 1:
raise ConanException(message)
out.error(message)
Copy link
Member

@jgsogo jgsogo Mar 24, 2020

Choose a reason for hiding this comment

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

One question about this line: will someone parse this ERROR as an actual error and think that the command has failed? Is it an error to fail with an URL when you have a mirror/fallback strategy? Printing something to stderr (we are not printing errors to stderr, should we?) is considered a failure from a CLI perspective?

wdyt, @memsharded @uilianries @czoido ?

Copy link
Member

@memsharded memsharded Mar 24, 2020

Choose a reason for hiding this comment

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

This is a very good point, indeed.
Probably should be a warning, not an error. Not a failure from CLI perspective, the command have succeeded if it was able to fallback to a mirror.

Copy link
Member Author

@uilianries uilianries Mar 24, 2020

Choose a reason for hiding this comment

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

Okay, I'll update it to warning level.

Copy link
Member

@jgsogo jgsogo left a comment

@uilianries , please, change the error to warn (#6679 (comment)), and we'll be done! 👍

Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries
Copy link
Member Author

@uilianries uilianries commented Mar 24, 2020

@jgsogo done, I've changed to warning level.

jgsogo
jgsogo approved these changes Mar 24, 2020
Copy link
Member

@jgsogo jgsogo left a comment

Thanks for the work here, @uilianries . And sorry for all the back and forth

@jgsogo jgsogo merged commit 7862db6 into conan-io:develop Mar 24, 2020
2 checks passed
@uilianries
Copy link
Member Author

@uilianries uilianries commented Mar 24, 2020

@jgsogo thank you for reviewing and making it better! 💪

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