Skip to content

[ci] Remove the code-block-python semgrep lint rule - #65903

Merged
dstrodtman merged 1 commit into
masterfrom
doc-1636-remove-code-block-python-lint
Sep 4, 2026
Merged

dstrodtman merged 1 commit into
masterfrom
doc-1636-remove-code-block-python-lint

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

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

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]>
@dstrodtman
dstrodtman requested review from a team as code owners September 3, 2026 19:03

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Sep 3, 2026
@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core devprod labels Sep 4, 2026
@dstrodtman
dstrodtman merged commit 7c99a0f into master Sep 4, 2026
6 checks passed
@dstrodtman
dstrodtman deleted the doc-1636-remove-code-block-python-lint branch September 4, 2026 15:47
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core devprod go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants