Repository navigation
[ci] Remove the code-block-python semgrep lint rule - #65903
Merged
Merged
Conversation
The `code-block-python` rule in semgrep.yml forbids `.. code-block:: python` in the Ray Core, Data, and Train source and doc trees, directing authors to `.. testcode::` instead on the premise that testcode is executed and a code-block is not. That premise doesn't hold: a large share of the API-ref testcode blocks are `:skipif: True` or carry `+MOCK` on their paired testoutput, so they render as examples but never actually run or validate. The rule therefore enforces the testcode syntax rather than actual testing, while blocking an honest, explicitly-untested `.. code-block:: python`. Remove the rule and its plumbing: - delete semgrep.yml (the file held only this one rule) - drop the semgrep hook from .pre-commit-config.yaml - drop semgrep_lint from ci/lint/lint.sh and the lint matrix in .buildkite/lint.rayci.yml - drop the semgrep.yml entry from .buildkite/test.rules.txt Vale is unaffected: it carries no equivalent rule and stays scoped to doc/source/data prose. A code-snippet policy, if wanted later, fits better as a Vale rule (which can warn rather than hard-fail) than a semgrep blocker. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
Contributor
There was a problem hiding this comment.
Code Review
This pull request removes Semgrep linting from the repository. This includes deleting the semgrep.yml configuration file, removing the semgrep pre-commit hook, and cleaning up the associated Buildkite CI steps and linting scripts. I have no feedback to provide on these changes.
elliot-barn
approved these changes
Sep 3, 2026
ronny-anyscale
approved these changes
Sep 3, 2026
nadongjun
pushed a commit
to nadongjun/ray
that referenced
this pull request
Oct 6, 2026
## What Remove the `code-block-python` semgrep lint rule and its CI/pre-commit plumbing. - delete `semgrep.yml` (it held only this one rule) - drop the `semgrep` hook from `.pre-commit-config.yaml` - drop `semgrep_lint` from `ci/lint/lint.sh` and the lint matrix in `.buildkite/lint.rayci.yml` - drop the `semgrep.yml` entry from `.buildkite/test.rules.txt` ## Why The rule forbids `.. code-block:: python` in the Ray Core, Data, and Train source and doc trees, directing authors to `.. testcode::` on the premise that testcode is executed and a code-block is not. That premise no longer holds. A large share of the API-ref `.. testcode::` blocks are `:skipif: True` or carry `+MOCK` on their paired `.. testoutput::`, so they render as examples but never actually run or validate. The rule enforces the testcode *syntax*, not actual testing, while blocking an honest, explicitly-untested `.. code-block:: python`. ## Blast radius Removes one lint check (`semgrep_lint`) from the lint pipeline. No test behavior changes. Vale is unaffected — it has no equivalent rule and stays scoped to `doc/source/data` prose. If a code-snippet policy is wanted later, it fits better as a Vale rule (which can warn rather than hard-fail) than a semgrep blocker. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
dstrodtman
added a commit
that referenced
this pull request
Oct 20, 2026
## Why are these changes needed? A `testcode` block reads as code that CI runs. On doc pages, 217 of them never run. Most carry `:skipif: True`, which Ray's pytest-sphinx fork drops before it builds an example, so the block never even shows up as skipped. The rest sit on pages that no doctest target collects. Most of these date from the semgrep `code-block-python` rule that required `testcode`, which #65903 removed. ### Changes - 45 doc pages: each never-run `testcode` block becomes a plain fenced `python` block, or `.. code-block:: python` in rST. Its paired `testoutput` becomes a `text` block. pytest-sphinx attaches a `testoutput` to the nearest preceding `testcode`, so leaving one behind would pin its output onto an earlier block that does run. - The 8 never-run blocks marked `:hide:` are deleted. Readers never saw them and CI never ran them. - The `hasattr` self-check asserts in the collective backend example are dropped. The asserts in `testing-tips.md` and the local-mode unit test stay, because they're what those examples teach. - `writing-code-snippets.md` no longer teaches `:skipif: True`. Code CI can't run goes in a plain code block, with a `text` block for sample output. - `doc/test_prose_doctest_targets.py` and `doc/BUILD.bazel`: `core/handling-dependencies.md` and `train/horovod.md` no longer hold a runnable example, so they leave `UNTESTED`, and the BUILD comments that explained their missing targets are trimmed. Docstring `testcode` under `python/ray/` is out of scope. It's moving to `>>>` examples in separate PRs, because `code-block` doesn't suit docstrings. ## Duplicate check No open PR covers this. Searches for `skipif`, `testcode`, and `writing-code-snippets` return only my own docstring-convergence PRs (#66745, #66746, #66812) and #66809, which this PR builds on and which has merged. ## Testing - For every changed page, I extracted examples with the pinned pytest-sphinx fork (`ray-project/pytest-sphinx@c1ab2b33`, `docstring2examples`, `pytest==7.4.4`) before and after the change. On the 36 pages a doctest target collects, the examples are identical: same source, expected output, and options. The 9 pages whose examples changed are exactly the pages no target collects, so no test result changes. - `python doc/test_prose_doctest_targets.py` passes: "45 listed pages; every runnable page is accounted for." Without the two `UNTESTED` removals, it fails on both as stale. - `pre-commit run` on all changed files passes. - No `:skipif:` remains under `doc/` except the guide's instruction not to use it. - Not run: a Sphinx build. The edits are directive-to-fence swaps, and the Read the Docs preview is the check. AI assistance (Claude Code) was used to write this change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Remove the
code-block-pythonsemgrep lint rule and its CI/pre-commit plumbing.semgrep.yml(it held only this one rule)semgrephook from.pre-commit-config.yamlsemgrep_lintfromci/lint/lint.shand the lint matrix in.buildkite/lint.rayci.ymlsemgrep.ymlentry from.buildkite/test.rules.txtWhy
The rule forbids
.. code-block:: pythonin the Ray Core, Data, and Train source and doc trees, directing authors to.. testcode::on the premise that testcode is executed and a code-block is not.That premise no longer holds. A large share of the API-ref
.. testcode::blocks are:skipif: Trueor carry+MOCKon their paired.. testoutput::, so they render as examples but never actually run or validate. The rule enforces the testcode syntax, not actual testing, while blocking an honest, explicitly-untested.. code-block:: python.Blast radius
Removes one lint check (
semgrep_lint) from the lint pipeline. No test behavior changes. Vale is unaffected — it has no equivalent rule and stays scoped todoc/source/dataprose. If a code-snippet policy is wanted later, it fits better as a Vale rule (which can warn rather than hard-fail) than a semgrep blocker.🤖 Generated with Claude Code