Skip to content

Rewrite check_toml_lints script in python to fix bug#1488

Open
tmpolaczyk wants to merge 3 commits intomasterfrom
tomasz-toml-lints-python
Open

Rewrite check_toml_lints script in python to fix bug#1488
tmpolaczyk wants to merge 3 commits intomasterfrom
tomasz-toml-lints-python

Conversation

@tmpolaczyk
Copy link
Contributor

It used to always return 0 because of how bash subshells interact with variables.

It used to always return 0 because of how bash subshells interact with variables.
@tmpolaczyk tmpolaczyk requested a review from a team as a code owner February 3, 2026 11:54
@coderabbitai
Copy link

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

Adds a Python script that scans tracked Cargo.toml files (via Git), validates each contains a [lints] table with workspace = true, replaces the removed shell script in the release workflow, and updates one proc-macro Cargo.toml to include the lints setting.

Changes

Cohort / File(s) Summary
New Python check / Removed shell script
\.github/scripts/check_toml_lints.py, \.github/scripts/check_toml_lints.sh
Adds check_toml_lints.py (repo-root detection via git rev-parse, tracked file discovery via git ls-files, TOML parsing with tomllib, per-file validation of [lints] workspace = true, detailed error reporting, exit codes). Removes the previous shell script.
Workflow
\.github/workflows/release.yml
Replaces the workflow step to invoke the new Python script instead of the removed shell script.
Manifest update
chains/runtime-common/src/processors/v2/proc_macro/Cargo.toml
Adds a [lints] table with workspace = true to the proc-macro crate manifest.
Proc-macro code & tests
chains/runtime-common/src/processors/v2/proc_macro/src/lib.rs, chains/runtime-common/src/processors/v2/proc_macro/tests/macro_test.rs
Minor token-stream return adjustment and small doc-comment whitespace removal; test helper updated to accept TokenStream directly.

Sequence Diagram(s)

sequenceDiagram
    participant CI as CI Workflow
    participant Script as check_toml_lints.py
    participant Git as Git CLI
    participant FS as Filesystem
    participant TOML as tomllib

    CI->>Script: invoke script
    Script->>Git: git rev-parse --show-toplevel
    Git-->>Script: repo root path
    Script->>Git: git ls-files -z '**/Cargo.toml'
    Git-->>Script: NUL-separated paths
    loop per manifest (excluding repo root)
        Script->>FS: open manifest path
        alt IO error
            FS-->>Script: error
            Script->>CI: emit read error for path
        else opened
            FS-->>Script: file bytes
            Script->>TOML: parse bytes
            alt parse error
                TOML-->>Script: decode error
                Script->>CI: emit parse error for path
            else parsed
                TOML-->>Script: toml dict
                Script->>Script: check lints.workspace == true
                alt missing/false
                    Script->>CI: emit "Missing [lints] workspace = true in <path>"
                else valid
                    Script-->>CI: no issue
                end
            end
        end
    end
    Script->>CI: exit 0 if all valid else exit 1
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: rewriting a shell script in Python to fix a specific bug related to exit code handling.
Description check ✅ Passed The description clearly explains the motivation for the change by identifying the bug in the original Bash implementation that was fixed by the rewrite.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tomasz-toml-lints-python

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @.github/scripts/check_toml_lints.py:
- Around line 162-164: The "Missing [lints] workspace = true" message is printed
whenever ok is False, which wrongly shows when the file failed to be
read/parsed; change the logic to distinguish read/parse errors from a genuine
missing configuration: introduce a separate flag (e.g., read_ok or parsed_ok)
when opening/parsing the TOML succeeds, keep using ok for "has required config",
and only print the "Missing [lints] workspace = true in {rel}" message (and set
failure=1) when parsed_ok is True but ok is False; update the code paths around
the file open/parse and the if not ok block to check both flags accordingly,
referencing ok, parsed_ok (or read_ok), failure, and rel.

In @.github/workflows/release.yml:
- Around line 116-117: The workflow step that runs check_toml_lints.py assumes
Python 3.11+ because the script imports tomllib; update the release.yml workflow
to ensure a compatible Python version is available by adding a setup step (e.g.,
actions/setup-python@v4 with python-version: '3.11') before the step that runs
./.github/scripts/check_toml_lints.py or alternatively document/validate that
the self-hosted runner provides Python >=3.11; reference the script name
check_toml_lints.py and the tomllib import to locate where this requirement
originates.
🧹 Nitpick comments (1)
.github/scripts/check_toml_lints.py (1)

13-13: Consider using straight quotes in docstrings for consistency.

The docstring uses curly/smart quotes ('cargo clippy') instead of straight quotes. While this doesn't affect functionality, using straight quotes (`cargo clippy`) would be more consistent with typical Python documentation conventions.

Comment on lines +162 to +164
if not ok:
print(f"Missing [lints] workspace = true in {rel}")
failure = 1
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Error message may be misleading when file access fails.

When ok is False due to a FileNotFoundError, PermissionError, or TOMLDecodeError, the code already prints an appropriate error message (e.g., "Error: file not found"). However, it then also prints "Missing [lints] workspace = true", which is misleading since the actual problem is file access or parsing, not a missing configuration.

Consider only printing the "Missing" message when the file was successfully read but lacks the required configuration.

🛠️ Suggested fix
             except OSError as oe:
                 print(f"Error: could not read {rel}: {oe}", file=sys.stderr)
                 ok = False
