-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path.cursorrules
More file actions
177 lines (125 loc) · 4.03 KB
/
.cursorrules
File metadata and controls
177 lines (125 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Deepnote Toolkit - .cursorrules
## Role and Expertise
You are an expert Python developer working on the Deepnote Toolkit, a Python package for Deepnote environment integration. Your code should be clean, efficient, and follow the project's established patterns for Jupyter/IPython integration.
## Coding Standards
### General Principles
- Write clean, readable Python code
- Follow PEP 8 style guide
- Use type hints where appropriate
- Document functions and classes with docstrings
- Use f-strings instead of .format() for string formatting
- Use pathlib.Path for file path operations instead of os.path
### Type Hints
- Always use `Optional[T]` for parameters that can be None (not `T = None`)
- Use explicit type hints for function parameters and return values
- Example: `def function(param: Optional[str] = None) -> str:`
### Project-Specific Standards
- Maximum line length: 88 characters (Black default)
- Use black for code formatting
- Use isort for import sorting (black profile)
- Use flake8 for linting
### Code Patterns
- Early returns to reduce nesting: Check conditions and return early
- Extract common checks into variables for readability
- Use dictionary unpacking for headers: `headers = {"Content-Type": "application/json", **auth_headers}`
- CLI arguments: Use space-separated format (`--port 8080`)
### Naming Conventions
- **Variables and Functions**: snake_case
- **Classes**: PascalCase
- **Files**: snake_case
- **Test Files**: test\_\*.py
### Error Handling
- Use appropriate exception types
- Log errors with context
- Handle Jupyter/IPython specific exceptions properly
## Project Structure
Organize the project with clear separation:
- **deepnote_toolkit /**: Core package code
- **tests/**: Unit and integration tests
- **configs/**: Configuration files
- **dockerfiles/**: Docker environment definitions
- **bin/**: Shell scripts and utilities
## Dependencies Management
### Poetry Groups
- **Core Dependencies**: `tool.poetry.dependencies`
```bash
poetry add <package>
```
- **Server Dependencies**: `tool.poetry.group.server.dependencies`
```bash
poetry add --group server <package>
```
- **Development Dependencies**: `tool.poetry.group.dev.dependencies`
```bash
poetry add --group dev <package>
```
## Testing Standards
### Environment Variables
Required for all tests:
- TEST_TYPE
- TOOLKIT_VERSION
Additional for integration tests:
- TOOLKIT_INDEX_URL
### Commands
```bash
# Run local tests
./bin/test-local
# Run a specific test file
./bin/test-local tests/unit/test_file.py
# ... or specific test from file
./bin/test-local tests/unit/test_file.py::TestClass::test_method
# Run specific test type
export TEST_TYPE="unit|integration"
export TOOLKIT_VERSION="local-build"
./bin/test
```
## Docker Environments
Available Dockerfiles:
- builder.Dockerfile: Creates bundles
- test.Dockerfile: Testing environment
- jupyter-for-local.Dockerfile: Local development
## Security Requirements
### Public Repository Rules
- No secrets or sensitive information in codebase
- No internal URLs or credentials
- No customer data
### Pre-commit Hooks
Setup: `poetry poe setup-hooks`
Required hooks:
- trailing-whitespace
- end-of-file-fixer
- check-yaml
- check-added-large-files
- flake8
- isort
## Python Version Support
Supported versions:
- Python 3.9
- Python 3.10
- Python 3.11
- Python 3.12
- Python 3.13
## Code Examples
### Example Activity Pattern
```python
def configure_dataframe_formatter(spec):
"""Configure the DataFrame formatter with given specifications.
Args:
spec: Formatting specifications for DataFrame display
"""
global df_formatter_spec
df_formatter_spec = spec
```
### Example Test Pattern
```python
class TestDataFrameUtils(unittest.TestCase):
def setUp(self):
self.df = pd.DataFrame({
"col1": [1, 2, 3],
"col2": [4, 5, 6]
})
def test_browse_dataframe(self):
"""Test DataFrame browsing functionality."""
result = browse_dataframe(self.df, {"view": "table"})
self.assertIsInstance(result, pd.DataFrame)
```