Skip to content

Commit fd8df36

Browse files
committed
Add cursor rules
1 parent cf7469d commit fd8df36

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

.cursor/logging.mdc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
description: Logging should be actionable, structured, and follow professional practices
3+
alwaysApply: true
4+
---
5+
6+
- Never log and raise at the same time. Let logs occur where the exception is handled.
7+
- Use `.bind()` to attach contextual fields like `job_id`, `trainer`, `dataset`, etc.
8+
- Propagate the bound logger across modules instead of re-creating it.
9+
- Use semantic log levels:
10+
- `debug`: Diagnostic/internal details, not printed in prod
11+
- `info`: Expected events (training started, dataset loaded, etc.)
12+
- `warning`: Unexpected but handled (e.g. missing columns)
13+
- `error`: Real failures that may abort a process
14+
- Avoid logs like `"Starting function"` — instead log **what happened**, with context.
15+
- Avoid excessive logging in loops. Log summary or batch progress only.
16+
- Enable JSON structured logs only in production environments.
17+
- Keep logs relevant to external observability, not internal dev experimentation.
18+
19+
**Checklist for evaluating a log:**
20+
- Does it convey a real event, not just function entry?
21+
- Is it at the correct level (not everything is warning)?
22+
- Is the logger properly bound with job/task context?
23+
- Can this log help diagnose or monitor the system?
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
description: Enforce modular design with clear responsibility boundaries
3+
alwaysApply: true
4+
---
5+
6+
- Follow **Single Responsibility Principle (SRP)**: one reason to change per module/class/function.
7+
- Avoid **over-engineering**: modularize only when it improves clarity, reuse or testability.
8+
- Group related logic in packages: `data/`, `services/`, `utils/`, `models/`, etc.
9+
- Keep modules cohesive but not overly fragmented.
10+
- Don't split code into separate files unless they evolve independently or have distinct lifecycles.
11+
12+
**Checklist for evaluating modularity:**
13+
- Can the module be reused independently?
14+
- Does it hide internal details behind a clean interface?
15+
- Would adding more features bloat its logic?
16+
17+
Example:
18+
✅ `email_service.py` sends emails
19+
🚫 `email_sender.py`, `email_templates.py`, `email_config.py` if too small and tightly coupled
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
description: Enforce structured and absolute import order for Python files
3+
globs:
4+
- "**/*.py"
5+
alwaysApply: true
6+
---
7+
8+
Group, order, and format Python imports following these conventions:
9+
10+
### ✅ Use **absolute imports only**:
11+
Always write imports using the full path from the project root.
12+
**Avoid** relative imports like `from .module import foo` or `from ..utils import bar`.
13+
14+
- ✅ `from my_project.utils import foo`
15+
- ❌ `from .utils import foo`
16+
- ❌ `from ..submodule import bar`
17+
18+
This ensures clarity, consistency across refactors, and better compatibility with tools like linters, IDEs, and packaging systems.
19+
20+
---
21+
22+
### 📚 Import grouping and ordering:
23+
24+
Organize imports into **three groups**, separated by a blank line:
25+
26+
1. **Standard Library Imports**
27+
e.g., `import os`, `from datetime import datetime`
28+
29+
2. **Third-Party Library Imports**
30+
e.g., `import numpy as np`, `from sqlalchemy import Column`
31+
32+
3. **Local Application/Library Imports**
33+
e.g., `from my_project.utils import helper_function`
34+
35+
---
36+
37+
### 🔤 Within each group:
38+
39+
- First: `import module` (in alphabetical order)
40+
- Then: `from module import name` (in alphabetical order)
41+
42+
---
43+
44+
### ✅ Example:
45+
46+
```python
47+
import os
48+
import sys
49+
from datetime import datetime
50+
51+
import numpy as np
52+
import pandas as pd
53+
from sqlalchemy import Column, Integer
54+
55+
import my_project
56+
from my_project.utils import helper_function

.cursor/type-hinting.mdc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
description: Enforce strict type annotations using Python 3.12+ standards
3+
globs:
4+
- "**/*.py"
5+
alwaysApply: true
6+
---
7+
8+
- Always annotate:
9+
- Function parameters and return types, even for `None`, `bool`, `str`, etc.
10+
- Variable declarations (including attributes and loop vars) when static typing helps comprehension.
11+
- Lambda expressions when assigned or passed as arguments.
12+
- **Avoid** `Any`, `Optional`, `Union`, `List`, `Dict`, etc. unless justified.
13+
- **Prefer** Python 3.12+ standard generics:
14+
- Use `list[str]`, `dict[str, int]`, `tuple[str, int]`
15+
- Avoid `List`, `Dict`, `Tuple` from `typing`
16+
- Use `|` (pipe) syntax for unions:
17+
- Use `str | None`
18+
- Avoid `Optional[str]`
19+
- Use `Self` and `classmethod`/`staticmethod` hints as per [PEP 673](https://peps.python.org/pep-0673/)
20+
21+
**Examples:**
22+
23+
```python
24+
def greet(name: str | None = None) -> str:
25+
return f"Hello, {name or 'World'}"
26+
27+
def parse(data: str) -> dict[str, int]:
28+
...

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ This project uses [structlog](https://www.structlog.org/en/stable/) for structur
116116

117117
Structured logs make it easier to parse, search, and analyze logs in production systems, especially when using centralized logging tools like Loki, ELK, or Datadog.
118118

119+
## IDE
120+
121+
This project has some [cursor|https://cursor.com/] rules under `.cursor` that help us write some code, but you are not forced to use it as this is optional.
122+
123+
119124
### Examples
120125

121126
1. Pass context information as key word arguments

0 commit comments

Comments
 (0)