Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a37446

Browse files
committed
Complement upgrade-pylib Claude Code command
1 parent 6d726d4 commit 7a37446

File tree

1 file changed

+81
-5
lines changed

1 file changed

+81
-5
lines changed

.claude/commands/upgrade-pylib.md

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,62 @@ Upgrade a Python standard library module from CPython to RustPython.
1515
- If `cpython/Lib/$ARGUMENTS.py` exists, copy it to `Lib/$ARGUMENTS.py`
1616
- If `cpython/Lib/$ARGUMENTS/` directory exists, copy it to `Lib/$ARGUMENTS/`
1717

18-
3. **Upgrade tests**
19-
- Run: `python lib_updater.py --quick-upgrade cpython/Lib/test/test_$ARGUMENTS`
20-
- This will update the test files with appropriate RustPython markers
18+
3. **Upgrade tests (quick upgrade with lib_updater)**
19+
- If `cpython/Lib/test/test_$ARGUMENTS.py` is a single file:
20+
- Run: `python3 scripts/lib_updater.py --quick-upgrade cpython/Lib/test/test_$ARGUMENTS.py`
21+
- If `cpython/Lib/test/test_$ARGUMENTS/` is a directory:
22+
- Run the script for each `.py` file in the directory:
23+
```bash
24+
for f in cpython/Lib/test/test_$ARGUMENTS/*.py; do
25+
python3 scripts/lib_updater.py --quick-upgrade "$f"
26+
done
27+
```
28+
- This will update the test files with basic RustPython markers (`@unittest.expectedFailure`, `@unittest.skip`, etc.)
29+
- **Handle lib_updater warnings**: If you see warnings like `WARNING: TestCFoo does not exist in remote file`, it means the class structure changed between versions and markers couldn't be transferred automatically. These need to be manually restored in step 4 or added in step 5.
30+
31+
4. **Review git diff and restore RUSTPYTHON-specific changes**
32+
- Run `git diff Lib/test/test_$ARGUMENTS` to review all changes
33+
- **Only restore changes that have explicit `RUSTPYTHON` comments**. Look for:
34+
- `# XXX: RUSTPYTHON` or `# XXX RUSTPYTHON` - Comments marking RustPython-specific code modifications
35+
- `# TODO: RUSTPYTHON` - Comments marking tests that need work
36+
- Code changes with inline `# ... RUSTPYTHON` comments
37+
- **Do NOT restore other diff changes** - these are likely upstream CPython changes, not RustPython-specific modifications
38+
- When restoring, preserve the original context and formatting
39+
40+
5. **Verify tests**
41+
- Run: `cargo run --release -- -m test test_$ARGUMENTS -v`
42+
- The `-v` flag shows detailed output to identify which tests fail and why
43+
- For each new failure, add appropriate markers based on the failure type:
44+
- **Test assertion failure** → `@unittest.expectedFailure` with `# TODO: RUSTPYTHON` comment
45+
- **Panic/crash** → `@unittest.skip("TODO: RUSTPYTHON; <panic message>")`
46+
- **Class-specific markers**: If a test fails only in the C implementation (TestCFoo) but passes in the Python implementation (TestPyFoo), or vice versa, add the marker to the specific subclass, not the base class:
47+
```python
48+
# Base class - no marker here
49+
class TestFoo:
50+
def test_something(self):
51+
...
52+
53+
class TestPyFoo(TestFoo, PyTest): pass
54+
55+
class TestCFoo(TestFoo, CTest):
56+
# TODO: RUSTPYTHON
57+
@unittest.expectedFailure
58+
def test_something(self):
59+
return super().test_something()
60+
```
61+
- **New tests from CPython**: The upgrade may bring in entirely new tests that didn't exist before. These won't have any RUSTPYTHON markers in the diff - they just need to be tested and marked if they fail.
62+
- Example markers:
63+
```python
64+
# TODO: RUSTPYTHON
65+
@unittest.expectedFailure
66+
def test_something(self):
67+
...
68+
69+
# TODO: RUSTPYTHON
70+
@unittest.skip("TODO: RUSTPYTHON; panics with 'index out of bounds'")
71+
def test_crashes(self):
72+
...
73+
```
2174
2275
## Example Usage
2376
```
@@ -26,7 +79,30 @@ Upgrade a Python standard library module from CPython to RustPython.
2679
/upgrade-pylib asyncio
2780
```
2881
82+
## Example: Restoring RUSTPYTHON changes
83+
84+
When git diff shows removed RUSTPYTHON-specific code like:
85+
```diff
86+
-# XXX RUSTPYTHON: we don't import _json as fresh since...
87+
-cjson = import_helper.import_fresh_module('json') #, fresh=['_json'])
88+
+cjson = import_helper.import_fresh_module('json', fresh=['_json'])
89+
```
90+
91+
You should restore the RustPython version:
92+
```python
93+
# XXX RUSTPYTHON: we don't import _json as fresh since...
94+
cjson = import_helper.import_fresh_module('json') #, fresh=['_json'])
95+
```
96+
2997
## Notes
3098
- The cpython/ directory should contain the CPython source that we're syncing from
31-
- lib_updater.py handles adding `# TODO: RUSTPYTHON` markers and `@unittest.expectedFailure` decorators
32-
- After upgrading, you may need to run tests to verify: `cargo run --release -- -m test test_$ARGUMENTS`
99+
- `scripts/lib_updater.py` handles basic patching:
100+
- Transfers `@unittest.expectedFailure` and `@unittest.skip` decorators with `TODO: RUSTPYTHON` markers
101+
- Adds `import unittest # XXX: RUSTPYTHON` if needed for the decorators
102+
- **Limitation**: If a class was restructured (e.g., method overrides removed), lib_updater will warn and skip those markers
103+
- The script does NOT preserve all RustPython-specific changes - you must review `git diff` and restore them
104+
- Common RustPython markers to look for:
105+
- `# XXX: RUSTPYTHON` or `# XXX RUSTPYTHON` - Inline comments for code modifications
106+
- `# TODO: RUSTPYTHON` - Test skip/failure markers
107+
- Any code with `RUSTPYTHON` in comments that was removed in the diff
108+
- **Important**: Not all changes in the git diff need to be restored. Only restore changes that have explicit `RUSTPYTHON` comments. Other changes are upstream CPython updates.

0 commit comments

Comments
 (0)