Skip to content

Commit 35bced5

Browse files
authored
Add formatting/linting to repo. (anthropics#253)
* chore: upgrade dependencies and add development tooling Update core dependencies to latest versions: - anthropic 0.39.0 → 0.71.0 - ipykernel 6.29.5 → 7.1.0 - notebook 7.2.2 → 7.4.7 - numpy 1.26.4 → 2.3.4 - pandas 2.2.3 → 2.3.3 Add Makefile with common development tasks (format, lint, test, check). Add pylint configuration for deeper code analysis. Enhance ruff linting configuration with per-file rules for notebooks. * Format and Lint all files/notebooks with ruff * add ruff format/lint checks in repo and format all notebooks * add github workflow, update GH actions so they only operate on changed files and restrict Claude workflow jobs to internal contributors Updates all three workflows to: - Accept pr_number as manual input parameter - Dynamically resolve PR number from event context - Fetch correct PR ref and base branch for manual triggers - Pass GH_TOKEN for gh CLI commands during manual dispatch
1 parent 4f3b478 commit 35bced5

File tree

109 files changed

+10320
-10629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+10320
-10629
lines changed

.claude/commands/link-review.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ allowed-tools: Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)
33
description: Review links in changed files for quality and security issues
44
---
55

6-
Review the links in the changed files and check for potential issues:
6+
**IMPORTANT**: Only review the files explicitly listed in the prompt above. Do not search for or review additional files.
7+
8+
Review the links in the specified changed files and check for potential issues:
79

810
## Link Quality Checks
911
1. **Broken Links**: Identify any links that might be broken or malformed

.claude/commands/model-check.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ allowed-tools: Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)
33
description: Validate Claude model usage against current public models
44
---
55

6-
Review the changed files for Claude model usage.
6+
**IMPORTANT**: Only review the files explicitly listed in the prompt above. Do not search for or review additional files.
7+
8+
Review the specified changed files for Claude model usage.
79

810
First, fetch the current list of allowed models from:
911
https://docs.claude.com/en/docs/about-claude/models/overview.md

