Manual-commit notebook snapshot extension (JupyterLab 4):
Backend
- Storage adapter layer (Local + S3 via boto3, pip extra)
- Dumb put/get/list/delete contract; key validation
- S3Storage: lazy boto3 import, S3ConnectionError with friendly
messages + connectivity check at startup
- SnapshotStore
- Strip code outputs/execution_count, MD5 on cleaned JSON
- Gzipped envelope (id/timestamp/name/description/hash/size/notebook)
- Append-only manifest.json (rebuildable from version files)
- SnapshotUnchangedError when new hash matches most recent version
- REST API (commit / list / content) under /snapshot/ namespace
- traitlets config (storage_type, local_root, s3_* + S3_* env fallback)
Frontend
- snapshot:commit command (toolbar button + command palette)
- Dialog for name + description
- SnapshotPanel (left sidebar timeline) + DiffWidget (main area)
- Cell diff: id-match first, LCS fallback; jsdiff for line diff
- Restore via model.fromJSON() + context.save() (no refresh)
- All AGENTS.md hard conventions enforced
Tests: 33 backend pytest passing (storage + store + routes)
Docs: AGENTS.md, design.md, README.md synced with implementation.
Co-Authored-By: Claude <noreply@anthropic.com>
73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
"""Traitlets-based configuration for the snapshot server extension."""
|
|
|
|
import os
|
|
|
|
from traitlets.config.configurable import Configurable
|
|
from traitlets.traitlets import Bool, Unicode, default
|
|
|
|
|
|
class SnapshotConfig(Configurable):
|
|
"""Configuration options for the notebook snapshot extension."""
|
|
|
|
storage_type = Unicode(
|
|
"local",
|
|
config=True,
|
|
help='Storage backend type. Either "local" or "s3" (covers AWS S3, MinIO, etc.).',
|
|
)
|
|
local_root = Unicode(
|
|
"",
|
|
config=True,
|
|
help="Directory for local snapshot storage. Empty means <server root_dir>/.notebook_versions.",
|
|
)
|
|
|
|
s3_endpoint = Unicode(
|
|
"",
|
|
config=True,
|
|
help="S3 endpoint host (without scheme), e.g. localhost:9000 for MinIO or s3.us-east-1.amazonaws.com for AWS S3.",
|
|
)
|
|
|
|
@default("s3_endpoint")
|
|
def _default_s3_endpoint(self):
|
|
"""Default to the ``S3_ENDPOINT`` environment variable."""
|
|
return os.environ.get("S3_ENDPOINT", "")
|
|
|
|
s3_access_key = Unicode(
|
|
"",
|
|
config=True,
|
|
help="S3 access key ID.",
|
|
)
|
|
|
|
@default("s3_access_key")
|
|
def _default_s3_access_key(self):
|
|
"""Default to the ``S3_ACCESS_KEY`` environment variable."""
|
|
return os.environ.get("S3_ACCESS_KEY", "")
|
|
|
|
s3_secret_key = Unicode(
|
|
"",
|
|
config=True,
|
|
help="S3 secret access key.",
|
|
)
|
|
|
|
@default("s3_secret_key")
|
|
def _default_s3_secret_key(self):
|
|
"""Default to the ``S3_SECRET_KEY`` environment variable."""
|
|
return os.environ.get("S3_SECRET_KEY", "")
|
|
|
|
s3_bucket = Unicode(
|
|
"notebook-snapshot",
|
|
config=True,
|
|
help="S3 bucket name. Created automatically if it does not exist.",
|
|
)
|
|
|
|
s3_secure = Bool(
|
|
False,
|
|
config=True,
|
|
help="Use HTTPS for the S3 connection.",
|
|
)
|
|
|
|
s3_prefix = Unicode(
|
|
"",
|
|
config=True,
|
|
help="Optional prefix prepended to all object keys in the S3 bucket.",
|
|
)
|