lysqlnb 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lysqlnb-0.2.0 → lysqlnb-0.3.0}/PKG-INFO +4 -4
- {lysqlnb-0.2.0 → lysqlnb-0.3.0}/README.md +3 -3
- {lysqlnb-0.2.0 → lysqlnb-0.3.0}/pyproject.toml +1 -1
- lysqlnb-0.3.0/src/lysqlnb/__init__.py +57 -0
- lysqlnb-0.3.0/src/lysqlnb/loader.py +35 -0
- {lysqlnb-0.2.0 → lysqlnb-0.3.0}/src/lysqlnb/models.py +2 -35
- lysqlnb-0.2.0/src/lysqlnb/__init__.py +0 -17
- {lysqlnb-0.2.0 → lysqlnb-0.3.0}/LICENCE +0 -0
- {lysqlnb-0.2.0 → lysqlnb-0.3.0}/src/lysqlnb/exceptions.py +0 -0
- {lysqlnb-0.2.0 → lysqlnb-0.3.0}/src/lysqlnb/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lysqlnb
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: A library for reading and validating SQL notebook files.
|
|
5
5
|
Keywords: notebook,sql
|
|
6
6
|
Author: Leyton Addison-Roach
|
|
@@ -41,9 +41,9 @@ The data models are based on the VS Code [NotebookSerializer API](https://code.v
|
|
|
41
41
|
|
|
42
42
|
```python
|
|
43
43
|
>>> from pathlib import Path
|
|
44
|
-
>>>
|
|
45
|
-
>>>
|
|
46
|
-
>>>
|
|
44
|
+
>>> import lysqlnb as sqlnb
|
|
45
|
+
>>> nb = sqlnb.load(Path("path/to/notebook.sqlnb"))
|
|
46
|
+
>>> nb.model_dump_json(indent=2)
|
|
47
47
|
{
|
|
48
48
|
"cells": [
|
|
49
49
|
{
|
|
@@ -19,9 +19,9 @@ The data models are based on the VS Code [NotebookSerializer API](https://code.v
|
|
|
19
19
|
|
|
20
20
|
```python
|
|
21
21
|
>>> from pathlib import Path
|
|
22
|
-
>>>
|
|
23
|
-
>>>
|
|
24
|
-
>>>
|
|
22
|
+
>>> import lysqlnb as sqlnb
|
|
23
|
+
>>> nb = sqlnb.load(Path("path/to/notebook.sqlnb"))
|
|
24
|
+
>>> nb.model_dump_json(indent=2)
|
|
25
25
|
{
|
|
26
26
|
"cells": [
|
|
27
27
|
{
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""lysqlnb — a library for reading and validating SQL notebook files."""
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from lysqlnb.exceptions import NotebookParseError
|
|
6
|
+
from lysqlnb.loader import loads as _loads
|
|
7
|
+
from lysqlnb.models import (
|
|
8
|
+
Notebook,
|
|
9
|
+
NotebookCell,
|
|
10
|
+
NotebookCellKind,
|
|
11
|
+
NotebookCellLanguage,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"Notebook",
|
|
19
|
+
"NotebookCell",
|
|
20
|
+
"NotebookCellKind",
|
|
21
|
+
"NotebookCellLanguage",
|
|
22
|
+
"NotebookParseError",
|
|
23
|
+
"load",
|
|
24
|
+
"loads",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def loads(s: str) -> Notebook:
|
|
29
|
+
"""Load a notebook from a string.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
s: String to load the notebook from.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Notebook data object.
|
|
36
|
+
|
|
37
|
+
Raises:
|
|
38
|
+
NotebookParseError: If the string contains invalid YAML or
|
|
39
|
+
does not conform to the notebook schema.
|
|
40
|
+
"""
|
|
41
|
+
return _loads(s)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def load(path: Path) -> Notebook:
|
|
45
|
+
"""Load a notebook from a file path.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
path: Path to the notebook file.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Notebook data object.
|
|
52
|
+
|
|
53
|
+
Raises:
|
|
54
|
+
NotebookParseError: If the file contains invalid YAML or
|
|
55
|
+
does not conform to the notebook schema.
|
|
56
|
+
"""
|
|
57
|
+
return loads(path.read_text(encoding="utf-8"))
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""YAML parsing and validation for notebook files."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import yaml
|
|
6
|
+
from pydantic import ValidationError
|
|
7
|
+
|
|
8
|
+
from lysqlnb.exceptions import NotebookParseError
|
|
9
|
+
from lysqlnb.models import Notebook
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def loads(s: str) -> Notebook:
|
|
13
|
+
"""Load a raw YAML string into a notebook.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
s: YAML string to load.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
Notebook data object.
|
|
20
|
+
|
|
21
|
+
Raises:
|
|
22
|
+
NotebookParseError: If the string contains invalid YAML or
|
|
23
|
+
does not conform to the notebook schema.
|
|
24
|
+
"""
|
|
25
|
+
try:
|
|
26
|
+
raw: Any = yaml.safe_load(s)
|
|
27
|
+
except yaml.YAMLError as e:
|
|
28
|
+
msg = f"Invalid YAML: {e}"
|
|
29
|
+
raise NotebookParseError(msg) from e
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
return Notebook.model_validate(raw)
|
|
33
|
+
except ValidationError as e:
|
|
34
|
+
msg = f"Invalid notebook structure: {e}"
|
|
35
|
+
raise NotebookParseError(msg) from e
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
"""Notebook data models
|
|
1
|
+
"""Notebook data models."""
|
|
2
2
|
|
|
3
3
|
from enum import IntEnum, StrEnum
|
|
4
|
-
from typing import TYPE_CHECKING, Any
|
|
5
4
|
|
|
6
|
-
import
|
|
7
|
-
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
|
8
|
-
|
|
9
|
-
from lysqlnb.exceptions import NotebookParseError
|
|
10
|
-
|
|
11
|
-
if TYPE_CHECKING:
|
|
12
|
-
from pathlib import Path
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
13
6
|
|
|
14
7
|
|
|
15
8
|
class NotebookCellKind(IntEnum):
|
|
@@ -68,29 +61,3 @@ class Notebook(BaseModel):
|
|
|
68
61
|
model_config = ConfigDict(extra="forbid")
|
|
69
62
|
|
|
70
63
|
cells: list[NotebookCell]
|
|
71
|
-
|
|
72
|
-
@classmethod
|
|
73
|
-
def from_file(cls, path: Path) -> Notebook:
|
|
74
|
-
"""Create a notebook from a file.
|
|
75
|
-
|
|
76
|
-
Args:
|
|
77
|
-
path: Path to the notebook file.
|
|
78
|
-
|
|
79
|
-
Returns:
|
|
80
|
-
Validated notebook data object.
|
|
81
|
-
|
|
82
|
-
Raises:
|
|
83
|
-
NotebookParseError: If the file contains invalid YAML or
|
|
84
|
-
does not conform to the notebook schema.
|
|
85
|
-
"""
|
|
86
|
-
try:
|
|
87
|
-
raw: Any = yaml.safe_load(path.read_text(encoding="utf-8"))
|
|
88
|
-
except yaml.YAMLError as e:
|
|
89
|
-
msg = f"Invalid YAML: {e}"
|
|
90
|
-
raise NotebookParseError(msg) from e
|
|
91
|
-
|
|
92
|
-
try:
|
|
93
|
-
return cls.model_validate(raw)
|
|
94
|
-
except ValidationError as e:
|
|
95
|
-
msg = f"Invalid notebook structure: {e}"
|
|
96
|
-
raise NotebookParseError(msg) from e
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"""lysqlnb — a library for reading and validating SQL notebook files."""
|
|
2
|
-
|
|
3
|
-
from lysqlnb.exceptions import NotebookParseError
|
|
4
|
-
from lysqlnb.models import (
|
|
5
|
-
Notebook,
|
|
6
|
-
NotebookCell,
|
|
7
|
-
NotebookCellKind,
|
|
8
|
-
NotebookCellLanguage,
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
__all__ = [
|
|
12
|
-
"Notebook",
|
|
13
|
-
"NotebookCell",
|
|
14
|
-
"NotebookCellKind",
|
|
15
|
-
"NotebookCellLanguage",
|
|
16
|
-
"NotebookParseError",
|
|
17
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|