Skip to content

Commit

Permalink
Switch user-agent to mp-api version (#874)
Browse files Browse the repository at this point in the history
* Switch user-agent to mp-api version

* Linting
  • Loading branch information
Jason Munro authored Dec 4, 2023
1 parent 39eb023 commit 5351c9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions mp_api/client/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import gzip
import itertools
import json
import os
import platform
import sys
import warnings
from concurrent.futures import FIRST_COMPLETED, ThreadPoolExecutor, wait
from copy import copy
from importlib.metadata import PackageNotFoundError, version
from json import JSONDecodeError
from math import ceil
from os import environ
Expand All @@ -38,10 +40,9 @@
boto3 = None

try:
from pymatgen.core import __version__ as pmg_version # type: ignore
except ImportError: # pragma: no cover
# fallback to root-level import for older pymatgen versions
from pymatgen import __version__ as pmg_version # type: ignore
__version__ = version("mp_api")
except PackageNotFoundError: # pragma: no cover
__version__ = os.getenv("SETUPTOOLS_SCM_PRETEND_VERSION")

# TODO: think about how to migrate from PMG_MAPI_KEY
DEFAULT_API_KEY = environ.get("MP_API_KEY", None)
Expand Down Expand Up @@ -160,12 +161,12 @@ def _create_session(api_key, include_user_agent, headers):
session.headers.update(headers)

if include_user_agent:
pymatgen_info = "pymatgen/" + pmg_version
mp_api_info = "mp-api/" + __version__
python_info = f"Python/{sys.version.split()[0]}"
platform_info = f"{platform.system()}/{platform.release()}"
session.headers[
"user-agent"
] = f"{pymatgen_info} ({python_info} {platform_info})"
] = f"{mp_api_info} ({python_info} {platform_info})"

settings = MAPIClientSettings()
max_retry_num = settings.MAX_RETRIES
Expand Down
3 changes: 2 additions & 1 deletion tests/molecules/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"all_fields",
"fields",
"exclude_elements",
"has_props"
"has_props",
]

alt_name_dict = {"formula": "formula_alphabetical", "molecule_ids": "molecule_id"}
Expand All @@ -32,6 +32,7 @@
"has_props": [HasProps.orbitals],
} # type: dict


@pytest.mark.skip(reason="Temporary until data adjustments")
@pytest.mark.skipif(
os.environ.get("MP_API_KEY", None) is None, reason="No API key found."
Expand Down

0 comments on commit 5351c9b

Please sign in to comment.