+                failure = 1
+                continue

             if not ok:
                 print(f"Missing [lints] workspace = true in {rel}")
                 failure = 1

Alternatively, track whether we already printed an error:

-            except FileNotFoundError:
-                print(f"Error: file not found: {rel}", file=sys.stderr)
-                ok = False
-            except PermissionError:
-                print(f"Error: permission denied reading: {rel}", file=sys.stderr)
-                ok = False
-            except tomllib.TOMLDecodeError as te:
-                print(f"Error: invalid TOML in {rel}: {te}", file=sys.stderr)
-                ok = False
-            except OSError as oe:
-                print(f"Error: could not read {rel}: {oe}", file=sys.stderr)
-                ok = False
-
-            if not ok:
-                print(f"Missing [lints] workspace = true in {rel}")
-                failure = 1
+            except (FileNotFoundError, PermissionError, tomllib.TOMLDecodeError, OSError) as e:
+                print(f"Error reading {rel}: {e}", file=sys.stderr)
+                failure = 1
+            else:
+                if not ok:
+                    print(f"Missing [lints] workspace = true in {rel}")
+                    failure = 1
🤖 Prompt for AI Agents
In @.github/scripts/check_toml_lints.py around lines 162 - 164, The "Missing
[lints] workspace = true" message is printed whenever ok is False, which wrongly
shows when the file failed to be read/parsed; change the logic to distinguish
read/parse errors from a genuine missing configuration: introduce a separate
flag (e.g., read_ok or parsed_ok) when opening/parsing the TOML succeeds, keep
using ok for "has required config", and only print the "Missing [lints]
workspace = true in {rel}" message (and set failure=1) when parsed_ok is True
but ok is False; update the code paths around the file open/parse and the if not
ok block to check both flags accordingly, referencing ok, parsed_ok (or
read_ok), failure, and rel.

Comment on lines 116 to +117
- name: Find toml files with lints key not set
run: ./.github/scripts/check_toml_lints.sh
run: ./.github/scripts/check_toml_lints.py
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the release.yml workflow around the flagged lines
cat -n .github/workflows/release.yml | sed -n '100,130p'

Repository: moondance-labs/tanssi

Length of output: 1640


🏁 Script executed:

# Check if the check_toml_lints.py script exists and what it contains
if [ -f ".github/scripts/check_toml_lints.py" ]; then
  echo "=== check_toml_lints.py found ==="
  cat -n .github/scripts/check_toml_lints.py
else
  echo "check_toml_lints.py not found"
fi

Repository: moondance-labs/tanssi

Length of output: 6912


🏁 Script executed:

# Check for any Python version setup in the workflow and surrounding context
cat -n .github/workflows/release.yml | head -50

Repository: moondance-labs/tanssi

Length of output: 2261


🏁 Script executed:

# Look for any python or setup-python references in the entire workflow
rg -n "python|Python" .github/workflows/release.yml

Repository: moondance-labs/tanssi

Length of output: 47


Ensure self-hosted runner has Python 3.11+ or add version requirement to workflow.

The check_toml_lints.py script explicitly requires Python 3.11+ for the tomllib module (line 37), with no fallback implementation. The workflow contains no Python version setup step, so if the self-hosted runner's default Python is 3.10 or earlier, this step will fail with an ImportError when trying to import tomllib.

Either ensure the runner has Python 3.11+ available, or add a setup step to guarantee the correct version (e.g., using actions/setup-python@v4 with python-version: '3.11').

🤖 Prompt for AI Agents
In @.github/workflows/release.yml around lines 116 - 117, The workflow step that
runs check_toml_lints.py assumes Python 3.11+ because the script imports
tomllib; update the release.yml workflow to ensure a compatible Python version
is available by adding a setup step (e.g., actions/setup-python@v4 with
python-version: '3.11') before the step that runs
./.github/scripts/check_toml_lints.py or alternatively document/validate that
the self-hosted runner provides Python >=3.11; reference the script name
check_toml_lints.py and the tomllib import to locate where this requirement
originates.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

WASM runtime size check:

Compared to target branch

dancebox runtime: 1900 KB (no changes) ✅

flashbox runtime: 1124 KB (no changes) ✅

dancelight runtime: 2668 KB (no changes) 🚨

starlight runtime: 2584 KB (no changes) 🚨

container chain template simple runtime: 1516 KB (no changes) ✅

container chain template frontier runtime: 1848 KB (no changes) ✅

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

Coverage Report

(master)

@@                     Coverage Diff                      @@
##           master   tomasz-toml-lints-python      +/-   ##
============================================================
- Coverage   73.91%                     73.84%   -0.07%     
- Files         569                        568       -1     
- Lines       83085                      82805     -280     
============================================================
- Hits        61410                      61141     -269     
- Misses      21675                      21664      -11     
Files Changed Coverage
/chains/orchestrator-relays/runtime/dancelight/src/bridge_to_ethereum_config.rs 78.75% (+1.92%)
/chains/orchestrator-relays/runtime/dancelight/src/lib.rs 36.61% (+0.11%)
/chains/orchestrator-relays/runtime/starlight/src/bridge_to_ethereum_config.rs 26.67% (+1.67%)
/pallets/outbound-message-commitment-recorder/src/lib.rs 45.45% (-49.14%)

Coverage generated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant