Skip to content

Commit b37b806

Browse files
committed
Port: Ensure build compatibility with Sphinx 8.x.x
Tested both with sphinx 7.4.7 and sphinx 8.1.3. Signed-off-by: Nicolae Dicu <[email protected]>
1 parent 6518e61 commit b37b806

File tree

2 files changed

+112
-2
lines changed

2 files changed

+112
-2
lines changed

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,110 @@ See [docs/](docs/) for more information.
1010

1111
[pypi-badge]: https://img.shields.io/pypi/v/sphinx-rust.svg
1212
[pypi-link]: https://pypi.org/project/sphinx-rust
13+
14+
## Fork notes
15+
16+
### Integration, usage and testing
17+
18+
**CURRENTLY FORK UNDER DEVELOPMENT! - PIP PACKAGE UNAVAILABLE**
19+
20+
* In order to integrate in score:
21+
22+
Update score/docs/conf.py :
23+
24+
```python
25+
extensions = [
26+
"sphinx_rust",
27+
...
28+
]
29+
30+
# point to a rust crate in score(create a dummy one for testing if unavailable)
31+
rust_crates = [
32+
"../rust-crates/dummy_crate",
33+
]
34+
```
35+
In index.rst :
36+
```
37+
Rust API <api/crates/dummy_crate/index>
38+
```
39+
40+
* Testing in score repo:
41+
42+
For fast development it is recomended to convert sphinx-rust module to bazel module by creating:
43+
44+
- __sphinx-rust__/BUILD.bazel:
45+
46+
```python
47+
load("@rules_python//python:defs.bzl", "py_library")
48+
49+
py_library(
50+
name = "sphinx_rust",
51+
srcs = glob(["python/sphinx_rust/**/*.py"]),
52+
data = glob([
53+
"python/sphinx_rust/sphinx_rust.cpython-312-*.so",
54+
]),
55+
imports = ["python"],
56+
visibility = ["//visibility:public"],
57+
)
58+
```
59+
60+
- __sphinx-rust__/MODULE.bazel
61+
62+
```python
63+
module(name = "sphinx_rust", version = "0.0.0-dev")
64+
bazel_dep(name = "rules_python", version = "1.4.1")
65+
```
66+
67+
Now we can add the __sphinx_rust__ module directly in __score__:
68+
69+
- __score__/MODULE.bazel:
70+
71+
```python
72+
bazel_dep(name = "sphinx_rust", version = "0.0.0-dev")
73+
local_path_override(module_name = "sphinx_rust", path = "../sphinx-rust")
74+
```
75+
76+
- create the dummy_crate in __score__ with the following structure and content:
77+
78+
```sh
79+
../score/rust-crates/
80+
└── dummy_crate
81+
├── Cargo.toml
82+
└── src
83+
└── lib.rs
84+
```
85+
86+
Cargo.toml:
87+
88+
```yaml
89+
[package]
90+
name = "dummy_crate"
91+
version = "0.1.0"
92+
edition = "2021"
93+
94+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
95+
96+
[dependencies]
97+
98+
[lib]
99+
name = "dummy_crate"
100+
```
101+
102+
lib.rs:
103+
104+
```rs
105+
pub fn add(left: usize, right: usize) -> usize {
106+
left + right
107+
}
108+
109+
#[cfg(test)]
110+
mod tests {
111+
use super::*;
112+
113+
#[test]
114+
fn it_works() {
115+
let result = add(2, 2);
116+
assert_eq!(result, 4);
117+
}
118+
}
119+
```

python/sphinx_rust/directives/_core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,11 @@ def parse_docstring(
146146
return []
147147

148148
docstring = item.docstring if docstring is None else docstring
149-
source_path = env.doc2path( # TODO this actually should be the rust file path
150-
env.docname
149+
150+
source_path = str(
151+
env.doc2path( # TODO this actually should be the rust file path
152+
env.docname
153+
)
151154
)
152155
# TODO how to handle line numbers?
153156
document = utils.new_document(source_path, doc.settings)

0 commit comments

Comments
 (0)