modern-python-guidance 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- modern_python_guidance-0.1.2/CHANGELOG.md +47 -0
- modern_python_guidance-0.1.2/LICENSE-MIT +21 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/PKG-INFO +47 -10
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/README.md +43 -8
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/pyproject.toml +3 -2
- modern_python_guidance-0.1.2/skills/modern-python-guidance/SKILL.md +62 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/src/modern_python_guidance/__init__.py +1 -1
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/src/modern_python_guidance/cli.py +11 -0
- modern_python_guidance-0.1.2/src/modern_python_guidance/mcp_server.py +398 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/tests/test_cli_integration.py +3 -1
- modern_python_guidance-0.1.2/tests/test_mcp_server.py +304 -0
- modern_python_guidance-0.1.2/tests/test_skill_sync.py +126 -0
- modern_python_guidance-0.1.0/CHANGELOG.md +0 -21
- modern_python_guidance-0.1.0/skills/modern-python-guidance/SKILL.md +0 -104
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/.github/workflows/ci.yml +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/.github/workflows/publish.yml +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/.gitignore +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/LICENSE +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/SECURITY.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/docs/design.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/async/async-timeout-context.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/async/exception-groups.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/async/taskgroup-over-gather.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/data-structures/dataclass-modern.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/data-structures/dict-merge-operator.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/data-structures/match-case-patterns.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/fastapi/fastapi-annotated-depends.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/fastapi/fastapi-lifespan.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/fastapi/fastapi-typed-state.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/httpx/httpx-async-client-reuse.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/httpx/httpx-streaming.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/pydantic/pydantic-v2-config.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/pydantic/pydantic-v2-model-api.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/pydantic/pydantic-v2-serialization.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/pydantic/pydantic-v2-validators.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/stdlib/datetime-utc.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/stdlib/pathlib-over-os-path.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/stdlib/removeprefix-removesuffix.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/stdlib/tomllib-builtin.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/toolchain/no-pickle.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/toolchain/pyproject-toml-over-setup.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/toolchain/ruff-over-flake8.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/toolchain/safe-subprocess.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/toolchain/uv-over-pip.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/typing/override-decorator.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/typing/paramspec-decorators.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/typing/type-parameter-syntax.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/typing/typeis-vs-typeguard.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/typing/union-syntax.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/skills/modern-python-guidance/guides/typing/use-builtin-generics.md +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/src/modern_python_guidance/__main__.py +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/src/modern_python_guidance/compat.py +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/src/modern_python_guidance/frontmatter.py +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/src/modern_python_guidance/guide_index.py +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/src/modern_python_guidance/retrieve.py +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/src/modern_python_guidance/search.py +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/src/modern_python_guidance/version_detect.py +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/tests/test_frontmatter.py +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/tests/test_retrieve.py +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/tests/test_search.py +0 -0
- {modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/tests/test_version_detect.py +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.2] — 2026-05-26
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- SKILL.md: replace inventory tables with 9 embedded BAD→GOOD arrow-list patterns (high-frequency × Ruff-uncovered) for pre-generation injection without MCP tool calls
|
|
10
|
+
- README: Quick start example changed from `use-builtin-generics` to `pydantic-v2-validators` (Layer 2 differentiation)
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- MIT license (dual-licensed under Apache-2.0 OR MIT)
|
|
15
|
+
- `test_skill_sync.py`: 8 sync tests for SKILL.md ↔ guide file consistency (V-001/V-002/V-009/V-010)
|
|
16
|
+
|
|
17
|
+
## [0.1.1] — 2026-05-25
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- Built-in MCP server (`mpg mcp`) exposing all 4 commands as tools over JSON-RPC 2.0 stdio transport — zero additional dependencies
|
|
22
|
+
- Setup: `claude mcp add mpg -- mpg mcp` for Claude Code, or add to `.mcp.json` manually
|
|
23
|
+
- 4 MCP tools: `search_guides`, `retrieve_guides`, `list_guides`, `detect_python_version`
|
|
24
|
+
- CWD confinement for `detect_python_version` (rejects absolute paths, traversal, symlink escape)
|
|
25
|
+
- Resilient message parsing: malformed messages are skipped instead of crashing the server
|
|
26
|
+
- JSON-RPC 2.0 notification compliance (no response for messages without `id`)
|
|
27
|
+
- 19 subprocess-based integration tests for MCP server
|
|
28
|
+
|
|
29
|
+
## [0.1.0] — 2026-05-24
|
|
30
|
+
|
|
31
|
+
Initial release.
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- CLI tool with `search`, `retrieve`, `list`, and `detect-version` commands
|
|
36
|
+
- `mpg` short alias (both `mpg` and `modern-python-guidance` work)
|
|
37
|
+
- 30 version-aware BAD/GOOD pattern guides across 3 layers: stdlib (16), frameworks (9), toolchain (5)
|
|
38
|
+
- Weighted keyword search with fuzzy fallback via `difflib.SequenceMatcher`
|
|
39
|
+
- Python version auto-detection from `pyproject.toml`, `.python-version`, or `--python-version` flag
|
|
40
|
+
- JSON output (default when piped) and human-readable output (default for TTY)
|
|
41
|
+
- Agent Skills plugin (`SKILL.md`) for Claude Code integration
|
|
42
|
+
- Strict YAML-subset frontmatter parser (no PyYAML dependency)
|
|
43
|
+
- GitHub Actions CI (pytest + ruff on Python 3.11, 3.12, 3.13)
|
|
44
|
+
|
|
45
|
+
[0.1.2]: https://github.com/yottayoshida/modern-python-guidance/releases/tag/v0.1.2
|
|
46
|
+
[0.1.1]: https://github.com/yottayoshida/modern-python-guidance/releases/tag/v0.1.1
|
|
47
|
+
[0.1.0]: https://github.com/yottayoshida/modern-python-guidance/releases/tag/v0.1.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Iori Yoshida
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modern-python-guidance
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Version-aware BAD/GOOD pattern guides that help AI coding agents generate modern Python
|
|
5
5
|
Project-URL: Homepage, https://github.com/yottayoshida/modern-python-guidance
|
|
6
6
|
Project-URL: Repository, https://github.com/yottayoshida/modern-python-guidance
|
|
7
7
|
Project-URL: Issues, https://github.com/yottayoshida/modern-python-guidance/issues
|
|
8
8
|
Author-email: Iori Yoshida <i.yoshida@raksul.com>
|
|
9
|
-
License-Expression: Apache-2.0
|
|
9
|
+
License-Expression: Apache-2.0 OR MIT
|
|
10
10
|
License-File: LICENSE
|
|
11
|
+
License-File: LICENSE-MIT
|
|
11
12
|
Keywords: ai,coding-agent,guidance,linter,modernization,python
|
|
12
13
|
Classifier: Development Status :: 3 - Alpha
|
|
13
14
|
Classifier: Environment :: Console
|
|
14
15
|
Classifier: Intended Audience :: Developers
|
|
15
16
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
18
|
Classifier: Programming Language :: Python :: 3
|
|
17
19
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
@@ -45,17 +47,17 @@ LLMs often produce outdated Python — `typing.List` instead of `list`, `@valida
|
|
|
45
47
|
pip install modern-python-guidance
|
|
46
48
|
|
|
47
49
|
# Search for a pattern
|
|
48
|
-
mpg search "
|
|
49
|
-
#
|
|
50
|
+
mpg search "pydantic validator"
|
|
51
|
+
# pydantic-v2-validators score=18.0 [pydantic]
|
|
50
52
|
|
|
51
53
|
# Get the full guide
|
|
52
|
-
mpg retrieve
|
|
53
|
-
# ---
|
|
54
|
+
mpg retrieve pydantic-v2-validators
|
|
55
|
+
# --- pydantic-v2-validators (version match: YES) ---
|
|
54
56
|
# ## BAD
|
|
55
|
-
#
|
|
57
|
+
# @validator("name")
|
|
56
58
|
# ...
|
|
57
59
|
# ## GOOD
|
|
58
|
-
#
|
|
60
|
+
# @field_validator("name")
|
|
59
61
|
# ...
|
|
60
62
|
```
|
|
61
63
|
|
|
@@ -110,6 +112,40 @@ mpg list --python-version 3.9
|
|
|
110
112
|
# Excludes: TaskGroup (3.11+), match/case (3.10+), etc.
|
|
111
113
|
```
|
|
112
114
|
|
|
115
|
+
## MCP server
|
|
116
|
+
|
|
117
|
+
mpg includes a built-in [MCP](https://modelcontextprotocol.io) server that exposes all 4 commands as tools. AI agents (Claude Code, Cursor, Gemini CLI, etc.) can discover and call them directly.
|
|
118
|
+
|
|
119
|
+
### Setup with Claude Code
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
claude mcp add mpg -- mpg mcp
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Or add to `.mcp.json` manually:
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"mcpServers": {
|
|
130
|
+
"mpg": {
|
|
131
|
+
"command": "mpg",
|
|
132
|
+
"args": ["mcp"]
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Available tools
|
|
139
|
+
|
|
140
|
+
| Tool | Description |
|
|
141
|
+
|------|-------------|
|
|
142
|
+
| `search_guides` | Search guides by keyword with fuzzy matching |
|
|
143
|
+
| `retrieve_guides` | Get full BAD/GOOD content by guide ID |
|
|
144
|
+
| `list_guides` | Browse all guides, filter by category/version |
|
|
145
|
+
| `detect_python_version` | Auto-detect project Python version |
|
|
146
|
+
|
|
147
|
+
The MCP server uses stdio transport (JSON-RPC 2.0) and adds zero additional dependencies.
|
|
148
|
+
|
|
113
149
|
## Agent Skills integration
|
|
114
150
|
|
|
115
151
|
This project doubles as a [Claude Code Agent Skills](https://docs.anthropic.com/en/docs/claude-code) plugin. Install it into your project's `.claude/skills/` to give Claude automatic access to modern Python patterns when writing or reviewing code.
|
|
@@ -139,7 +175,8 @@ ruff check src/ tests/
|
|
|
139
175
|
|
|
140
176
|
```
|
|
141
177
|
src/modern_python_guidance/
|
|
142
|
-
├── cli.py # Entry point (search, retrieve, list, detect-version)
|
|
178
|
+
├── cli.py # Entry point (search, retrieve, list, detect-version, mcp)
|
|
179
|
+
├── mcp_server.py # MCP server (JSON-RPC 2.0 over stdio)
|
|
143
180
|
├── frontmatter.py # YAML-subset parser (no PyYAML dependency)
|
|
144
181
|
├── guide_index.py # Guide discovery and indexing
|
|
145
182
|
├── search.py # Weighted keyword search + fuzzy fallback
|
|
@@ -177,4 +214,4 @@ Contributions welcome! To add a new guide:
|
|
|
177
214
|
|
|
178
215
|
## License
|
|
179
216
|
|
|
180
|
-
Apache-2.0 — see [LICENSE](LICENSE).
|
|
217
|
+
Apache-2.0 OR MIT — see [LICENSE](LICENSE) and [LICENSE-MIT](LICENSE-MIT).
|
|
@@ -16,17 +16,17 @@ LLMs often produce outdated Python — `typing.List` instead of `list`, `@valida
|
|
|
16
16
|
pip install modern-python-guidance
|
|
17
17
|
|
|
18
18
|
# Search for a pattern
|
|
19
|
-
mpg search "
|
|
20
|
-
#
|
|
19
|
+
mpg search "pydantic validator"
|
|
20
|
+
# pydantic-v2-validators score=18.0 [pydantic]
|
|
21
21
|
|
|
22
22
|
# Get the full guide
|
|
23
|
-
mpg retrieve
|
|
24
|
-
# ---
|
|
23
|
+
mpg retrieve pydantic-v2-validators
|
|
24
|
+
# --- pydantic-v2-validators (version match: YES) ---
|
|
25
25
|
# ## BAD
|
|
26
|
-
#
|
|
26
|
+
# @validator("name")
|
|
27
27
|
# ...
|
|
28
28
|
# ## GOOD
|
|
29
|
-
#
|
|
29
|
+
# @field_validator("name")
|
|
30
30
|
# ...
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -81,6 +81,40 @@ mpg list --python-version 3.9
|
|
|
81
81
|
# Excludes: TaskGroup (3.11+), match/case (3.10+), etc.
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
## MCP server
|
|
85
|
+
|
|
86
|
+
mpg includes a built-in [MCP](https://modelcontextprotocol.io) server that exposes all 4 commands as tools. AI agents (Claude Code, Cursor, Gemini CLI, etc.) can discover and call them directly.
|
|
87
|
+
|
|
88
|
+
### Setup with Claude Code
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
claude mcp add mpg -- mpg mcp
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Or add to `.mcp.json` manually:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"mcpServers": {
|
|
99
|
+
"mpg": {
|
|
100
|
+
"command": "mpg",
|
|
101
|
+
"args": ["mcp"]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Available tools
|
|
108
|
+
|
|
109
|
+
| Tool | Description |
|
|
110
|
+
|------|-------------|
|
|
111
|
+
| `search_guides` | Search guides by keyword with fuzzy matching |
|
|
112
|
+
| `retrieve_guides` | Get full BAD/GOOD content by guide ID |
|
|
113
|
+
| `list_guides` | Browse all guides, filter by category/version |
|
|
114
|
+
| `detect_python_version` | Auto-detect project Python version |
|
|
115
|
+
|
|
116
|
+
The MCP server uses stdio transport (JSON-RPC 2.0) and adds zero additional dependencies.
|
|
117
|
+
|
|
84
118
|
## Agent Skills integration
|
|
85
119
|
|
|
86
120
|
This project doubles as a [Claude Code Agent Skills](https://docs.anthropic.com/en/docs/claude-code) plugin. Install it into your project's `.claude/skills/` to give Claude automatic access to modern Python patterns when writing or reviewing code.
|
|
@@ -110,7 +144,8 @@ ruff check src/ tests/
|
|
|
110
144
|
|
|
111
145
|
```
|
|
112
146
|
src/modern_python_guidance/
|
|
113
|
-
├── cli.py # Entry point (search, retrieve, list, detect-version)
|
|
147
|
+
├── cli.py # Entry point (search, retrieve, list, detect-version, mcp)
|
|
148
|
+
├── mcp_server.py # MCP server (JSON-RPC 2.0 over stdio)
|
|
114
149
|
├── frontmatter.py # YAML-subset parser (no PyYAML dependency)
|
|
115
150
|
├── guide_index.py # Guide discovery and indexing
|
|
116
151
|
├── search.py # Weighted keyword search + fuzzy fallback
|
|
@@ -148,4 +183,4 @@ Contributions welcome! To add a new guide:
|
|
|
148
183
|
|
|
149
184
|
## License
|
|
150
185
|
|
|
151
|
-
Apache-2.0 — see [LICENSE](LICENSE).
|
|
186
|
+
Apache-2.0 OR MIT — see [LICENSE](LICENSE) and [LICENSE-MIT](LICENSE-MIT).
|
|
@@ -4,10 +4,10 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "modern-python-guidance"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "Version-aware BAD/GOOD pattern guides that help AI coding agents generate modern Python"
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
license = "Apache-2.0"
|
|
10
|
+
license = "Apache-2.0 OR MIT"
|
|
11
11
|
requires-python = ">=3.11"
|
|
12
12
|
authors = [
|
|
13
13
|
{ name = "Iori Yoshida", email = "i.yoshida@raksul.com" },
|
|
@@ -18,6 +18,7 @@ classifiers = [
|
|
|
18
18
|
"Environment :: Console",
|
|
19
19
|
"Intended Audience :: Developers",
|
|
20
20
|
"License :: OSI Approved :: Apache Software License",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
21
22
|
"Programming Language :: Python :: 3",
|
|
22
23
|
"Programming Language :: Python :: 3.11",
|
|
23
24
|
"Programming Language :: Python :: 3.12",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: modern-python-guidance
|
|
3
|
+
description: Version-aware BAD/GOOD pattern guides for modern Python. Use when writing, reviewing, or refactoring Python code to avoid outdated patterns (e.g. typing.List → list, @validator → @field_validator, setup.py → pyproject.toml). Triggers on "Python", "modernize", "upgrade", "deprecated", "pydantic", "fastapi", "httpx", "typing", "dataclass", "asyncio".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Modern Python Guidance
|
|
7
|
+
|
|
8
|
+
Pre-generation design patterns that Ruff cannot auto-fix. Apply these transformations when writing or reviewing Python code.
|
|
9
|
+
|
|
10
|
+
## When to use
|
|
11
|
+
|
|
12
|
+
- Writing new Python code (use modern patterns from the start)
|
|
13
|
+
- Reviewing Python code (flag outdated patterns)
|
|
14
|
+
- Migrating from Pydantic V1 to V2
|
|
15
|
+
- Upgrading Python version (check which new features are available)
|
|
16
|
+
- Replacing legacy tooling (setup.py, flake8, pip)
|
|
17
|
+
|
|
18
|
+
## Embedded patterns (high-frequency, Ruff-uncovered)
|
|
19
|
+
|
|
20
|
+
### Pydantic V2 (>=3.9)
|
|
21
|
+
|
|
22
|
+
- `@validator("f")` → `@field_validator("f")`
|
|
23
|
+
- `@root_validator` → `@model_validator(mode="after")`
|
|
24
|
+
- `class Config:` → `model_config = ConfigDict(...)`
|
|
25
|
+
- `orm_mode` → `from_attributes`, `allow_population_by_field_name` → `populate_by_name`
|
|
26
|
+
- `.parse_obj(d)` → `.model_validate(d)`, `.parse_raw(j)` → `.model_validate_json(j)`
|
|
27
|
+
- `.dict()` → `.model_dump()`, `.json()` → `.model_dump_json()`
|
|
28
|
+
- `.schema()` → `.model_json_schema()`, `.copy()` → `.model_copy()`
|
|
29
|
+
|
|
30
|
+
### FastAPI (>=3.9)
|
|
31
|
+
|
|
32
|
+
- `@app.on_event("startup")`/`"shutdown"` → `@asynccontextmanager` lifespan + `FastAPI(lifespan=lifespan)`; yield dict becomes `request.state`
|
|
33
|
+
- `db: Session = Depends(get_db)` → `DbDep = Annotated[Session, Depends(get_db)]`; reusable type alias per PEP 593
|
|
34
|
+
|
|
35
|
+
### httpx
|
|
36
|
+
|
|
37
|
+
- Per-request `async with httpx.AsyncClient()` → shared `AsyncClient` with `base_url`
|
|
38
|
+
- Caveat: shared client must be closed via `async with` or lifespan management
|
|
39
|
+
|
|
40
|
+
### asyncio (>=3.11)
|
|
41
|
+
|
|
42
|
+
- `await asyncio.gather(a(), b())` → `async with asyncio.TaskGroup() as tg:` + `tg.create_task()`; access results via `task.result()`
|
|
43
|
+
- Caveat: 3.11+ only. `TaskGroup` cancels siblings on error and raises `ExceptionGroup`; `gather` preserves return order and supports `return_exceptions=True`
|
|
44
|
+
|
|
45
|
+
### Toolchain
|
|
46
|
+
|
|
47
|
+
- `setup.py` / `setup.cfg` → `pyproject.toml` with `[build-system]` + `[project]` (PEP 621)
|
|
48
|
+
- `subprocess.run(f"cmd {arg}", shell=True)` → `subprocess.run(["cmd", arg], check=True)`
|
|
49
|
+
- Caveat: `shell=True` is valid when pipes/globs are needed; use `shlex.quote()` for user input
|
|
50
|
+
|
|
51
|
+
## All 30 guides by category
|
|
52
|
+
|
|
53
|
+
- **typing** (6): `use-builtin-generics`, `union-syntax`, `type-parameter-syntax`, `override-decorator`, `typeis-vs-typeguard`, `paramspec-decorators`
|
|
54
|
+
- **async** (3): `taskgroup-over-gather`, `exception-groups`, `async-timeout-context`
|
|
55
|
+
- **stdlib** (4): `datetime-utc`, `pathlib-over-os-path`, `tomllib-builtin`, `removeprefix-removesuffix`
|
|
56
|
+
- **data-structures** (3): `dict-merge-operator`, `match-case-patterns`, `dataclass-modern`
|
|
57
|
+
- **pydantic** (4): `pydantic-v2-validators`, `pydantic-v2-config`, `pydantic-v2-model-api`, `pydantic-v2-serialization`
|
|
58
|
+
- **fastapi** (3): `fastapi-lifespan`, `fastapi-annotated-depends`, `fastapi-typed-state`
|
|
59
|
+
- **httpx** (2): `httpx-async-client-reuse`, `httpx-streaming`
|
|
60
|
+
- **toolchain** (5): `pyproject-toml-over-setup`, `uv-over-pip`, `ruff-over-flake8`, `no-pickle`, `safe-subprocess`
|
|
61
|
+
|
|
62
|
+
For full code examples, use `mpg retrieve <guide-id>` or MCP tool `retrieve_guides`.
|
{modern_python_guidance-0.1.0 → modern_python_guidance-0.1.2}/src/modern_python_guidance/cli.py
RENAMED
|
@@ -62,6 +62,9 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
62
62
|
p_detect = subparsers.add_parser("detect-version", help="Detect project Python version")
|
|
63
63
|
p_detect.add_argument("--project-dir", type=Path, help="Project directory (default: cwd)")
|
|
64
64
|
|
|
65
|
+
# mcp
|
|
66
|
+
subparsers.add_parser("mcp", help="Start MCP server (JSON-RPC over stdio)")
|
|
67
|
+
|
|
65
68
|
args = parser.parse_args(argv)
|
|
66
69
|
|
|
67
70
|
if args.command is None:
|
|
@@ -81,6 +84,8 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
81
84
|
_cmd_list(args)
|
|
82
85
|
elif args.command == "detect-version":
|
|
83
86
|
_cmd_detect_version(args)
|
|
87
|
+
elif args.command == "mcp":
|
|
88
|
+
_cmd_mcp()
|
|
84
89
|
except BrokenPipeError:
|
|
85
90
|
sys.exit(0)
|
|
86
91
|
|
|
@@ -200,3 +205,9 @@ def _cmd_list(args: argparse.Namespace) -> None:
|
|
|
200
205
|
def _cmd_detect_version(args: argparse.Namespace) -> None:
|
|
201
206
|
version = detect_version(project_dir=args.project_dir)
|
|
202
207
|
print(version)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _cmd_mcp() -> None:
|
|
211
|
+
from modern_python_guidance.mcp_server import serve
|
|
212
|
+
|
|
213
|
+
serve()
|