Skip to content

Commit 9a35a57

Browse files
committed
update clinerules
1 parent e8ca233 commit 9a35a57

2 files changed

Lines changed: 336 additions & 13 deletions

File tree

.clinerules/hatch-tooling.md

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
# Hatch Tooling Requirements
2+
3+
## Primary Development Tool
4+
5+
**CRITICAL:** This project uses **Hatch** as its primary development and build tool. All development workflows, dependency management, testing, and build operations MUST use Hatch unless technically impossible.
6+
7+
## Why Hatch?
8+
9+
Hatch is the modern Python project manager that provides:
10+
- Unified environment management
11+
- Reproducible builds
12+
- Integrated testing workflows
13+
- Standardized project structure
14+
- PEP 517/518 compliance
15+
16+
## Hatch Command Reference
17+
18+
### Environment Management
19+
20+
**Install dependencies and set up environment:**
21+
```bash
22+
hatch env create
23+
```
24+
25+
**Activate the default environment:**
26+
```bash
27+
hatch shell
28+
```
29+
30+
**Run commands in the environment without activation:**
31+
```bash
32+
hatch run <command>
33+
```
34+
35+
**List all environments:**
36+
```bash
37+
hatch env show
38+
```
39+
40+
**Remove an environment:**
41+
```bash
42+
hatch env remove <env-name>
43+
```
44+
45+
### Dependency Management
46+
47+
**Add a new dependency:**
48+
```bash
49+
# Edit pyproject.toml [project.dependencies] section manually
50+
# Then sync the environment
51+
hatch env create
52+
```
53+
54+
**Add a development dependency:**
55+
```bash
56+
# Edit pyproject.toml [tool.hatch.envs.default] section manually
57+
# Then sync the environment
58+
hatch env create
59+
```
60+
61+
**Update dependencies:**
62+
```bash
63+
hatch env prune
64+
hatch env create
65+
```
66+
67+
### Testing
68+
69+
**Run tests:**
70+
```bash
71+
hatch run test
72+
```
73+
74+
**Run tests with coverage:**
75+
```bash
76+
hatch run cov
77+
```
78+
79+
**Run tests for specific Python versions:**
80+
```bash
81+
hatch run test:test
82+
```
83+
84+
**Run a specific test file:**
85+
```bash
86+
hatch run pytest tests/test_plugin_textroom.py
87+
```
88+
89+
**Run a specific test:**
90+
```bash
91+
hatch run pytest tests/test_plugin_textroom.py::TestTransportHttp::test_textroom_message_history
92+
```
93+
94+
### Code Quality
95+
96+
**Run linting:**
97+
```bash
98+
hatch run lint:check
99+
```
100+
101+
**Auto-fix linting issues:**
102+
```bash
103+
hatch run lint:fix
104+
```
105+
106+
**Run type checking:**
107+
```bash
108+
hatch run lint:typing
109+
```
110+
111+
**Format code:**
112+
```bash
113+
hatch run lint:fmt
114+
```
115+
116+
### Documentation
117+
118+
**Build documentation:**
119+
```bash
120+
hatch run docs:build
121+
```
122+
123+
**Serve documentation locally:**
124+
```bash
125+
hatch run docs:serve
126+
```
127+
128+
**Build documentation with strict mode:**
129+
```bash
130+
hatch run python -W ignore::DeprecationWarning:mkdocs_autorefs -m mkdocs build --clean --strict
131+
```
132+
133+
### Building and Publishing
134+
135+
**Build the package:**
136+
```bash
137+
hatch build
138+
```
139+
140+
**Build wheel only:**
141+
```bash
142+
hatch build -t wheel
143+
```
144+
145+
**Build source distribution only:**
146+
```bash
147+
hatch build -t sdist
148+
```
149+
150+
**Publish to PyPI:**
151+
```bash
152+
hatch publish
153+
```
154+
155+
**Publish to Test PyPI:**
156+
```bash
157+
hatch publish -r test
158+
```
159+
160+
### Version Management
161+
162+
**Show current version:**
163+
```bash
164+
hatch version
165+
```
166+
167+
**Bump version (patch):**
168+
```bash
169+
hatch version patch
170+
```
171+
172+
**Bump version (minor):**
173+
```bash
174+
hatch version minor
175+
```
176+
177+
**Bump version (major):**
178+
```bash
179+
hatch version major
180+
```
181+
182+
**Set specific version:**
183+
```bash
184+
hatch version 1.2.3
185+
```
186+
187+
## Development Workflow with Hatch
188+
189+
### Initial Setup
190+
```bash
191+
# Clone the repository
192+
git clone <repository-url>
193+
cd python_janus_client
194+
195+
# Create and activate environment
196+
hatch env create
197+
hatch shell
198+
199+
# Verify installation
200+
hatch run python -c "import janus_client; print(janus_client.__version__)"
201+
```
202+
203+
### Daily Development
204+
```bash
205+
# Activate environment
206+
hatch shell
207+
208+
# Run tests during development
209+
hatch run pytest tests/
210+
211+
# Check code quality
212+
hatch run lint:check
213+
214+
# Format code
215+
hatch run lint:fmt
216+
```
217+
218+
### Before Committing
219+
```bash
220+
# Run full test suite
221+
hatch run test
222+
223+
# Check coverage
224+
hatch run cov
225+
226+
# Run linting
227+
hatch run lint:check
228+
229+
# Run type checking
230+
hatch run lint:typing
231+
232+
# Build documentation
233+
hatch run docs:build
234+
```
235+
236+
### Adding New Dependencies
237+
```bash
238+
# 1. Edit pyproject.toml to add dependency
239+
# 2. Recreate environment
240+
hatch env prune
241+
hatch env create
242+
243+
# 3. Verify dependency is installed
244+
hatch run python -c "import <new_package>"
245+
```
246+
247+
## When NOT to Use Hatch
248+
249+
Hatch should be used for all development tasks. However, in rare cases where Hatch cannot be used:
250+
251+
1. **CI/CD Constraints:** If the CI/CD platform doesn't support Hatch, use pip with requirements files generated from pyproject.toml
252+
2. **Legacy System Compatibility:** If deploying to systems that cannot run Hatch
253+
3. **Docker Builds:** In minimal Docker images, pip installation from wheel may be preferred
254+
255+
In these cases, document the reason and provide alternative commands.
256+
257+
## Migration from Poetry
258+
259+
This project previously used Poetry. If you encounter Poetry commands in documentation or scripts:
260+
261+
| Poetry Command | Hatch Equivalent |
262+
|----------------|------------------|
263+
| `poetry install` | `hatch env create` |
264+
| `poetry shell` | `hatch shell` |
265+
| `poetry add <package>` | Edit pyproject.toml + `hatch env create` |
266+
| `poetry run <command>` | `hatch run <command>` |
267+
| `poetry build` | `hatch build` |
268+
| `poetry publish` | `hatch publish` |
269+
| `poetry version` | `hatch version` |
270+
| `poetry run pytest` | `hatch run pytest` |
271+
| `poetry run flake8` | `hatch run lint:check` |
272+
273+
## Environment Configuration
274+
275+
Hatch environments are configured in `pyproject.toml` under `[tool.hatch.envs]`. The project uses:
276+
277+
- **default:** Main development environment with all dependencies
278+
- **test:** Testing environment with pytest and coverage
279+
- **lint:** Linting environment with flake8, black, isort, mypy
280+
- **docs:** Documentation environment with mkdocs
281+
282+
## Best Practices
283+
284+
1. **Always use Hatch commands:** Don't use pip directly in the project directory
285+
2. **Keep pyproject.toml updated:** All dependencies must be declared in pyproject.toml
286+
3. **Use environment-specific commands:** Use `hatch run <env>:<script>` for specific environments
287+
4. **Regenerate environments after changes:** Run `hatch env prune && hatch env create` after modifying dependencies
288+
5. **Document Hatch usage:** When adding new scripts or workflows, document the Hatch commands
289+
290+
## Troubleshooting
291+
292+
### Environment Issues
293+
```bash
294+
# Remove all environments and start fresh
295+
hatch env prune
296+
hatch env create
297+
```
298+
299+
### Dependency Conflicts
300+
```bash
301+
# Check environment details
302+
hatch env show
303+
304+
# Recreate specific environment
305+
hatch env remove <env-name>
306+
hatch env create <env-name>
307+
```
308+
309+
### Command Not Found
310+
```bash
311+
# Ensure you're in the project directory
312+
cd /path/to/python_janus_client
313+
314+
# Verify Hatch is installed
315+
hatch --version
316+
317+
# If not installed, install Hatch
318+
pip install hatch
319+
```
320+
321+
## Summary
322+
323+
**Remember:** Use Hatch for ALL development tasks. This ensures consistency, reproducibility, and adherence to modern Python packaging standards. Only deviate from Hatch when technically impossible, and document the reason clearly.

