Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions mmif/serialize/mmif.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,4 @@ def __getitem__(self, item: str) -> Union[Document, View, Annotation, MmifMetada
ret = self.views._items.get(item)
if ret is None:
raise KeyError(f"Object with ID {item} not found in the MMIF object. ")
else:
return ret
else:
return ret
return ret
4 changes: 2 additions & 2 deletions mmif/serialize/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,14 @@ def __contains__(self, key: str) -> bool:
try:
self.__getitem__(key)
return True
except (TypeError, AttributeError, KeyError):
except (TypeError, KeyError):
return False

def __getitem__(self, key) -> Any:
if key in self._named_attributes():
value = self.__dict__[key]
elif self._unnamed_attributes is None:
raise AttributeError(f"Additional properties are disallowed by {self.__class__}: {key}")
raise KeyError(f"Additional properties are disallowed by {self.__class__}: {key}")
else:
value = self._unnamed_attributes[key]
if key not in self._required_attributes and self.is_empty(value):
Expand Down
10 changes: 7 additions & 3 deletions tests/mmif_examples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import itertools
import os
import subprocess
from pathlib import Path
from string import Template
from urllib import request

Expand All @@ -20,8 +21,11 @@ def _load_from_url_or_git(url):
If LOCALMMIF env var is set, use git show to load from local repo.
LOCALMMIF should be the path to the local mmif repository.
"""
localmmif = os.environ.get('LOCALMMIF')
if localmmif:
localmmif_str = os.environ.get('LOCALMMIF')
if localmmif_str:
localmmif = Path(localmmif_str)
if not localmmif.is_dir():
raise ValueError(f"LOCALMMIF path is not a valid directory: {localmmif}")
# Extract the version/branch and file path from the URL
# URL format: https://raw.githubusercontent.com/clamsproject/mmif/{version}/{filepath}
url_prefix = "https://raw.githubusercontent.com/clamsproject/mmif/"
Expand All @@ -35,7 +39,7 @@ def _load_from_url_or_git(url):
try:
result = subprocess.run(
['git', 'show', git_ref],
cwd=localmmif,
cwd=str(localmmif),
capture_output=True,
text=True,
check=True
Expand Down
Loading