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

feature: add support for non-tqdm arbitrary progress bars for HTTPDownloader #228

Merged
merged 5 commits into from
May 8, 2021

Conversation

neutrinoceros
Copy link
Contributor

@neutrinoceros neutrinoceros commented Mar 8, 2021

Hi ! here's a patch with minimal changes required to make the downloaders accept an arbitrary "progress bar" object from outside of pooch, making tqdm not the only way to display progress. In particular, this allows users to create custom progress bars with rich. The reason I'm doing this is that there are a lot of places in the project I maintain use progress bars (and the pooch downloader is one of them), and I want them to have a visual consistency.

I'm opening as a draft for now because I need to work a little more to figure out a proper way to expose the total computation, since it would be useful to properly define a progress from outside pooch.
I may need help to write tests (or update the existing ones) for this, but I tested it for HTTPDownloader on the project I'm maintaining (https://github.com/yt-project/yt).

Here's a screenshot of it in action
Screenshot 2021-03-08 at 18 51 41

I'll try to come up with a simple example of arbitrary progress bar class to contribute to docs later.

Reminders:

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • (NA) Add new public functions/methods/classes to doc/api/index.rst and the base __init__.py file for the package.
  • Write detailed docstrings for all functions/classes/methods. It often helps to design better code if you write the docstrings first.
  • If adding new functionality, add an example to the docstring, gallery, and/or tutorials.
  • Add your full name, affiliation, and ORCID (optional) to the AUTHORS.md file (if you haven't already) in case you'd like to be listed as an author on the Zenodo archive of the next release.

@welcome
Copy link

welcome bot commented Mar 8, 2021

💖 Thanks for opening your first pull request! 💖

Please make sure you read the following:

  • Authorship Guidelines: Our rules for giving you credit for your contributions, including authorship on publications and Zenodo archives.
  • Contributing Guide: What the review process is like and our infrastructure for testing and documentation.
  • Code of Conduct: How we expect people to interact in our projects.

A few things to keep in mind:

  • Remember to run make format to make sure your code follows our style guide.
  • If you need help writing tests, take a look at the existing ones for inspiration. If you don't know where to start, let us know and we'll walk you through it.
  • All new features should be documented. It helps to write the docstrings for your functions/classes before writing the code. This will help you think about your code design and results in better code.
  • No matter what, we are really grateful that you put in the effort to do this! ⭐

@neutrinoceros neutrinoceros force-pushed the arbitrary_progressbars branch 4 times, most recently from 7291308 to f22484f Compare March 9, 2021 22:35
@neutrinoceros neutrinoceros marked this pull request as ready for review March 9, 2021 22:35
@neutrinoceros neutrinoceros force-pushed the arbitrary_progressbars branch 2 times, most recently from 2825da0 to d36a13a Compare March 9, 2021 22:58
@neutrinoceros neutrinoceros changed the title feature: add support for non-tqdm arbitrary progress bars and docs feature: add support for non-tqdm arbitrary progress bars Mar 9, 2021
@neutrinoceros
Copy link
Contributor Author

neutrinoceros commented Mar 9, 2021

Apparently there's exactly one line I'm not hitting but I can't figure out which one and I can't access the codecov report for some reason.
edit: got it !
I'm now restricting the change for the HTTPDownloader class because things get more complicated with SFTPDownloader

@neutrinoceros neutrinoceros changed the title feature: add support for non-tqdm arbitrary progress bars feature: add support for non-tqdm arbitrary progress bars for HTTPDownloader Mar 9, 2021
@leouieda
Copy link
Member

👋🏽 Hi @neutrinoceros thanks for the PR! This looks nice a great addition. I'm a bit strapped for time at the moment so this may take a little while to be merged. I hope that's OK.

A few quick questions:

  1. Did you make up the spec for the progress bar class or is that what is used by other libraries? It would be nice if we didn't create our own spec for this to help with interoperability.
  2. Would this work if we pass in a tqdm instance? If so, then it would be nice to have a test for that.

@neutrinoceros
Copy link
Contributor Author

Thanks for getting back to me !
There's no rush on my side, take your time.

The specs are designed around tqdm's api to allow more flexibility in pooch with minimal change. Basically I'm going with a duck typing approach : if it looks, feels and tastes like a tqdm pbar, we can treat it as if it was, transparently and without creating much technical debt on your side.

Other libraries use slightly different method names as far as I can tell (The ones I have personally studied are tqdm and rich.progress), but it's only a matter of wrapping them with a little syntactic sugar to make them compatible.
In my own application for this, I wrapped a rich progress bar in a small custom class to make it look like tqdm and it worked :)

Copy link
Member

@leouieda leouieda left a comment

Choose a reason for hiding this comment

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

Great stuff @neutrinoceros (and awesome handle)! Left a few suggestions, mostly for the docs. Otherwise, this seems to work like a charm 👍🏽

doc/intermediate.rst Outdated Show resolved Hide resolved
doc/intermediate.rst Outdated Show resolved Hide resolved
doc/intermediate.rst Show resolved Hide resolved
pooch/downloaders.py Outdated Show resolved Hide resolved
pooch/downloaders.py Outdated Show resolved Hide resolved
self.count = 0

def close(self):
print("", file=sys.stderr)
Copy link
Member

Choose a reason for hiding this comment

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

Could you add an example using this class with HTTPDownloader?

Copy link
Member

Choose a reason for hiding this comment

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

Might also be good to add a .. note: here saying that this only available for HTTPDownloader for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done !

doc/intermediate.rst Show resolved Hide resolved
@neutrinoceros
Copy link
Contributor Author

Thanks for your careful review ! I'll go back to this in a few days.

@leouieda leouieda mentioned this pull request May 5, 2021
30 tasks
@leouieda leouieda merged commit 609d22a into fatiando:master May 8, 2021
@welcome
Copy link

welcome bot commented May 8, 2021

🎉🎉🎉 Congrats on merging your first pull request and welcome to the team! 🎉🎉🎉

If you would like to be added as a author on the Zenodo archive of the next release, make sure that you have added your full name, affiliation, and ORCID (optional) to the AUTHORS.md file of this repository.

We hope that this was a good experience for you. Let us know if there is any way that the contributing process could be improved.

@leouieda
Copy link
Member

leouieda commented May 8, 2021

@neutrinoceros thank you for the contribution! I made a few minor edits to the docs but this is looking really good.

@neutrinoceros
Copy link
Contributor Author

Glad you like it ! Thank you for your support in getting this to the finish line. Do you intend to release it in the same go or should I except a delay ? I'm good with either way :)

@leouieda
Copy link
Member

leouieda commented May 8, 2021

I'm just going to push some updates to the docs and then make a release. It should be out within the next few weeks.

@neutrinoceros neutrinoceros deleted the arbitrary_progressbars branch May 8, 2021 16:25
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.

2 participants