-
Notifications
You must be signed in to change notification settings - Fork 338
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
New apis for downloading #2695
New apis for downloading #2695
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
Some missing things
-
this really needs to be tested in the c++ tests as once plugged it will be a fundamental piece of the whole library. I understand it is not easy to test because it's using curl internally and this cannot be replaced by some networking fake api, but maybe we can at least test with files in local directory?
-
documentation of the types and functions apis in core/download.hpp
@@ -134,6 +134,8 @@ namespace mamba | |||
int retry_timeout{ 2 }; // seconds | |||
int retry_backoff{ 3 }; // retry_timeout * retry_backoff | |||
int max_retries{ 3 }; // max number of retries | |||
|
|||
std::map<std::string, std::string> proxy_servers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider std::unordered_map
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this member from somewhere else, changing the type for an unordered_map
requires many changes in the configuration, let's do this in a dedicated PR to unordered_map.
{ | ||
struct TransferData | ||
{ | ||
int http_status; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= 0;
?
|
||
struct DownloadProgress | ||
{ | ||
std::size_t downloaded_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= 0;
? and for the following member
|
||
struct DownloadOptions | ||
{ | ||
bool fail_fast; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please provide default values 🥲
|
||
MultiDownloadResult download(MultiDownloadRequest requests, | ||
const Context& context, | ||
DownloadOptions options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider setting DownloadOptions options = {}
for quick default usage?
libmamba/src/core/download.cpp
Outdated
void Downloader::prepare_next_downloads() | ||
{ | ||
size_t running_attempts = m_completion_map.size(); | ||
size_t max_parallel_downloads = p_context->threads_params.download_threads; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
if (!msg.m_transfer_done) | ||
{ | ||
// We are only interested in messages about finished transfers | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does pop_message()
handles the waiting of the current thread? I would use std::yield()
here otherwise, to avoid saturating the cpu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope this should be done in m_curl_handle->perform()
actually, which is missing from this function.
libmamba/src/core/download.cpp
Outdated
|
||
MultiDownloadResult Downloader::build_result() const | ||
{ | ||
DownloadResultList l; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please avoid 1 letters or abreviations names in non-maths code🥲
libmamba/src/core/download_impl.hpp
Outdated
using on_success_callback = std::function<bool(DownloadSuccess)>; | ||
using on_failure_callback = std::function<bool(DownloadError)>; | ||
|
||
DownloadAttempt(CURLHandle& handle, const DownloadRequest* request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As pointed before, request should be taken by const reference, passing nullptr should not be authorized.
libmamba/src/core/download_impl.hpp
Outdated
using completion_function = DownloadAttempt::completion_function; | ||
using completion_map_entry = std::pair<CURLId, completion_function>; | ||
|
||
DownloadTracker(const DownloadRequest* request, std::size_t max_retries, bool fail_fast); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same remark about request should be a const ref here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also to avoid the bool in the interface of DownloadTRacker, consider grouping both value arguments in a DownloadTrackerOptions struct with them and default values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I did it in the first version but I found it a bit overkilled for only two members. I will reintroduce it, I agree the boolean here is kind of ugly.
e569e3c
to
af525f8
Compare
86ee5d8
to
100efba
Compare
@@ -578,6 +577,7 @@ PYBIND11_MODULE(bindings, m) | |||
.def_readwrite("retry_backoff", &Context::RemoteFetchParams::retry_backoff) | |||
.def_readwrite("user_agent", &Context::RemoteFetchParams::user_agent) | |||
// .def_readwrite("read_timeout_secs", &Context::RemoteFetchParams::read_timeout_secs) | |||
.def_readwrite("proxy_servers", &Context::RemoteFetchParams::proxy_servers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, if we still want backward compatibility with python API, we need to add something like this:
https://github.com/mamba-org/mamba/blob/main/libmambapy/src/main.cpp#L605-L621
58a5ba9
to
27dc742
Compare
@@ -188,6 +188,7 @@ jobs: | |||
shell: bash -l {0} | |||
run: | | |||
pybind11-stubgen libmambapy.bindings | |||
pre-commit run --files stubs/libmambapy/binginds-stubds/__init__.pyi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a typo? binginds-stubds -> bindings-stubs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes definitely! Thanks for catching it ;)
* New apis for downloading * Changes according to review * Added minimal test and fixed issues * Python backward compatibility
No description provided.