This is an automated email from the ASF dual-hosted git repository.
HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git
The following commit(s) were added to refs/heads/master by this push:
new 74d2c980 [SPARK-61587][FOLLOWUP][CONNECT][BUILD] Check the indented
rust snippets of the docs too, and fix the one of the troubleshooting guide
74d2c980 is described below
commit 74d2c9801e8a8c33edaff5210e21ae2b468d66e8
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Fri Nov 13 11:57:02 2026 +0900
[SPARK-61587][FOLLOWUP][CONNECT][BUILD] Check the indented rust snippets of
the docs too, and fix the one of the troubleshooting guide
### What changes were proposed in this pull request?
- `scripts/check_doc_snippets.py` now also finds an indented ```` ```rust
```` fence, as in a list item, an admonition or a content tab. It strips the
indentation of the opening fence from each line, as Markdown does. `{.rust
.no-run}` fences stay unchecked.
- The snippet in `docs/troubleshooting.md` now imports
`SparkSessionBuilder`, which it uses, and is indented to sit inside its list
item.
- A unit test covers the fences at the start of a line, in a list item and
in an admonition, an indented `.no-run` fence, and a non-Rust fence.
### Why are the changes needed?
The check matched only fences at the start of a line. It skipped three
snippets: in `docs/troubleshooting.md`, `docs/architecture.md` and
`docs/sql.md`. The troubleshooting one does not compile (`E0433: cannot find
type SparkSessionBuilder`), and CI passed.
### Does this PR introduce _any_ user-facing change?
The troubleshooting guide's TLS snippet now compiles and renders inside its
list item.
### How was this patch tested?
- `python3 -m unittest discover -s scripts/tests`: 37 tests pass.
- `cargo build -p apache-spark-connect`, then `python
scripts/check_doc_snippets.py`: 59 snippets checked, 0 failed. It checked 56
before.
- The old troubleshooting snippet, extracted by the new check, fails with
`E0433`, as it should.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
This pull request and its description were written by Isaac.
Closes #602 from HyukjinKwon/SPARK-61587-followup-indented-fences.
Authored-by: Hyukjin Kwon <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
---
docs/troubleshooting.md | 10 ++++++----
scripts/check_doc_snippets.py | 27 ++++++++++++++++++++++-----
scripts/tests/test_check_doc_snippets.py | 31 +++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 9 deletions(-)
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index 12e4ee36..fc5bf3a6 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -22,10 +22,12 @@ Common issues and solutions when using Spark Connect Rust.
**Solution:**
1. Verify you are using the correct connection string format with TLS enabled:
```rust
-let spark = SparkSessionBuilder::default()
- .remote("sc://host:15002/;use_ssl=true;token=YOUR_TOKEN")
- .get_or_create()?;
-```
+ use spark_connect::SparkSessionBuilder;
+
+ let spark = SparkSessionBuilder::default()
+ .remote("sc://host:15002/;use_ssl=true;token=YOUR_TOKEN")
+ .get_or_create()?;
+ ```
2. If the server uses self-signed certificates, consult your infrastructure
team.
3. Check that your token or authentication credentials are valid.
4. Verify the server is configured to accept your authentication method (check
server config or logs).
diff --git a/scripts/check_doc_snippets.py b/scripts/check_doc_snippets.py
index f9de82f1..b8fae61f 100644
--- a/scripts/check_doc_snippets.py
+++ b/scripts/check_doc_snippets.py
@@ -20,7 +20,8 @@
The published guides drifted out of sync with the API (examples that used `lit`
without importing it, or `SparkSessionBuilder` without a `use`), and nothing
in CI
caught it because the docs workflow only *deploys*. This type-checks every
-```rust``` block so a doc example can't reference a symbol the crate doesn't
export.
+```rust``` block, including the indented ones of list items, admonitions and
content
+tabs, so a doc example can't reference a symbol the crate doesn't export.
Each block is wrapped in a small harness that binds ``spark`` and ``df`` (so
the
common "continue from an earlier block" fragments type-check) and is run
through
@@ -54,8 +55,24 @@ from pathlib import Path
REPO = Path(__file__).resolve().parent.parent
# ```rust``` (checked) vs ```{.rust .no-run}``` (rendered but skipped). We
only check
-# plain ```rust``` fences; any info string with a comma/space/brace is left
alone.
-_BLOCK = re.compile(r"^```rust\s*$\n(.*?)^```\s*$", re.DOTALL | re.MULTILINE)
+# plain ```rust``` fences; any info string with a comma/space/brace is left
alone. A fence
+# may be indented, as in a list item, an admonition or a content tab, and its
closing fence
+# with it.
+_BLOCK = re.compile(
+ r"^(?P<indent>[ \t]*)```rust[ \t]*$\n(?P<body>.*?)^[ \t]*```[ \t]*$",
re.DOTALL | re.MULTILINE
+)
+
+
+def snippets(text: str) -> list[str]:
+ """The ```rust``` snippets of the Markdown ``text``. Each line of an
indented snippet loses
+ up to the indentation of its opening fence, as Markdown strips it."""
+ found = []
+ for m in _BLOCK.finditer(text):
+ width = len(m.group("indent"))
+ lines = m.group("body").splitlines()
+ found.append("\n".join(ln[min(width, len(ln) - len(ln.lstrip(" \t")))
:] for ln in lines))
+ return found
+
# Harness: bind the identifiers the fragments assume from earlier blocks. `use`
# statements are legal inside a fn body, so a block can carry its own imports;
a
@@ -172,10 +189,10 @@ def main() -> int:
idx = 0
for md in sorted(glob.glob(str(REPO / "docs" / "**" / "*.md"),
recursive=True)):
text = Path(md).read_text()
- for m in _BLOCK.finditer(text):
+ for code in snippets(text):
idx += 1
checked += 1
- ok, err = check_block(m.group(1), tmpdir, idx, rlib, deps)
+ ok, err = check_block(code, tmpdir, idx, rlib, deps)
if not ok:
rel = Path(md).relative_to(REPO)
# First rustc error line is the most informative.
diff --git a/scripts/tests/test_check_doc_snippets.py
b/scripts/tests/test_check_doc_snippets.py
index 04d39993..34715598 100644
--- a/scripts/tests/test_check_doc_snippets.py
+++ b/scripts/tests/test_check_doc_snippets.py
@@ -69,6 +69,37 @@ class CheckDocSnippetsTests(unittest.TestCase):
self.assertIn(diagnostic, error)
+class SnippetsTests(unittest.TestCase):
+ def test_finds_indented_fences_and_strips_their_indentation(self):
+ text = "\n".join(
+ [
+ "```rust",
+ "let a = 1;",
+ "```",
+ "1. In a list item:",
+ " ```rust",
+ " let b = 2;",
+ " let c = 3;",
+ " ```",
+ "!!! note",
+ " ```rust",
+ " let d = 4;",
+ " ```",
+ " ```{.rust .no-run}",
+ " let e = 5;",
+ " ```",
+ "```python",
+ "f = 6",
+ "```",
+ "",
+ ]
+ )
+ self.assertEqual(
+ checker.snippets(text),
+ ["let a = 1;", "let b = 2;\n let c = 3;", "let d = 4;"],
+ )
+
+
class CrateArtifactsTests(unittest.TestCase):
def test_failed_build_prints_the_rendered_errors_of_rustc(self):
# cargo prints the errors of rustc as JSON on stdout with
--message-format=json.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]