Skip to content

Commit

Permalink
Add arg to mute progress bars (#844)
Browse files Browse the repository at this point in the history
* Add arg to mute progress bars

* Linting
  • Loading branch information
Jason Munro authored Sep 12, 2023
1 parent 63adcdf commit ffd9713
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mp_api/client/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
# TODO: think about how to migrate from PMG_MAPI_KEY
DEFAULT_API_KEY = environ.get("MP_API_KEY", None)
DEFAULT_ENDPOINT = environ.get("MP_API_ENDPOINT", "https://api.materialsproject.org/")
settings = MAPIClientSettings()

T = TypeVar("T")

Expand All @@ -70,6 +71,7 @@ def __init__(
use_document_model: bool = True,
timeout: int = 20,
headers: dict = None,
mute_progress_bars: bool = settings.MUTE_PROGRESS_BARS,
):
"""Args:
api_key (str): A String API key for accessing the MaterialsProject
Expand Down Expand Up @@ -107,6 +109,7 @@ def __init__(
self.use_document_model = use_document_model
self.timeout = timeout
self.headers = headers or {}
self.mute_progress_bars = mute_progress_bars

if self.suffix:
self.endpoint = urljoin(self.endpoint, self.suffix)
Expand Down Expand Up @@ -632,7 +635,7 @@ def _submit_requests(
desc=pbar_message,
total=num_docs_needed,
)
if not MAPIClientSettings().MUTE_PROGRESS_BARS
if not self.mute_progress_bars
else None
)

Expand Down
6 changes: 6 additions & 0 deletions mp_api/client/mprester.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def __init__(
use_document_model: bool = True,
session: Session = None,
headers: dict = None,
mute_progress_bars: bool = _MAPI_SETTINGS.MUTE_PROGRESS_BARS,
):
"""Args:
api_key (str): A String API key for accessing the MaterialsProject
Expand Down Expand Up @@ -162,6 +163,7 @@ def __init__(
and will not give auto-complete for available fields.
session (Session): Session object to use. By default (None), the client will create one.
headers (dict): Custom headers for localhost connections.
mute_progress_bars (bool): Whether to mute progress bars.
"""
if api_key and len(api_key) != 32:
raise ValueError(
Expand All @@ -180,6 +182,7 @@ def __init__(
)
self.use_document_model = use_document_model
self.monty_decode = monty_decode
self.mute_progress_bars = mute_progress_bars

self._deprecated_attributes = [
"eos",
Expand Down Expand Up @@ -269,6 +272,7 @@ def __init__(
monty_decode=monty_decode,
use_document_model=use_document_model,
headers=self.headers,
mute_progress_bars=self.mute_progress_bars,
)
for cls in self._all_resters
if cls.suffix in core_suffix
Expand All @@ -293,6 +297,7 @@ def __init__(
else False, # Disable monty decode on nested data which may give errors
use_document_model=use_document_model,
headers=self.headers,
mute_progress_bars=self.mute_progress_bars,
) # type: BaseRester
setattr(
self,
Expand Down Expand Up @@ -320,6 +325,7 @@ def __core_custom_getattr(_self, _attr, _rester_map):
else False, # Disable monty decode on nested data which may give errors
use_document_model=use_document_model,
headers=self.headers,
mute_progress_bars=self.mute_progress_bars,
) # type: BaseRester

setattr(
Expand Down

0 comments on commit ffd9713

Please sign in to comment.