Skip to content

Commit ad9d446

Browse files
committedFeb 7, 2025
update docs and deps
1 parent 7de581c commit ad9d446

File tree

12 files changed

+662
-603
lines changed

12 files changed

+662
-603
lines changed
 

‎docs/conf.py

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
"""Configuration file for the Sphinx documentation builder."""
22

3+
from glob import glob
4+
import shutil
5+
6+
shutil.copyfile("../README.md", "source/README.md")
7+
38
project = "torchrunx"
49
github_username = "apoorvkh"
510
github_repository = "torchrunx"
611
html_theme = "furo"
712
language = "en"
813

9-
html_extra_path = ["source/examples/scripts"]
14+
html_extra_path = list(glob("source/examples/scripts/*.py"))
1015

1116
extensions = [
1217
"autodoc2",
@@ -27,69 +32,5 @@
2732
"numpy": ("https://numpy.org/doc/stable", None),
2833
}
2934

30-
## Copy README.md to docs/source/
31-
import shutil
32-
shutil.copyfile("../README.md", "source/README.md")
33-
## End of "Copy README.md to docs/source/"
34-
35-
## sphinx.ext.linkcode configuration
36-
# Link code to Github source
37-
# From: https://github.com/scikit-learn/scikit-learn/blob/main/doc/sphinxext/github_link.py
38-
39-
import inspect
40-
import os
41-
import subprocess
42-
import sys
43-
from operator import attrgetter
44-
45-
package = project
46-
47-
try:
48-
revision = (
49-
subprocess.check_output("git rev-parse --short HEAD".split()).strip().decode("utf-8")
50-
)
51-
except (subprocess.CalledProcessError, OSError):
52-
print("Failed to execute git to get revision")
53-
revision = None
54-
55-
url_fmt = (
56-
f"https://github.com/{github_username}/{github_repository}/"
57-
"blob/{revision}/src/{package}/{path}#L{lineno}"
58-
)
59-
60-
def linkcode_resolve(domain, info):
61-
if revision is None:
62-
return
63-
if domain not in ("py", "pyx"):
64-
return
65-
if not info.get("module") or not info.get("fullname"):
66-
return
67-
68-
class_name = info["fullname"].split(".")[0]
69-
module = __import__(info["module"], fromlist=[class_name])
70-
obj = attrgetter(info["fullname"])(module)
71-
72-
# Unwrap the object to get the correct source
73-
# file in case that is wrapped by a decorator
74-
obj = inspect.unwrap(obj)
75-
76-
try:
77-
fn = inspect.getsourcefile(obj)
78-
except Exception:
79-
fn = None
80-
if not fn:
81-
try:
82-
fn = inspect.getsourcefile(sys.modules[obj.__module__])
83-
except Exception:
84-
fn = None
85-
if not fn:
86-
return
87-
88-
fn = os.path.relpath(fn, start=os.path.dirname(__import__(package).__file__))
89-
try:
90-
lineno = inspect.getsourcelines(obj)[1]
91-
except Exception:
92-
lineno = ""
93-
return url_fmt.format(revision=revision, package=package, path=fn, lineno=lineno)
94-
95-
## End of "sphinx.ext.linkcode configuration"
35+
from docs.linkcode_github import generate_linkcode_resolve_fn
36+
linkcode_resolve = generate_linkcode_resolve_fn(project, github_username, github_repository)

‎docs/linkcode_github.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
## sphinx.ext.linkcode configuration
2+
# Link code to Github source
3+
# From: https://github.com/scikit-learn/scikit-learn/blob/main/doc/sphinxext/github_link.py
4+
5+
import inspect
6+
import os
7+
import subprocess
8+
import sys
9+
from operator import attrgetter
10+
11+
12+
def generate_linkcode_resolve_fn(package, github_username, github_repository):
13+
14+
try:
15+
revision = (
16+
subprocess.check_output("git rev-parse --short HEAD".split()).strip().decode("utf-8")
17+
)
18+
except (subprocess.CalledProcessError, OSError):
19+
print("Failed to execute git to get revision")
20+
revision = None
21+
22+
url_fmt = (
23+
f"https://github.com/{github_username}/{github_repository}/"
24+
"blob/{revision}/src/{package}/{path}#L{lineno}"
25+
)
26+
27+
def linkcode_resolve(domain, info):
28+
if revision is None:
29+
return
30+
if domain not in ("py", "pyx"):
31+
return
32+
if not info.get("module") or not info.get("fullname"):
33+
return
34+
35+
class_name = info["fullname"].split(".")[0]
36+
module = __import__(info["module"], fromlist=[class_name])
37+
obj = attrgetter(info["fullname"])(module)
38+
39+
# Unwrap the object to get the correct source
40+
# file in case that is wrapped by a decorator
41+
obj = inspect.unwrap(obj)
42+
43+
try:
44+
fn = inspect.getsourcefile(obj)
45+
except Exception:
46+
fn = None
47+
if not fn:
48+
try:
49+
fn = inspect.getsourcefile(sys.modules[obj.__module__])
50+
except Exception:
51+
fn = None
52+
if not fn:
53+
return
54+
55+
fn = os.path.relpath(fn, start=os.path.dirname(__import__(package).__file__))
56+
try:
57+
lineno = inspect.getsourcelines(obj)[1]
58+
except Exception:
59+
lineno = ""
60+
return url_fmt.format(revision=revision, package=package, path=fn, lineno=lineno)
61+
62+
return linkcode_resolve

‎docs/source/examples/accelerate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Accelerate
22

33
```{eval-rst}
4-
.. literalinclude:: ./scripts/accelerate_example.py
4+
.. literalinclude:: ./scripts/accelerate_train.py
55
```

‎docs/source/examples/deepspeed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DeepSpeed
22

33
```{eval-rst}
4-
.. literalinclude:: ./scripts/deepspeed_example.py
4+
.. literalinclude:: ./scripts/deepspeed_train.py
55
.. literalinclude:: ./scripts/deepspeed_config.json
66
```

‎docs/source/examples/lightning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Pytorch Lightning
22

33
```{eval-rst}
4-
.. literalinclude:: ./scripts/lightning_example.py
4+
.. literalinclude:: ./scripts/lightning_train.py
55
```

‎docs/source/examples/transformers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The following arguments are required: `--model.name`, `--dataset.tokenizer-name`
1414
<summary><p style="display: inline-block;"><code class="docutils literal notranslate"><span class="pre">python transformers_train.py --help</span></code></p> (expand)</summary>
1515

1616
```{eval-rst}
17-
.. literalinclude:: ./transformers_help.txt
17+
.. literalinclude:: ./scripts/transformers_help.txt
1818
```
1919
</details>
2020

‎pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies = [
3030
"numpy>=1.20",
3131
]
3232
[dependency-groups]
33-
dev = ["ruff", "pyright", "pytest", "build", "twine"]
33+
dev = ["ruff", "pyright[nodejs]", "pytest", "build", "twine"]
3434
dev-extras = ["submitit", "transformers"]
3535
docs = ["sphinx==7.4.7", "furo==2024.8.6", "myst-parser==3.0.1", "sphinx-autodoc2==0.5.0", "sphinx-toolbox==3.8.1"]
3636

0 commit comments

Comments
 (0)