Commit f0704d3
authored
fix: Improve Python project detection and entrypoint resolution (#1010)
### Summary
- Simplified Python project detection to discover packages purely by
looking for directories with `__init__.py` files.
- Derived default Actor name from the Python package name.
- Added near-miss detection with actionable fix suggestions for broken
Python packages.
- Subpackage detection.
- Added 29 unit tests covering the full detection matrix.
### Python project detection
- Detect Python projects purely via package structure: directories with
valid Python identifier names containing `__init__.py`.
- Skip hidden directories (`.venv`) and underscore-prefixed directories
(`__pycache__`, `_internal`) as they shouldn't be main entrypoints.
- When `src/` is itself a package (has `__init__.py`), treat nested
directories as subpackages, not separate top-level packages.
### Actor name derivation
- For Python projects, the default Actor name is derived from the
package name.
- Entrypoint src.my_package → extracts my_package → sanitizes to
my-package.
- Entrypoint my_package → sanitizes to my-package.
### Runtime precedence
- Node.js (`package.json`) takes precedence over Python indicators when
both exist.
### Error handling
- Near-miss: invalid name + `__init__.py` — suggests renaming the
directory (e.g., my-package/ → my_package/)
- Near-miss: valid name + .py files but no `__init__.py` — suggests
adding `__init__.py`
- Near-miss: invalid name + .py files but no `__init__.py` — suggests
both renaming and adding `__init__.py`
- Multiple packages — lists all found packages and guides user to ensure
only one top-level package exists
- No package and no Python files — returns Unknown (not a Python
project)
### Test plan
- 29 tests covering the full parametrized matrix: {CWD with dashes |
underscores} × {flat | src container} × {valid | invalid pkg name} ×
{`__init__.py` + .py | .py only | no .py} = 24 cases, plus 5 individual
cases:
- JavaScript and Python coexistence (JS takes precedence)
- Multiple flat packages error
- Multiple packages in `src/` error
- Loose .py files without package structure
- No Python project at all (Unknown)
- All existing local tests pass
---
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com1 parent 02ca16d commit f0704d3
5 files changed
Lines changed: 832 additions & 42 deletions
File tree
- src
- commands
- lib/hooks
- test
- lib/hooks
- local/__fixtures__/commands/run/python
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
60 | 74 | | |
61 | 75 | | |
62 | 76 | | |
| |||
100 | 114 | | |
101 | 115 | | |
102 | 116 | | |
103 | | - | |
| 117 | + | |
104 | 118 | | |
105 | 119 | | |
106 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
133 | 139 | | |
134 | 140 | | |
135 | 141 | | |
| |||
0 commit comments