.claude/commands/notebook-review.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ allowed-tools: Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(
33
description: Comprehensive review of Jupyter notebooks and Python scripts
44
---
55

6-
Review the changes to Jupyter notebooks and Python scripts in this PR using the Notebook review skill.
6+
**IMPORTANT**: Only review the files explicitly listed in the prompt above. Do not search for or review additional files.
7+
8+
Review the specified Jupyter notebooks and Python scripts using the Notebook review skill.
79

810
Provide a clear summary with:
911
- ✅ What looks good

.github/workflows/claude-link-review.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,74 @@ on:
88
- '**.mdx'
99
- '**.ipynb'
1010
- 'README.md'
11+
workflow_dispatch:
12+
inputs:
13+
pr_number:
14+
description: 'PR number to review'
15+
required: true
16+
type: number
1117

1218
jobs:
1319
link-review:
20+
# Only run for internal contributors (not forks) unless manually triggered
21+
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository
1422
runs-on: ubuntu-latest
1523
permissions:
1624
contents: read
1725
pull-requests: write
1826
steps:
19-
- name: Checkout repository
27+
- name: Set PR number
28+
id: pr-number
29+
run: |
30+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
31+
echo "number=${{ inputs.pr_number }}" >> $GITHUB_OUTPUT
32+
else
33+
echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
34+
fi
35+
36+
- name: Checkout PR
2037
uses: actions/checkout@v4
2138
with:
2239
fetch-depth: 0
40+
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/pull/{0}/head', inputs.pr_number) || '' }}
41+
42+
- name: Get changed files
43+
id: changed-files
44+
run: |
45+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
46+
# For manual dispatch, get base ref from PR
47+
BASE_REF=$(gh pr view ${{ steps.pr-number.outputs.number }} --json baseRefName -q .baseRefName)
48+
git fetch origin $BASE_REF
49+
CHANGED_FILES=$(git diff --name-only origin/$BASE_REF...HEAD | grep -E '\.(md|mdx|ipynb)$' || echo "")
50+
else
51+
git fetch origin ${{ github.base_ref }}
52+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.(md|mdx|ipynb)$' || echo "")
53+
fi
54+
55+
if [ -z "$CHANGED_FILES" ]; then
56+
echo "No relevant files changed"
57+
echo "has_files=false" >> $GITHUB_OUTPUT
58+
else
59+
echo "Changed files:"
60+
echo "$CHANGED_FILES"
61+
echo "$CHANGED_FILES" > changed_files.txt
62+
echo "has_files=true" >> $GITHUB_OUTPUT
63+
fi
64+
env:
65+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2366

2467
- name: Run Claude Link Review
68+
if: steps.changed-files.outputs.has_files == 'true'
2569
uses: anthropics/claude-code-action@v1
2670
with:
2771
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
2872
github_token: ${{ secrets.GITHUB_TOKEN }}
29-
prompt: "/link-review"
73+
prompt: |
74+
/link-review
75+
76+
Changed files to review:
77+
$(cat changed_files.txt)
3078
claude_args: |
3179
--allowedTools "Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(echo:*),Read,Glob,Grep,WebFetch"
3280
env:
33-
PR_NUMBER: ${{ github.event.pull_request.number }}
81+
PR_NUMBER: ${{ steps.pr-number.outputs.number }}

.github/workflows/claude-model-check.yml

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,76 @@ on:
77
- '**/*.ipynb'
88
- '**.py'
99
- '**.md'
10+
workflow_dispatch:
11+
inputs:
12+
pr_number:
13+
description: 'PR number to review'
14+
required: true
15+
type: number
1016

1117
permissions:
1218
contents: read
1319
pull-requests: write
1420

1521
jobs:
1622
model-check:
23+
# Only run for internal contributors (not forks) unless manually triggered
24+
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository
1725
runs-on: ubuntu-latest
18-
26+
1927
steps:
20-
- uses: actions/checkout@v4
28+
- name: Set PR number
29+
id: pr-number
30+
run: |
31+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
32+
echo "number=${{ inputs.pr_number }}" >> $GITHUB_OUTPUT
33+
else
34+
echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
35+
fi
36+
37+
- name: Checkout PR
38+
uses: actions/checkout@v4
2139
with:
2240
fetch-depth: 0
23-
41+
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/pull/{0}/head', inputs.pr_number) || '' }}
42+
43+
- name: Get changed files
44+
id: changed-files
45+
run: |
46+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
47+
# For manual dispatch, get base ref from PR
48+
BASE_REF=$(gh pr view ${{ steps.pr-number.outputs.number }} --json baseRefName -q .baseRefName)
49+
git fetch origin $BASE_REF
50+
CHANGED_FILES=$(git diff --name-only origin/$BASE_REF...HEAD | grep -E '\.(ipynb|py|md)$' || echo "")
51+
else
52+
git fetch origin ${{ github.base_ref }}
53+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.(ipynb|py|md)$' || echo "")
54+
fi
55+
56+
if [ -z "$CHANGED_FILES" ]; then
57+
echo "No relevant files changed"
58+
echo "has_files=false" >> $GITHUB_OUTPUT
59+
else
60+
echo "Changed files:"
61+
echo "$CHANGED_FILES"
62+
echo "$CHANGED_FILES" > changed_files.txt
63+
echo "has_files=true" >> $GITHUB_OUTPUT
64+
fi
65+
env:
66+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
2468
- name: Claude Model Validation
69+
if: steps.changed-files.outputs.has_files == 'true'
2570
uses: anthropics/claude-code-action@v1
2671
with:
2772
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
2873
github_token: ${{ secrets.GITHUB_TOKEN }}
29-
prompt: "/model-check"
74+
prompt: |
75+
/model-check
76+
77+
Changed files to review:
78+
$(cat changed_files.txt)
3079
claude_args: |
3180
--allowedTools "Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(echo:*),Read,Glob,Grep,WebFetch"
3281
env:
33-
PR_NUMBER: ${{ github.event.pull_request.number }}
82+
PR_NUMBER: ${{ steps.pr-number.outputs.number }}

.github/workflows/claude-notebook-review.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,74 @@ on:
88
- 'pyproject.toml'
99
- 'uv.lock'
1010
- 'scripts/**/*.py'
11+
workflow_dispatch:
12+
inputs:
13+
pr_number:
14+
description: 'PR number to review'
15+
required: true
16+
type: number
1117

1218
jobs:
1319
notebook-review:
20+
# Only run for internal contributors (not forks) unless manually triggered
21+
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository
1422
runs-on: ubuntu-latest
1523
permissions:
1624
contents: read
1725
pull-requests: write
1826
steps:
19-
- name: Checkout repository
27+
- name: Set PR number
28+
id: pr-number
29+
run: |
30+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
31+
echo "number=${{ inputs.pr_number }}" >> $GITHUB_OUTPUT
32+
else
33+
echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
34+
fi
35+
36+
- name: Checkout PR
2037
uses: actions/checkout@v4
2138
with:
2239
fetch-depth: 0
40+
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/pull/{0}/head', inputs.pr_number) || '' }}
41+
42+
- name: Get changed files
43+
id: changed-files
44+
run: |
45+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
46+
# For manual dispatch, get base ref from PR
47+
BASE_REF=$(gh pr view ${{ steps.pr-number.outputs.number }} --json baseRefName -q .baseRefName)
48+
git fetch origin $BASE_REF
49+
CHANGED_FILES=$(git diff --name-only origin/$BASE_REF...HEAD | grep -E '\.(ipynb|py)$' || echo "")
50+
else
51+
git fetch origin ${{ github.base_ref }}
52+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.(ipynb|py)$' || echo "")
53+
fi
54+
55+
if [ -z "$CHANGED_FILES" ]; then
56+
echo "No relevant files changed"
57+
echo "has_files=false" >> $GITHUB_OUTPUT
58+
else
59+
echo "Changed files:"
60+
echo "$CHANGED_FILES"
61+
echo "$CHANGED_FILES" > changed_files.txt
62+
echo "has_files=true" >> $GITHUB_OUTPUT
63+
fi
64+
env:
65+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2366

2467
- name: Run Claude Notebook Review
68+
if: steps.changed-files.outputs.has_files == 'true'
2569
uses: anthropics/claude-code-action@v1
2670
with:
2771
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
2872
github_token: ${{ secrets.GITHUB_TOKEN }}
29-
prompt: "/notebook-review"
73+
prompt: |
74+
/notebook-review
75+
76+
Changed files to review:
77+
$(cat changed_files.txt)
3078
claude_args: |
3179
--allowedTools "Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(echo:*),Read,Glob,Grep,WebFetch"
3280
env:
33-
PR_NUMBER: ${{ github.event.pull_request.number }}
81+
PR_NUMBER: ${{ steps.pr-number.outputs.number }}

0 commit comments

Comments
 (0)