Skip to content

Commit e0d7ede

Browse files
authored
docs: prune unused linkcode (#19897)
1 parent 414c863 commit e0d7ede

File tree

2 files changed

+1
-96
lines changed

2 files changed

+1
-96
lines changed

docs/source-app/conf.py

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@
4141
# The full version, including alpha/beta/rc tags
4242
release = lightning.__version__
4343

44-
# Options for the linkcode extension
45-
# ----------------------------------
46-
github_user = "Lightning-AI"
47-
github_repo = project
48-
4944
# -- Project documents -------------------------------------------------------
5045

5146
if _FETCH_S3_ASSETS:
@@ -71,7 +66,7 @@
7166
"sphinx_toolbox.collapse",
7267
"sphinx.ext.todo",
7368
"sphinx.ext.coverage",
74-
"sphinx.ext.linkcode",
69+
# "sphinx.ext.linkcode",
7570
"sphinx.ext.autosummary",
7671
"sphinx.ext.napoleon",
7772
# 'sphinxcontrib.mockautodoc', # raises error: directive 'automodule' is already registered ...
@@ -324,15 +319,6 @@ def setup(app):
324319
app.add_js_file("copybutton.js")
325320
app.add_css_file("main.css")
326321

327-
328-
# copy all notebooks to local folder
329-
path_nbs = os.path.join(_PATH_HERE, "notebooks")
330-
if not os.path.isdir(path_nbs):
331-
os.mkdir(path_nbs)
332-
for path_ipynb in glob.glob(os.path.join(_PATH_ROOT, "notebooks", "*.ipynb")):
333-
path_ipynb2 = os.path.join(path_nbs, os.path.basename(path_ipynb))
334-
shutil.copy(path_ipynb, path_ipynb2)
335-
336322
# copy all examples to local folder
337323
path_examples = os.path.join(_PATH_HERE, "..", "examples")
338324
if not os.path.isdir(path_examples):
@@ -370,44 +356,6 @@ def _package_list_from_file(file):
370356
autodoc_mock_imports = MOCK_PACKAGES
371357

372358

373-
# Resolve function
374-
# This function is used to populate the (source-app) links in the API
375-
def linkcode_resolve(domain, info):
376-
def find_source():
377-
# try to find the file and line number, based on code from numpy:
378-
# https://github.com/numpy/numpy/blob/master/doc/source/conf.py#L286
379-
obj = sys.modules[info["module"]]
380-
for part in info["fullname"].split("."):
381-
obj = getattr(obj, part)
382-
fname = inspect.getsourcefile(obj)
383-
# https://github.com/rtfd/readthedocs.org/issues/5735
384-
if any(s in fname for s in ("readthedocs", "rtfd", "checkouts")):
385-
# /home/docs/checkouts/readthedocs.org/user_builds/pytorch_lightning/checkouts/
386-
# devel/pytorch_lightning/utilities/cls_experiment.py#L26-L176
387-
path_top = os.path.abspath(os.path.join("..", "..", ".."))
388-
fname = os.path.relpath(fname, start=path_top)
389-
else:
390-
# Local build, imitate master
391-
fname = "master/" + os.path.relpath(fname, start=os.path.abspath(".."))
392-
source, lineno = inspect.getsourcelines(obj)
393-
return fname, lineno, lineno + len(source) - 1
394-
395-
if domain != "py" or not info["module"]:
396-
return None
397-
try:
398-
filename = "%s#L%d-L%d" % find_source()
399-
except Exception:
400-
filename = info["module"].replace(".", "/") + ".py"
401-
# import subprocess
402-
# tag = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE,
403-
# universal_newlines=True).communicate()[0][:-1]
404-
branch = filename.split("/")[0]
405-
# do mapping from latest tags to master
406-
branch = {"latest": "master", "stable": "master"}.get(branch, branch)
407-
filename = "/".join([branch] + filename.split("/")[1:])
408-
return f"https://github.com/{github_user}/{github_repo}/blob/{filename}"
409-
410-
411359
autosummary_generate = True
412360

413361
autodoc_member_order = "groupwise"

docs/source-fabric/conf.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
# The full version, including alpha/beta/rc tags
4040
release = lightning.__version__
4141

42-
# Options for the linkcode extension
43-
# ----------------------------------
44-
github_user = "Lightning-AI"
45-
github_repo = project
46-
4742
# -- Project documents -------------------------------------------------------
4843

4944
if _FETCH_S3_ASSETS:
@@ -339,44 +334,6 @@ def _package_list_from_file(file):
339334
autodoc_mock_imports = MOCK_PACKAGES
340335

341336

342-
# Resolve function
343-
# This function is used to populate the (source) links in the API
344-
def linkcode_resolve(domain, info):
345-
def find_source():
346-
# try to find the file and line number, based on code from numpy:
347-
# https://github.com/numpy/numpy/blob/master/doc/source/conf.py#L286
348-
obj = sys.modules[info["module"]]
349-
for part in info["fullname"].split("."):
350-
obj = getattr(obj, part)
351-
fname = inspect.getsourcefile(obj)
352-
# https://github.com/rtfd/readthedocs.org/issues/5735
353-
if any(s in fname for s in ("readthedocs", "rtfd", "checkouts")):
354-
# /home/docs/checkouts/readthedocs.org/user_builds/pytorch_lightning/checkouts/
355-
# devel/pytorch_lightning/utilities/cls_experiment.py#L26-L176
356-
path_top = os.path.abspath(os.path.join("..", "..", ".."))
357-
fname = os.path.relpath(fname, start=path_top)
358-
else:
359-
# Local build, imitate master
360-
fname = "master/" + os.path.relpath(fname, start=os.path.abspath(".."))
361-
source, lineno = inspect.getsourcelines(obj)
362-
return fname, lineno, lineno + len(source) - 1
363-
364-
if domain != "py" or not info["module"]:
365-
return None
366-
try:
367-
filename = "%s#L%d-L%d" % find_source()
368-
except Exception:
369-
filename = info["module"].replace(".", "/") + ".py"
370-
# import subprocess
371-
# tag = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE,
372-
# universal_newlines=True).communicate()[0][:-1]
373-
branch = filename.split("/")[0]
374-
# do mapping from latest tags to master
375-
branch = {"latest": "master", "stable": "master"}.get(branch, branch)
376-
filename = "/".join([branch] + filename.split("/")[1:])
377-
return f"https://github.com/{github_user}/{github_repo}/blob/{filename}"
378-
379-
380337
autosummary_generate = True
381338

382339
autodoc_member_order = "groupwise"

0 commit comments

Comments
 (0)