Skip to content

Commit 8b2941b

Browse files
committed
Open source Deepnote Toolkit
1 parent 9cf9bfc commit 8b2941b

File tree

201 files changed

+40800
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+40800
-0
lines changed

.codecov.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: auto
6+
threshold: 0.05%
7+
patch:
8+
default:
9+
target: auto
10+
threshold: 0.05%

.cursorrules

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

.flake8

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[flake8]
2+
max-line-length = 100
3+
# This tells flake8 to only select error codes that start with E (PEP8 errors) and F (PyFlakes errors). It excludes warnings (W) and complexity checks (C).
4+
select = E,F
5+
extend-ignore = E203, E266, E501, W503
6+
exclude = .git,__pycache__,.nox,docs/source/conf.py,old,build,dist,configs/ipython/profile_default/ipython_config.py,.venv,.poetry
7+
per-file-ignores =
8+
# imported but unused
9+
__init__.py: F401
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: 'Build Python Wheel'
2+
description: 'Build a Python wheel package using Poetry with dynamic versioning'
3+
4+
outputs:
5+
wheel-name:
6+
description: 'Name of the built wheel file'
7+
value: ${{ steps.build.outputs.wheel-name }}
8+
version:
9+
description: 'Package version'
10+
value: ${{ steps.build.outputs.version }}
11+
wheel-path:
12+
description: 'Full path to the wheel file'
13+
value: ${{ steps.build.outputs.wheel-path }}
14+
15+
runs:
16+
using: 'composite'
17+
steps:
18+
- name: Build wheel and extract metadata
19+
id: build
20+
shell: bash
21+
run: |
22+
set -euo pipefail
23+
24+
# Ensure dynamic versioning plugin is installed
25+
poetry self add 'poetry-dynamic-versioning[plugin]>=1.4.0' 2>/dev/null || true
26+
27+
# Remove any pre-existing artifacts to avoid publishing stale wheels
28+
rm -rf dist
29+
mkdir -p dist
30+
31+
# Build the wheel
32+
echo "Building wheel with Poetry..."
33+
poetry build --format wheel
34+
35+
# Get version and wheel info
36+
VERSION=$(poetry version --short)
37+
WHEEL_COUNT=$(find dist -maxdepth 1 -name '*.whl' | wc -l | tr -d ' ')
38+
if [ "$WHEEL_COUNT" -ne 1 ]; then
39+
echo "ERROR: Expected exactly 1 wheel, found ${WHEEL_COUNT}"
40+
ls -la dist/
41+
exit 1
42+
fi
43+
WHEEL=$(find dist -maxdepth 1 -name '*.whl' -print -quit)
44+
WHEEL_NAME=$(basename "$WHEEL")
45+
WHEEL_PATH=$(realpath "$WHEEL")
46+
47+
# Output to GitHub Actions
48+
{
49+
echo "wheel-name=${WHEEL_NAME}"
50+
echo "version=${VERSION}"
51+
echo "wheel-path=${WHEEL_PATH}"
52+
} >> "$GITHUB_OUTPUT"
53+
54+
# Display results
55+
echo "✓ Built wheel: $WHEEL_NAME"
56+
echo "✓ Version: $VERSION"
57+
echo "✓ Path: $WHEEL_PATH"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Export Version'
2+
description: 'Exports VERSION environment variable based on git ref'
3+
outputs:
4+
version:
5+
description: 'The version string'
6+
value: ${{ steps.export-version.outputs.version }}
7+
runs:
8+
using: 'composite'
9+
steps:
10+
- name: Create VERSION env variable
11+
id: export-version
12+
shell: bash
13+
run: |
14+
if [[ -n "$GITHUB_REF_NAME" && "$GITHUB_REF_TYPE" == "tag" ]]; then
15+
VERSION=$GITHUB_REF_NAME
16+
else
17+
VERSION="$(git rev-parse --short HEAD)"
18+
fi
19+
echo "VERSION=$VERSION" >> $GITHUB_ENV
20+
echo "version=$VERSION" >> $GITHUB_OUTPUT
21+
echo "Version is set to: $VERSION"

0 commit comments

Comments
 (0)