File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change 184184]
185185
186186
187- # -- Extension configuration -------------------------------------------------
187+ # -- linkcode setting -------------------------------------------------
188+
189+ import inspect
190+ import os
191+ import sys
192+ import functools
193+
194+ GITHUB_REPO = "https://github.com/AtsushiSakai/PythonRobotics"
195+ GITHUB_BRANCH = "main"
196+
197+
198+ def linkcode_resolve (domain , info ):
199+ if domain != "py" :
200+ return None
201+
202+ modname = info ["module" ]
203+ fullname = info ["fullname" ]
204+
205+ try :
206+ module = __import__ (modname , fromlist = [fullname ])
207+ obj = functools .reduce (getattr , fullname .split ("." ), module )
208+ except (ImportError , AttributeError ):
209+ return None
210+
211+ try :
212+ srcfile = inspect .getsourcefile (obj )
213+ srcfile = os .path .relpath (srcfile , start = os .path .dirname (
214+ sys .modules [modname ].__file__ ))
215+ lineno = inspect .getsourcelines (obj )[1 ]
216+ except Exception :
217+ return None
218+
219+ return f"{ GITHUB_REPO } /blob/{ GITHUB_BRANCH } /{ srcfile } #L{ lineno } "
You can’t perform that action at this time.
0 commit comments