Skip to content

Lookup MPRester API key in settings if None provided as arg - #3004

Merged
janosh merged 3 commits into
materialsproject:masterfrom
ml-evs:ml-evs/mp_rester_compat
May 21, 2023
Merged

Lookup MPRester API key in settings if None provided as arg#3004
janosh merged 3 commits into
materialsproject:masterfrom
ml-evs:ml-evs/mp_rester_compat

Conversation

@ml-evs

@ml-evs ml-evs commented May 21, 2023

Copy link
Copy Markdown
Contributor

Summary

Both the new and legacy versions of MPRester accepted api_key=None to be passed as an argument, triggering a fallback to the settings version of the key. The new behavior of the dynamic MPRester is to attempt to use the None value directly, i.e., without checking for an externally configured value.

This PR simply adjusts the behavior so that api_key=None will still trigger a settings lookup.

@janosh
janosh enabled auto-merge (squash) May 21, 2023 22:26
@janosh janosh added fix Bug fix PRs api Application programming interface labels May 21, 2023
@janosh

janosh commented May 21, 2023

Copy link
Copy Markdown
Member

For the new Rester, reading the API key from .pmgrc.yaml or env variable required passing no args, i.e.

- MPRester(None)
+ MPRester()

Thanks for making the upper case work as well @ml-evs!

@janosh
janosh merged commit 1039c70 into materialsproject:master May 21, 2023
@ml-evs
ml-evs deleted the ml-evs/mp_rester_compat branch May 22, 2023 10:50
lbluque pushed a commit to lbluque/pymatgen that referenced this pull request May 23, 2023
…rialsproject#3004)

* Lookup `MPRester` API key in settings if `None` provided as arg

* shorten MPRester doc str

* add MPResterOldTest.test_api_key_is_none()

---------

Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Application programming interface fix Bug fix PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants