Skip to content

Commit

Permalink
fix: allow biothing_type as a single-value list #28
Browse files Browse the repository at this point in the history
  • Loading branch information
newgene committed Mar 16, 2023
1 parent 2b6990e commit 3f89d13
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions biothings_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,16 @@ def get_client(biothing_type=None, instance=True, *args, **kwargs):
res = requests.get(url)
dic = res.json()
biothing_type = dic.get("biothing_type")
assert isinstance(biothing_type, str)
if isinstance(biothing_type, list):
if len(biothing_type) == 1:
# if a list with only one item, use that item
biothing_type = biothing_type[0]
else:
raise RuntimeError("Biothing_type in metadata url is not unique.")
if not isinstance(biothing_type, str):
raise RuntimeError("Biothing_type in metadata url is not a valid string.")
except requests.RequestException:
raise RuntimeError("Cannot access metadata url to determine biothing_type.")
except AssertionError:
raise RuntimeError("Biothing_type in metadata url is not a valid string.")
else:
biothing_type = biothing_type.lower()
if biothing_type not in CLIENT_SETTINGS and not kwargs.get("url", False):
Expand Down

0 comments on commit 3f89d13

Please sign in to comment.