.clinerules/python-best-practices.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This is a Python async client library for the Janus WebRTC gateway. The project
99
- Admin/Monitor API support
1010
- Media streaming capabilities with PyAV
1111

12-
**Key Technologies:** Python 3.8-3.11, asyncio, aiortc, websockets, aiohttp, Poetry
12+
**Key Technologies:** Python 3.8-3.11, asyncio, aiortc, websockets, aiohttp, Hatch
1313

1414
## Python Development Standards
1515

@@ -91,9 +91,9 @@ janus_client/
9191
- **Conditional Imports:** Use try/except for optional dependencies
9292

9393
### Dependency Management
94-
- **Poetry:** Use `poetry add` for new dependencies
94+
- **Hatch:** Edit pyproject.toml and run `hatch env create` for new dependencies
9595
- **Version Constraints:** Use compatible version ranges (^1.0.0)
96-
- **Dev Dependencies:** Separate development dependencies
96+
- **Dev Dependencies:** Separate development dependencies in tool.hatch.envs sections
9797
- **Optional Dependencies:** Use extras for optional features
9898

9999
## Testing Standards
@@ -175,11 +175,11 @@ async def join_room(self, room_id: int, username: str, pin: Optional[str] = None
175175

176176
## Development Workflow
177177

178-
### Poetry Usage
179-
- **Install:** `poetry install` for development setup
180-
- **Dependencies:** `poetry add <package>` for new dependencies
181-
- **Virtual Environment:** `poetry shell` to activate environment
182-
- **Scripts:** Define common tasks in `pyproject.toml`
178+
### Hatch Usage
179+
- **Install:** `hatch env create` for development setup
180+
- **Dependencies:** Edit pyproject.toml and run `hatch env create` for new dependencies
181+
- **Virtual Environment:** `hatch shell` to activate environment
182+
- **Scripts:** Define common tasks in `pyproject.toml` under `[tool.hatch.envs]`
183183

184184
### Git Practices
185185
- **Commits:** Use conventional commit messages
@@ -188,14 +188,14 @@ async def join_room(self, room_id: int, username: str, pin: Optional[str] = None
188188
- **Versioning:** Follow semantic versioning (MAJOR.MINOR.PATCH)
189189

190190
### Code Quality
191-
- **Linting:** Run `flake8` before committing
192-
- **Testing:** Run full test suite with `pytest`
193-
- **Coverage:** Check coverage with `coverage run -m pytest`
194-
- **Type Checking:** Use `mypy` for static type checking
191+
- **Linting:** Run `hatch run lint:check` before committing
192+
- **Testing:** Run full test suite with `hatch run test`
193+
- **Coverage:** Check coverage with `hatch run cov`
194+
- **Type Checking:** Run `hatch run lint:typing` for static type checking
195195

196196
### Documentation Building
197197
- **MkDocs Strict Mode:** Always use `--strict` flag when building documentation to catch warnings as errors
198-
- **Build Command:** Use `poetry run python -W ignore::DeprecationWarning:mkdocs_autorefs -m mkdocs build --clean --strict`
198+
- **Build Command:** Use `hatch run python -W ignore::DeprecationWarning:mkdocs_autorefs -m mkdocs build --clean --strict`
199199
- **Warning Suppression:** The command above suppresses known deprecation warnings from mkdocs-autorefs plugin
200200
- **Local Testing:** Test documentation builds locally before committing changes
201201
- **CI/CD:** The GitHub workflow automatically uses strict mode to ensure clean documentation builds

0 commit comments

Comments
 (0)