Skip to content

Commit 50000c7

Browse files
committed
Add Cursor Rules
1 parent a0adf1e commit 50000c7

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed

.cursor/rules/conda_env.mdc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
description: sparse_attention_hub conda
3+
alwaysApply: true
4+
---
5+
Every project is associated with a conda environment. before starting to run any commands, run the following
6+
```
7+
bash
8+
```
9+
followed by
10+
```
11+
conda activate sparse_attention_hub
12+
```

.cursor/rules/defensive-coding.mdc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
description: when to do defensive and when not to do defensive coding
3+
globs: *.py
4+
alwaysApply: true
5+
---
6+
7+
Follow these instructions when writing any python code
8+
9+
1. Keep code minimal by focusing only on the logic needed for the task.
10+
2. Trust internal invariants in self-contained projects—don't check for impossible conditions.
11+
3. Avoid unnecessary type checks or error handling when inputs are fully controlled.
12+
4. Use assertions during development to catch unexpected states, but remove or reduce them in production if they're redundant.
13+
5. Apply defensive coding only when dealing with:
14+
a. External inputs (user data, files, APIs)
15+
b. Unreliable dependencies
16+
c. Long-lived or reused code (e.g. libraries, shared modules)
17+
6. Prioritize readability and maintainability over protecting against unrealistic edge cases.
18+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
description: docstring format to use in python
3+
globs: *.py
4+
alwaysApply: true
5+
---
6+
7+
While writing python code, always ensure to add correct formatted docstrings to classes and methods.
8+
9+
An example format of a good docstring is below
10+
11+
12+
"""Example Google style docstrings.
13+
14+
This module demonstrates documentation as specified by the `Google Python
15+
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
16+
with a section header and a colon followed by a block of indented text.
17+
18+
Example:
19+
Examples can be given using either the ``Example`` or ``Examples``
20+
sections. Sections support any reStructuredText formatting, including
21+
literal blocks::
22+
23+
$ python example_google.py
24+
25+
Section breaks are created by resuming unindented text. Section breaks
26+
are also implicitly created anytime a new section starts.
27+
28+
Attributes:
29+
module_level_variable1 (int): Module level variables may be documented in
30+
either the ``Attributes`` section of the module docstring, or in an
31+
inline docstring immediately following the variable.
32+
33+
Either form is acceptable, but the two should not be mixed. Choose
34+
one convention to document module level variables and be consistent
35+
with it.
36+
37+
Todo:
38+
* For module TODOs
39+
"""

.cursor/rules/linting.mdc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
description: Linters when success is confirmed
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
When the conversation is about to end and task is a success, ask if linters should be run. If yes
8+
run the following linters and fix the linting issues
9+
10+
```bash
11+
black --check --line-length=88 sparse_attention_hub tests scripts
12+
```
13+
14+
```bash
15+
isort \
16+
--profile=black \
17+
--line-length=88 \
18+
--multi-line=3 \
19+
-p sparse_attention_hub \
20+
sparse_attention_hub tests scripts
21+
```
22+
23+
```bash
24+
flake8 \
25+
--max-line-length=88 \
26+
--extend-ignore=E203,W503,E501 \
27+
--exclude=build,dist,.git,__pycache__,.pytest_cache,.venv \
28+
sparse_attention_hub tests scripts
29+
```
30+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
description: Strong type annotations
3+
globs: *py
4+
alwaysApply: true
5+
---
6+
7+
While writing python code, always use strong type annotations in the following places
8+
1. method signatures
9+
2. while declaring new variables in code

.cursor/rules/tests.mdc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
description: tests
3+
globs:
4+
alwaysApply: true
5+
---
6+
7+
when writing tests, remember to
8+
1. use the sparse-attention-hub/tests directory and appropriate file structure mimicing the code file structure from sparse-attention-hub/sparse_attention_hub/
9+
2. You are free to add new tests
10+
3. If modifying the tests, always ask before making changes.

.cursor/rules/type-annotations.mdc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
alwaysApply: true
3+
---
4+
while writing python code,
5+
6+
Always use Type annotations for the generating code including but not limited to
7+
1. Method parameters and return types
8+
2. Class members
9+
3. actual code of the form b = f (a), use b: Type = f(a)

0 commit comments

Comments
 (0)