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

New apis for downloading #2695

Merged
merged 4 commits into from
Aug 23, 2023
Merged

New apis for downloading #2695

merged 4 commits into from
Aug 23, 2023

Conversation

JohanMabille
Copy link
Member

No description provided.

Copy link
Member

@Klaim Klaim left a 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

  1. 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?

  2. 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;
Copy link
Member

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?

Copy link
Member Author

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;
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

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?

void Downloader::prepare_next_downloads()
{
size_t running_attempts = m_completion_map.size();
size_t max_parallel_downloads = p_context->threads_params.download_threads;
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member Author

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.


MultiDownloadResult Downloader::build_result() const
{
DownloadResultList l;
Copy link
Member

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🥲

using on_success_callback = std::function<bool(DownloadSuccess)>;
using on_failure_callback = std::function<bool(DownloadError)>;

DownloadAttempt(CURLHandle& handle, const DownloadRequest* request);
Copy link
Member

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.

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);
Copy link
Member

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

Copy link
Member

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.

Copy link
Member Author

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.

@JohanMabille JohanMabille force-pushed the download branch 7 times, most recently from e569e3c to af525f8 Compare July 28, 2023 14:08
@JohanMabille JohanMabille marked this pull request as ready for review July 28, 2023 14:09
@JohanMabille JohanMabille force-pushed the download branch 2 times, most recently from 86ee5d8 to 100efba Compare July 28, 2023 14:14
@@ -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)
Copy link
Member

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

@JohanMabille JohanMabille force-pushed the download branch 4 times, most recently from 58a5ba9 to 27dc742 Compare August 22, 2023 13:46
@JohanMabille JohanMabille merged commit 6e4d91e into mamba-org:main Aug 23, 2023
29 checks passed
@JohanMabille JohanMabille deleted the download branch August 23, 2023 07:07
@@ -188,6 +188,7 @@ jobs:
shell: bash -l {0}
run: |
pybind11-stubgen libmambapy.bindings
pre-commit run --files stubs/libmambapy/binginds-stubds/__init__.pyi
Copy link
Member

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?

Copy link
Member Author

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 ;)

cvanelteren pushed a commit to cvanelteren/mamba that referenced this pull request Aug 29, 2023
* New apis for downloading

* Changes according to review

* Added minimal test and fixed issues

* Python backward compatibility
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

4 participants