Skip to content

Commit cc41cad

Browse files
committed
Merge branch 'master' into realtime-trace-jsonl
2 parents 6bf7355 + 1fdc6ca commit cc41cad

15 files changed

Lines changed: 1272 additions & 499 deletions

.github/workflows/stubs.yml

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,24 @@ jobs:
4949
run: python -m mypy --package pyscipopt
5050

5151
- name: Run stubtest
52+
id: stubtest
5253
run: stubs/test.sh
5354

55+
- name: Stub regeneration hint
56+
if: failure() && steps.stubtest.outcome == 'failure'
57+
run: |
58+
echo "Type stubs are out of date. Please regenerate them locally:"
59+
echo ""
60+
echo " python scripts/generate_stubs.py"
61+
echo " pip install ruff"
62+
echo " ruff check src/pyscipopt/scip.pyi --extend-select ANN,I,PYI,RUF100 --fix"
63+
echo " ruff format src/pyscipopt/scip.pyi"
64+
echo ""
65+
echo "Then commit the updated scip.pyi file."
66+
echo ""
67+
echo "Tip: You can set up a pre-commit hook to do this automatically."
68+
echo "See .pre-commit-config.yaml in the repository root."
69+
5470
lint:
5571
runs-on: ubuntu-latest
5672
env:
@@ -67,5 +83,104 @@ jobs:
6783
- name: Lint type stubs
6884
run: ruff check ${{ env.FILES }} --extend-select ANN,I,PYI,RUF100
6985

70-
- name: Format type stubs
71-
run: ruff format ${{ env.FILES }}
86+
- name: Format check type stubs
87+
run: ruff format --check ${{ env.FILES }}
88+
89+
# =============================================================================
90+
# AUTO-REGENERATION STEPS (disabled)
91+
# =============================================================================
92+
# TODO: To enable automatic stub regeneration in CI, uncomment the code below
93+
# and add the following to the stubtest job:
94+
# - Add these permissions to stubtest job:
95+
# permissions:
96+
# contents: write
97+
# pull-requests: write
98+
# - Add these to the checkout step:
99+
# with:
100+
# ref: ${{ github.head_ref || github.ref }}
101+
# repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
102+
# token: ${{ secrets.GITHUB_TOKEN }}
103+
# fetch-depth: 0
104+
# - Change "Run MyPy" and "Run stubtest" to have continue-on-error: true
105+
# and rename to "Run MyPy (before regeneration)" / "Run stubtest (before regeneration)"
106+
# - Add "needs: stubtest" to the lint job
107+
# - Remove the "Stub regeneration hint" step
108+
#
109+
# Then uncomment these steps:
110+
#
111+
# - name: Check if safe to run generate_stubs.py
112+
# id: check_script
113+
# run: |
114+
# # For same-repo PRs, always allow running the script
115+
# if [[ "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]] || [[ "${{ github.event_name }}" != "pull_request" ]]; then
116+
# echo "allowed=true" >> $GITHUB_OUTPUT
117+
# echo "Same-repo PR or push - allowing regeneration"
118+
# else
119+
# # For fork PRs, only allow if script is unchanged from master
120+
# git fetch origin master
121+
# if git diff --quiet origin/master -- scripts/generate_stubs.py; then
122+
# echo "allowed=true" >> $GITHUB_OUTPUT
123+
# echo "Fork PR with unchanged script - allowing regeneration"
124+
# else
125+
# echo "allowed=false" >> $GITHUB_OUTPUT
126+
# echo "::warning::Fork PR with modified scripts/generate_stubs.py - skipping auto-regeneration for security"
127+
# fi
128+
# fi
129+
#
130+
# - name: Regenerate stubs
131+
# if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
132+
# run: |
133+
# python scripts/generate_stubs.py
134+
# pip install ruff
135+
# ruff check src/pyscipopt/scip.pyi --extend-select ANN,I,PYI,RUF100 --fix
136+
# ruff format src/pyscipopt/scip.pyi
137+
# cp src/pyscipopt/scip.pyi "$(python -c 'import pyscipopt; print(pyscipopt.__path__[0])')/scip.pyi"
138+
#
139+
# - name: Run MyPy (after regeneration)
140+
# if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
141+
# run: python -m mypy --package pyscipopt
142+
#
143+
# - name: Run stubtest (after regeneration)
144+
# if: steps.stubtest_before.outcome == 'failure' && steps.check_script.outputs.allowed == 'true'
145+
# run: stubs/test.sh
146+
#
147+
# - name: Commit and push updated stubs
148+
# id: commit
149+
# 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
150+
# run: |
151+
# git config user.name "github-actions[bot]"
152+
# git config user.email "github-actions[bot]@users.noreply.github.com"
153+
# git add src/pyscipopt/scip.pyi
154+
# DIFF=$(git diff --cached --stat)
155+
# echo "diff<<EOF" >> $GITHUB_OUTPUT
156+
# echo "$DIFF" >> $GITHUB_OUTPUT
157+
# echo "EOF" >> $GITHUB_OUTPUT
158+
# DETAILED_DIFF=$(git diff --cached src/pyscipopt/scip.pyi | head -100 || true)
159+
# echo "detailed_diff<<EOF" >> $GITHUB_OUTPUT
160+
# echo "$DETAILED_DIFF" >> $GITHUB_OUTPUT
161+
# echo "EOF" >> $GITHUB_OUTPUT
162+
# if git diff --cached --quiet; then
163+
# echo "committed=false" >> $GITHUB_OUTPUT
164+
# else
165+
# git commit -m "Auto-regenerate type stubs"
166+
# git push
167+
# echo "committed=true" >> $GITHUB_OUTPUT
168+
# fi
169+
#
170+
# - name: Comment on PR
171+
# if: steps.commit.outputs.committed == 'true'
172+
# env:
173+
# GH_TOKEN: ${{ github.token }}
174+
# run: |
175+
# gh pr comment ${{ github.event.pull_request.number }} --body "## 🤖 Type stubs automatically regenerated
176+
#
177+
# The type stubs were out of date and have been automatically regenerated.
178+
#
179+
# <details>
180+
# <summary>Changes summary</summary>
181+
#
182+
# \`\`\`
183+
# ${{ steps.commit.outputs.diff }}
184+
# \`\`\`
185+
#
186+
# </details>"

