Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
77e0ee3
automatically run stub test
Joao-Dionisio Jan 14, 2026
ddf3d78
add isObjIntegral() for test
Joao-Dionisio Jan 14, 2026
e578db5
changelog
Joao-Dionisio Jan 14, 2026
1d7ed33
run on PR instead of pushes to master, and write a message
Joao-Dionisio Jan 14, 2026
6785f98
apply copilot suggestions
Joao-Dionisio Jan 14, 2026
292adf4
fix stub generator for numpy subclass overrides and Statistics types
Joao-Dionisio Jan 14, 2026
129eb2f
add type annotations to generated stub methods
Joao-Dionisio Jan 14, 2026
272d60b
add type annotations to __init__ and other special methods
Joao-Dionisio Jan 14, 2026
2eeedbb
fix auto-regeneration: add token, show diff in PR comment
Joao-Dionisio Jan 14, 2026
0a5ac24
restructure workflow: test -> regenerate -> test -> commit
Joao-Dionisio Jan 14, 2026
5645239
parse actual function parameters instead of using *args/**kwargs
Joao-Dionisio Jan 14, 2026
002afee
Add @disjoint_base decorator and fix sum() override for numpy subclasses
Joao-Dionisio Jan 14, 2026
75fdde8
Fix stubtest errors in stub generator
Joao-Dionisio Jan 14, 2026
746317c
Allow stub regeneration for forks when script is unchanged
Joao-Dionisio Jan 14, 2026
8cf8bc9
Only check script changes for fork PRs
Joao-Dionisio Jan 14, 2026
f36b628
Copy regenerated stub to installed location for stubtest
Joao-Dionisio Jan 14, 2026
490892e
Fix SIGPIPE error in commit step
Joao-Dionisio Jan 14, 2026
7ce6666
Auto-regenerate type stubs
github-actions[bot] Jan 14, 2026
3e22af9
Skip regeneration if stubtest already passes
Joao-Dionisio Jan 14, 2026
e67ee9a
Only import dataclass when needed
Joao-Dionisio Jan 14, 2026
6402c2d
Auto-fix some lint issues after stub regeneration
Joao-Dionisio Jan 14, 2026
e802f6f
Make lint job run after stubtest
Joao-Dionisio Jan 14, 2026
3e1ef48
Regenerate stubs without unused import
Joao-Dionisio Jan 14, 2026
564fe64
Disable auto-regeneration in CI, add pre-commit hook for stubs
Joao-Dionisio Jan 22, 2026
b74c23c
Merge master into auto-regenerate-stubs
Joao-Dionisio Jan 22, 2026
4592fab
Regenerate stubs, remove lint dependency on stubtest
Joao-Dionisio Jan 22, 2026
4be6d43
Fix stub generation for __array_ufunc__, Term, UnaryExpr, TYPE_CHECKING
Joao-Dionisio Jan 22, 2026
279bdca
Comment out auto-regeneration steps, simplify workflow
Joao-Dionisio Jan 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 117 additions & 2 deletions .github/workflows/stubs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,24 @@ jobs:
run: python -m mypy --package pyscipopt

- name: Run stubtest
id: stubtest
run: stubs/test.sh

- name: Stub regeneration hint
if: failure() && steps.stubtest.outcome == 'failure'
run: |
echo "Type stubs are out of date. Please regenerate them locally:"
echo ""
echo " python scripts/generate_stubs.py"
echo " pip install ruff"
echo " ruff check src/pyscipopt/scip.pyi --extend-select ANN,I,PYI,RUF100 --fix"
echo " ruff format src/pyscipopt/scip.pyi"
echo ""
echo "Then commit the updated scip.pyi file."
echo ""
echo "Tip: You can set up a pre-commit hook to do this automatically."
echo "See .pre-commit-config.yaml in the repository root."

lint:
runs-on: ubuntu-latest
env:
Expand All @@ -67,5 +83,104 @@ jobs:
- name: Lint type stubs
run: ruff check ${{ env.FILES }} --extend-select ANN,I,PYI,RUF100

- name: Format type stubs
run: ruff format ${{ env.FILES }}
- name: Format check type stubs
run: ruff format --check ${{ env.FILES }}

# =============================================================================
# AUTO-REGENERATION STEPS (disabled)
# =============================================================================
# TODO: To enable automatic stub regeneration in CI, uncomment the code below
# and add the following to the stubtest job:
# - Add these permissions to stubtest job:
# permissions:
# contents: write
# pull-requests: write
# - Add these to the checkout step:
# with:
# ref: ${{ github.head_ref || github.ref }}
# repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
# token: ${{ secrets.GITHUB_TOKEN }}
# fetch-depth: 0
# - Change "Run MyPy" and "Run stubtest" to have continue-on-error: true
# and rename to "Run MyPy (before regeneration)" / "Run stubtest (before regeneration)"
# - Add "needs: stubtest" to the lint job
# - Remove the "Stub regeneration hint" step
#
# Then uncomment these steps:
#
# - name: Check if safe to run generate_stubs.py
# id: check_script
# run: |
# # For same-repo PRs, always allow running the script
# if [[ "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]] || [[ "${{ github.event_name }}" != "pull_request" ]]; then
# echo "allowed=true" >> $GITHUB_OUTPUT
# echo "Same-repo PR or push - allowing regeneration"
# else
# # For fork PRs, only allow if script is unchanged from master
# git fetch origin master
# if git diff --quiet origin/master -- scripts/generate_stubs.py; then
# echo "allowed=true" >> $GITHUB_OUTPUT
# echo "Fork PR with unchanged script - allowing regeneration"
# else
# echo "allowed=false" >> $GITHUB_OUTPUT
# echo "::warning::Fork PR with modified scripts/generate_stubs.py - skipping auto-regeneration for security"
# fi
# fi
#
# - name: Regenerate stubs
# if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
# run: |
# python scripts/generate_stubs.py
# pip install ruff
# ruff check src/pyscipopt/scip.pyi --extend-select ANN,I,PYI,RUF100 --fix
# ruff format src/pyscipopt/scip.pyi
# cp src/pyscipopt/scip.pyi "$(python -c 'import pyscipopt; print(pyscipopt.__path__[0])')/scip.pyi"
#
# - name: Run MyPy (after regeneration)
# if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
# run: python -m mypy --package pyscipopt
#
# - name: Run stubtest (after regeneration)
# if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
# run: stubs/test.sh
#
# - name: Commit and push updated stubs
# id: commit
# if: steps.stubtest_before.outcome == 'failure' && github.event_name == 'pull_request' && steps.check_script.outputs.allowed == 'true' && github.event.pull_request.head.repo.full_name == github.repository
# run: |
# git config user.name "github-actions[bot]"
# git config user.email "github-actions[bot]@users.noreply.github.com"
# git add src/pyscipopt/scip.pyi
# DIFF=$(git diff --cached --stat)
# echo "diff<<EOF" >> $GITHUB_OUTPUT
# echo "$DIFF" >> $GITHUB_OUTPUT
# echo "EOF" >> $GITHUB_OUTPUT
# DETAILED_DIFF=$(git diff --cached src/pyscipopt/scip.pyi | head -100 || true)
# echo "detailed_diff<<EOF" >> $GITHUB_OUTPUT
# echo "$DETAILED_DIFF" >> $GITHUB_OUTPUT
# echo "EOF" >> $GITHUB_OUTPUT
# if git diff --cached --quiet; then
# echo "committed=false" >> $GITHUB_OUTPUT
# else
# git commit -m "Auto-regenerate type stubs"
# git push
# echo "committed=true" >> $GITHUB_OUTPUT
# fi
#
# - name: Comment on PR
# if: steps.commit.outputs.committed == 'true'
# env:
# GH_TOKEN: ${{ github.token }}
# run: |
# gh pr comment ${{ github.event.pull_request.number }} --body "## 🤖 Type stubs automatically regenerated
#
# The type stubs were out of date and have been automatically regenerated.
#
# <details>
# <summary>Changes summary</summary>
#
# \`\`\`
# ${{ steps.commit.outputs.diff }}
# \`\`\`
#
# </details>"
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Pre-commit hooks for PySCIPOpt
# Install with: pip install pre-commit && pre-commit install
#
# Note: The stub generation hook requires pyscipopt to be installed.
# If you haven't built pyscipopt yet, run: pip install -e .

repos:
- repo: local
hooks:
- id: regenerate-stubs
name: Regenerate type stubs
entry: bash -c 'python scripts/generate_stubs.py && pip install ruff -q && ruff check src/pyscipopt/scip.pyi --extend-select ANN,I,PYI,RUF100 --fix --quiet && ruff format src/pyscipopt/scip.pyi --quiet'
language: system
files: ^src/pyscipopt/.*\.(pxi|pxd|pyx)$
pass_filenames: false
stages: [pre-commit]
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Added automated script for generating type stubs
- Include parameter names in type stubs
- Speed up MatrixExpr.sum(axis=...) via quicksum
- Added pre-commit hook for automatic stub regeneration (see .pre-commit-config.yaml)
- Wrapped isObjIntegral() and test
- Added structured_optimization_trace recipe for structured optimization progress tracking
### Fixed
- getBestSol() now returns None for infeasible problems instead of a Solution with NULL pointer
Expand Down
Loading
Loading