Skip to content

Commit a51b29e

Browse files
authored
Refactor test processing and folder construction in vscode_pytest module (#25478)
1 parent cf088e8 commit a51b29e

File tree

4 files changed

+255
-84
lines changed

4 files changed

+255
-84
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
applyTo: 'python_files/**'
3+
description: Guide for running and fixing Python quality checks (Ruff and Pyright) that run in CI
4+
---
5+
6+
# Python Quality Checks — Ruff and Pyright
7+
8+
Run the same Python quality checks that run in CI. All checks target `python_files/` and use config from `python_files/pyproject.toml`.
9+
10+
## Commands
11+
12+
```bash
13+
npm run check-python # Run both Ruff and Pyright
14+
npm run check-python:ruff # Linting and formatting only
15+
npm run check-python:pyright # Type checking only
16+
```
17+
18+
## Fixing Ruff Errors
19+
20+
**Auto-fix most issues:**
21+
22+
```bash
23+
cd python_files
24+
python -m ruff check . --fix
25+
python -m ruff format
26+
npm run check-python:ruff # Verify
27+
```
28+
29+
**Manual fixes:**
30+
31+
- Ruff shows file, line number, rule code (e.g., `F841`), and description
32+
- Open the file, read the error, fix the code
33+
- Common: line length (100 char max), import sorting, unused variables
34+
35+
## Fixing Pyright Errors
36+
37+
**Common patterns and fixes:**
38+
39+
- **Undefined variable/import**: Add the missing import
40+
- **Type mismatch**: Correct the type or add type annotations
41+
- **Missing return type**: Add `-> ReturnType` to function signatures
42+
```python
43+
def my_function() -> str: # Add return type
44+
return "result"
45+
```
46+
47+
**Verify:**
48+
49+
```bash
50+
npm run check-python:pyright
51+
```
52+
53+
## Configuration
54+
55+
- **Ruff**: Line length 100, Python 3.9+, 40+ rule families (flake8, isort, pyupgrade, etc.)
56+
- **Pyright**: Version 1.1.308 (or whatever is found in the environment), ignores `lib/` and 15+ legacy files
57+
- Config: `python_files/pyproject.toml` sections `[tool.ruff]` and `[tool.pyright]`
58+
59+
## Troubleshooting
60+
61+
**"Module not found" in Pyright**: Install dependencies
62+
63+
```bash
64+
python -m pip install --upgrade -r build/test-requirements.txt
65+
nox --session install_python_libs
66+
```
67+
68+
**Import order errors**: Auto-fix with `ruff check . --fix`
69+
70+
**Type errors in ignored files**: Legacy files in `pyproject.toml` ignore list—fix if working on them
71+
72+
## Learnings
73+
74+
- Always run `npm run check-python` before pushing to catch CI failures early (1)
75+
- Use `ruff check . --fix` to auto-fix most linting issues before manual review (1)
76+
- Pyright version must match CI (1.1.308) to avoid inconsistent results between local and CI runs (1)

.vscode/tasks.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
"type": "npm",
1313
"script": "compile",
1414
"isBackground": true,
15-
"problemMatcher": [
16-
"$tsc-watch"
17-
],
15+
"problemMatcher": ["$tsc-watch"],
1816
"group": {
1917
"kind": "build",
2018
"isDefault": true
@@ -34,6 +32,13 @@
3432
"script": "preTestJediLSP",
3533
"problemMatcher": [],
3634
"label": "preTestJediLSP"
35+
},
36+
{
37+
"type": "npm",
38+
"script": "check-python",
39+
"problemMatcher": ["$python"],
40+
"label": "npm: check-python",
41+
"detail": "npm run check-python:ruff && npm run check-python:pyright"
3742
}
3843
]
3944
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,9 @@
16951695
"lint-fix": "eslint --fix src build pythonExtensionApi gulpfile.js",
16961696
"format-check": "prettier --check 'src/**/*.ts' 'build/**/*.js' '.github/**/*.yml' gulpfile.js",
16971697
"format-fix": "prettier --write 'src/**/*.ts' 'build/**/*.js' '.github/**/*.yml' gulpfile.js",
1698+
"check-python": "npm run check-python:ruff && npm run check-python:pyright",
1699+
"check-python:ruff": "cd python_files && python -m pip install -U ruff && python -m ruff check . && python -m ruff format --check",
1700+
"check-python:pyright": "cd python_files && npx --yes [email protected] .",
16981701
"clean": "gulp clean",
16991702
"addExtensionPackDependencies": "gulp addExtensionPackDependencies",
17001703
"updateBuildNumber": "gulp updateBuildNumber",

0 commit comments

Comments
 (0)