.pre-commit-config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Pre-commit hooks for PySCIPOpt
2+
# Install with: pip install pre-commit && pre-commit install
3+
#
4+
# Note: The stub generation hook requires pyscipopt to be installed.
5+
# If you haven't built pyscipopt yet, run: pip install -e .
6+
7+
repos:
8+
- repo: local
9+
hooks:
10+
- id: regenerate-stubs
11+
name: Regenerate type stubs
12+
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'
13+
language: system
14+
files: ^src/pyscipopt/.*\.(pxi|pxd|pyx)$
15+
pass_filenames: false
16+
stages: [pre-commit]

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@
55
- Added automated script for generating type stubs
66
- Include parameter names in type stubs
77
- Speed up MatrixExpr.sum(axis=...) via quicksum
8+
- Added pre-commit hook for automatic stub regeneration (see .pre-commit-config.yaml)
9+
- Wrapped isObjIntegral() and test
810
- Added structured_optimization_trace recipe for structured optimization progress tracking
911
- Added realtime_trace_jsonl recipe for real-time optimization progress tracking with JSONL streaming output
1012
### Fixed
13+
- getBestSol() now returns None for infeasible problems instead of a Solution with NULL pointer
1114
- all fundamental callbacks now raise an error if not implemented
1215
- Fixed the type of MatrixExpr.sum(axis=...) result from MatrixVariable to MatrixExpr.
1316
- Updated IIS result in PyiisfinderExec()
17+
- Model.getVal now supports GenExpr type
1418
- Fixed lotsizing_lazy example
1519
- Fixed incorrect getVal() result when _bestSol.sol was outdated
20+
- Fixed segmentation fault when using Variable or Constraint objects after freeTransform() or Model destruction
1621
### Changed
1722
- changed default value of enablepricing flag to True
23+
- Speed up MatrixExpr.add.reduce via quicksum
24+
- Speed up np.ndarray(..., dtype=np.float64) @ MatrixExpr
25+
- MatrixExpr and MatrixExprCons use `__array_ufunc__` protocol to control all numpy.ufunc inputs and outputs
1826
### Removed
1927

2028
## 6.0.0 - 2025.xx.yy

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ['setuptools', 'cython >=0.21']
2+
requires = ["setuptools", "cython >=0.21", "numpy"]
33
build-backend = "setuptools.build_meta"
44

55
[project]

0 commit comments

Comments
 (0)