From 63ea4661a3858f4b0506fa9a38272c66ca10b634 Mon Sep 17 00:00:00 2001 From: Patrick Huck Date: Wed, 11 Sep 2024 14:18:39 -0700 Subject: [PATCH 1/2] use bson.json_util.loads for S3 --- mp_api/client/core/client.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mp_api/client/core/client.py b/mp_api/client/core/client.py index ba6f0ad9..a59f6964 100644 --- a/mp_api/client/core/client.py +++ b/mp_api/client/core/client.py @@ -2,6 +2,7 @@ API v3 to enable the creation of data structures and pymatgen objects using Materials Project data. """ + from __future__ import annotations import itertools @@ -19,6 +20,7 @@ from math import ceil from typing import Any, Callable, Generic, TypeVar from urllib.parse import quote, urljoin +from bson import json_util import requests from emmet.core.utils import jsanitize @@ -176,9 +178,9 @@ def _create_session(api_key, include_user_agent, headers): mp_api_info = "mp-api/" + __version__ if __version__ else None python_info = f"Python/{sys.version.split()[0]}" platform_info = f"{platform.system()}/{platform.release()}" - session.headers[ - "user-agent" - ] = f"{mp_api_info} ({python_info} {platform_info})" + session.headers["user-agent"] = ( + f"{mp_api_info} ({python_info} {platform_info})" + ) settings = MAPIClientSettings() # type: ignore max_retry_num = settings.MAX_RETRIES @@ -494,7 +496,7 @@ def _query_resource( ) suffix = suffix.replace("_", "-") - # Paginate over all entried in the bucket. + # Paginate over all entries in the bucket. # This will have to change for when a subset of entries from # the DB is needed. is_tasks = "tasks" in suffix @@ -516,7 +518,9 @@ def _query_resource( if key: keys.append(key) - decoder = MontyDecoder().decode if self.monty_decode else json.loads + decoder = ( + MontyDecoder().decode if self.monty_decode else json_util.loads + ) # Multithreaded function inputs s3_params_list = { From 857ba32285e282d5e0fb214fe1dc08e1d51a1bd1 Mon Sep 17 00:00:00 2001 From: Patrick Huck Date: Wed, 11 Sep 2024 14:23:02 -0700 Subject: [PATCH 2/2] pre-commit fixes --- mp_api/client/core/client.py | 8 ++++---- mp_api/client/mprester.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mp_api/client/core/client.py b/mp_api/client/core/client.py index a59f6964..94183081 100644 --- a/mp_api/client/core/client.py +++ b/mp_api/client/core/client.py @@ -20,9 +20,9 @@ from math import ceil from typing import Any, Callable, Generic, TypeVar from urllib.parse import quote, urljoin -from bson import json_util import requests +from bson import json_util from emmet.core.utils import jsanitize from monty.json import MontyDecoder from pydantic import BaseModel, create_model @@ -178,9 +178,9 @@ def _create_session(api_key, include_user_agent, headers): mp_api_info = "mp-api/" + __version__ if __version__ else None python_info = f"Python/{sys.version.split()[0]}" platform_info = f"{platform.system()}/{platform.release()}" - session.headers["user-agent"] = ( - f"{mp_api_info} ({python_info} {platform_info})" - ) + session.headers[ + "user-agent" + ] = f"{mp_api_info} ({python_info} {platform_info})" settings = MAPIClientSettings() # type: ignore max_retry_num = settings.MAX_RETRIES diff --git a/mp_api/client/mprester.py b/mp_api/client/mprester.py index 53324145..3ccf7645 100644 --- a/mp_api/client/mprester.py +++ b/mp_api/client/mprester.py @@ -1378,7 +1378,9 @@ def get_charge_density_from_material_id( if self.use_document_model else x["last_updated"], # type: ignore ) - task_id = latest_doc.task_id if self.use_document_model else latest_doc["task_id"] + task_id = ( + latest_doc.task_id if self.use_document_model else latest_doc["task_id"] + ) return self.get_charge_density_from_task_id(task_id, inc_task_doc) def get_download_info(self, material_ids, calc_types=None, file_patterns=None):