Skip to content

Commit d82e2fc

Browse files
committed
Fix the issue with READMEs being incorrectly reported as missing when the metadata is coming from the readme
1 parent 3e21c02 commit d82e2fc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

modelindex/models/Model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self,
3636
readme: str = None,
3737
in_collection: Union[str, List[str]] = None,
3838
_filepath: str = None,
39+
_path_to_readme: str=None,
3940
**kwargs,
4041
):
4142
"""
@@ -51,6 +52,7 @@ def __init__(self,
5152
readme (str): path to the README file for the model
5253
in_collection (str, List): name of the collection to which the model belongs to
5354
_filepath: The file path to where the data was loaded from
55+
_path_to_readme: Path to the markdown readme file if data is coming from there
5456
**kwargs: Any other custom fields
5557
"""
5658

@@ -93,6 +95,8 @@ def __init__(self,
9395
# Only non-empty items
9496
data = {k: v for k, v in d.items() if v is not None}
9597

98+
self._path_to_readme = _path_to_readme
99+
96100
super().__init__(
97101
data=data,
98102
filepath=_filepath,
@@ -103,7 +107,7 @@ def _check(self, silent=True):
103107
if self.name is None or self.name == "":
104108
self.check_errors.add("Field 'Name' cannot be empty")
105109

106-
if self.readme and self.readme.endswith(".md") and len(self.readme) < 256:
110+
if self.readme and self.readme.endswith(".md") and len(self.readme) < 256 and not self._path_to_readme:
107111
# check if the README exists
108112
fullpath = full_filepath(self.readme, self.filepath)
109113
if not os.path.isfile(fullpath):
@@ -149,6 +153,7 @@ def from_dict(cls, d: Dict, _filepath: str = None, _path_to_readme: str = None):
149153

150154
return cls(
151155
_filepath=_filepath,
156+
_path_to_readme=_path_to_readme,
152157
**dd,
153158
)
154159

tests/test_import.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def test_wildcard_model_import():
146146
def test_models_import_wildcard():
147147
mi = modelindex.load("tests/test-mi/13_wildcard_model_imports/mi8.yml")
148148

149+
err = mi.check(silent=True)
150+
assert len(err) == 1
151+
assert "docs/inception-v3-readme.md" in err[0]
152+
149153
assert len(mi.collections) == 1
150154
assert len(mi.models) == 2
151155

0 commit comments

Comments
 (0)