Skip to content

Commit 4c7f1a0

Browse files
committed
Fix error reporting for finding shard.yml
1 parent e802f18 commit 4c7f1a0

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

mkdocstrings/handlers/crystal/collector.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,21 @@ def shard_version(self):
148148
@classmethod
149149
@functools.lru_cache(maxsize=None)
150150
def _shard_version(cls, path: str):
151-
file_path = os.path.join(path, "shard.yml")
151+
file_path = _find_above(path, "shard.yml")
152+
with open(file_path, "rb") as f:
153+
m = re.search(rb"^version: *([\S+]+)", f.read(), flags=re.MULTILINE)
154+
if not m:
155+
raise PluginError(f"`version:` not found in {file_path!r}")
156+
157+
158+
def _find_above(path: str, filename: str) -> str:
159+
orig_path = path
160+
while path:
161+
file_path = os.path.join(path, filename)
152162
if os.path.isfile(file_path):
153-
with open(file_path, "rb") as f:
154-
m = re.search(rb"^version: *([\S+]+)", f.read(), flags=re.MULTILINE)
155-
if not m:
156-
raise PluginError(f"`version:` not found in {file_path!r}")
157-
return m[1].decode()
158-
if not path:
159-
raise PluginError(f"'shard.yml' not found anywhere above {path!r}")
160-
return cls._shard_version(os.path.dirname(path))
163+
return file_path
164+
path = os.path.dirname(path)
165+
raise PluginError(f"{filename!r} not found anywhere above {os.path.abspath(orig_path)!r}")
161166

162167

163168
class DocRoot(DocModule):

0 commit comments

Comments
 (0)