File tree Expand file tree Collapse file tree
mkdocstrings/handlers/crystal Expand file tree Collapse file tree Original file line number Diff line number Diff 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
163168class DocRoot (DocModule ):
You can’t perform that action at this time.
0 commit comments