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

Allow users to disable progress bars #612

Open
simonhatcher opened this issue Jun 25, 2024 · 3 comments
Open

Allow users to disable progress bars #612

simonhatcher opened this issue Jun 25, 2024 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@simonhatcher
Copy link

Please add an optional argument to earthaccess.open to disable PQDM progress bars. The progress bars clog up my Jupyter notebook output very badly.

@simonhatcher simonhatcher changed the title Disable PQDM Disable PQDM in earthaccess.open Jun 25, 2024
@jhkennedy
Copy link
Collaborator

@simonhatcher I agree it's a good idea to provide this control.

For now, since pqdm wraps tqdm, I believe you can set this environment variable to disable the progress bars. You can do this in a shell beforehand:

export TQDM_DISABLE=1

Or in Python ahead of any TQDM imports:

import os

os.environ["TQDM_DISABLE"] = "1"

The environment variable requires tqdm v4.66.0+, but you can also hack it for older versions ahead of any TQDM imports like:

from tqdm import tqdm
from functools import partialmethod

tqdm.__init__ = partialmethod(tqdm.__init__, disable=True)

@mfisher87 mfisher87 added the enhancement New feature or request label Jun 25, 2024
@simonhatcher
Copy link
Author

@jhkennedy Thank you! That does work, but the one challenge is that I'm using TQDM elsewhere and I don't want to globally disable it in the long run.

@mfisher87 mfisher87 changed the title Disable PQDM in earthaccess.open Allow users to disable progress bars Jun 25, 2024
@mfisher87 mfisher87 added the good first issue Good for newcomers label Jun 25, 2024
@jhkennedy
Copy link
Collaborator

That does work, but the one challenge is that I'm using TQDM elsewhere and I don't want to globally disable it in the long run.

yes, definitely exactly why we should provide a way to disable it for Earthaccess.

🤔 I think you could write a context manager that would disable it temporarily... but that's getting to be a lot. Something like (I'm sure there are much cleaner ways to do this):

from tqdm import tqdm
from functools import partialmethod

class DisableTqdm(object):
    def __init__(self):
        self._tqdm_init = tqdm.__init__
        
    def __enter__(self):
        tqdm.__init__ = partialmethod(tqdm.__init__, disable=True)
        
    def __exit__(self, type, value, traceback):
        tqdm.__init__ = self._tqdm_init
        
with DisableTqdm():
    # Do stuff
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Status: 🆕 New
Development

No branches or pull requests

3 participants