Skip to content

Commit

Permalink
Retrieve providers list if no submodule is found (#374)
Browse files Browse the repository at this point in the history
Use https for submodule.


Co-authored-by: Matthew Evans <7916000+ml-evs@users.noreply.github.com>
  • Loading branch information
CasperWA and ml-evs committed Jun 25, 2020
1 parent 16ab982 commit ad68951
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "providers"]
path = providers
url = git@github.com:Materials-Consortia/providers.git
url = https://github.com/Materials-Consortia/providers.git
8 changes: 6 additions & 2 deletions optimade/server/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@


for var, path in data_paths.items():
with open(Path(__file__).parent / path) as f:
globals()[var] = bson.json_util.loads(f.read())
try:
with open(Path(__file__).parent / path) as f:
globals()[var] = bson.json_util.loads(f.read())
except FileNotFoundError:
if var != "providers":
raise
28 changes: 26 additions & 2 deletions optimade/server/routers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from optimade.server.entry_collections import EntryCollection
from optimade.server.exceptions import BadRequest
from optimade.server.query_params import EntryListingQueryParams, SingleEntryQueryParams
from optimade.server.data import providers

ENTRY_INFO_SCHEMAS = {
"structures": StructureResource.schema,
Expand Down Expand Up @@ -307,7 +306,32 @@ def mongo_id_for_database(database_id: str, database_type: str) -> str:


def get_providers():
"""Retrieve Materials-Consortia providers (from https://providers.optimade.org/providers.json)"""
"""Retrieve Materials-Consortia providers (from https://providers.optimade.org/v1/links)"""
import requests

try:
from optimade.server.data import providers
except ImportError:
providers = None

if providers is None:
try:
import simplejson as json
except ImportError:
import json

try:
providers = requests.get("https://providers.optimade.org/v1/links").json()
except (
requests.exceptions.ConnectionError,
requests.exceptions.ConnectTimeout,
json.JSONDecodeError,
):
raise BadRequest(
status_code=500,
detail="Could not retrieve providers list from https://providers.optimade.org",
)

providers_list = []
for provider in providers.get("data", []):
# Remove/skip "exmpl"
Expand Down

0 comments on commit ad68951

Please sign in to comment.