2222# -- General configuration ---------------------------------------------------
2323# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
2424
25- extensions = ['sphinx.ext.autodoc' , 'sphinx.ext.napoleon' ]
25+ extensions = [
26+ 'sphinx.ext.autodoc' ,
27+ 'sphinx.ext.napoleon' ,
28+ 'sphinx.ext.linkcode'
29+ ]
2630
2731templates_path = ['_templates' ]
2832exclude_patterns = []
3539html_theme = 'sphinx_rtd_theme'
3640html_theme_options = {
3741 "collapse_navigation" : False ,
38- "navigation_depth" : 4
42+ "navigation_depth" : 4 ,
43+ "logo_only" : True ,
3944}
4045html_static_path = ['_static' ]
46+
47+ html_context = {
48+ "display_github" : True ,
49+ "github_user" : "RWTH-E3D" ,
50+ "github_repo" : "carbonfly" ,
51+ "github_version" : "master" ,
52+ "conf_py_path" : "/docs/source/" ,
53+ }
54+
55+ html_css_files = [
56+ 'custom.css' ,
57+ ]
58+
59+ html_logo = "_static/carbonfly_logo.svg"
60+
61+
62+ # Prevent import errors from halting the building process
63+ # when some external dependencies cannot be imported at build time
64+ autodoc_mock_imports = [
65+ "Rhino"
66+ ]
67+
68+
69+ # link code
70+ import inspect
71+
72+ def linkcode_resolve (domain , info ):
73+ if domain != 'py' :
74+ return None
75+
76+ module_name = info ['module' ]
77+ fullname = info ['fullname' ]
78+
79+ try :
80+ mod = sys .modules .get (module_name )
81+ if mod is None :
82+ __import__ (module_name )
83+ mod = sys .modules [module_name ]
84+
85+ obj = mod
86+ for part in fullname .split ('.' ):
87+ obj = getattr (obj , part )
88+
89+ # source code location
90+ fn = inspect .getsourcefile (obj )
91+ if not fn :
92+ return None
93+ fn = os .path .relpath (fn , start = os .path .dirname (carbonfly .__file__ ))
94+
95+ source , lineno = inspect .getsourcelines (obj )
96+ linespec = f"#L{ lineno } -L{ lineno + len (source ) - 1 } "
97+
98+ return f"https://github.com/RWTH-E3D/carbonfly/blob/master/carbonfly/{ fn } { linespec } "
99+
100+ except Exception :
101+ return None
0 commit comments