nbcat 0.9.0__py3-none-any.whl → 0.9.3__py3-none-any.whl
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.
- nbcat/__init__.py +1 -1
- nbcat/main.py +9 -7
- nbcat/schemas.py +2 -2
- {nbcat-0.9.0.dist-info → nbcat-0.9.3.dist-info}/METADATA +18 -39
- nbcat-0.9.3.dist-info/RECORD +11 -0
- nbcat-0.9.0.dist-info/RECORD +0 -11
- {nbcat-0.9.0.dist-info → nbcat-0.9.3.dist-info}/WHEEL +0 -0
- {nbcat-0.9.0.dist-info → nbcat-0.9.3.dist-info}/entry_points.txt +0 -0
- {nbcat-0.9.0.dist-info → nbcat-0.9.3.dist-info}/licenses/LICENSE +0 -0
nbcat/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.9.
|
1
|
+
__version__ = "0.9.3"
|
nbcat/main.py
CHANGED
@@ -26,7 +26,7 @@ from .schemas import Cell, Notebook
|
|
26
26
|
console = Console()
|
27
27
|
|
28
28
|
|
29
|
-
def read_notebook(fp: str) -> Notebook:
|
29
|
+
def read_notebook(fp: str, debug: bool = False) -> Notebook:
|
30
30
|
"""
|
31
31
|
Load and parse a Jupyter notebook from a local file or remote URL.
|
32
32
|
|
@@ -61,6 +61,8 @@ def read_notebook(fp: str) -> Notebook:
|
|
61
61
|
try:
|
62
62
|
return Notebook.model_validate_json(content)
|
63
63
|
except ValidationError as e:
|
64
|
+
if not debug:
|
65
|
+
raise InvalidNotebookFormatError("Failed to read notebook")
|
64
66
|
raise InvalidNotebookFormatError(f"Invalid notebook: {e}")
|
65
67
|
|
66
68
|
|
@@ -84,19 +86,16 @@ def render_cell(cell: Cell) -> list[tuple[str | None, RenderableType]]:
|
|
84
86
|
return Markdown(input)
|
85
87
|
|
86
88
|
def _render_code(input: str) -> Panel:
|
87
|
-
return Panel(Syntax(input, "python",
|
89
|
+
return Panel(Syntax(input, "python", theme="ansi_dark"), box=box.SQUARE)
|
88
90
|
|
89
91
|
def _render_raw(input: str) -> Text:
|
90
92
|
return Text(input)
|
91
93
|
|
92
|
-
def _render_heading(input: str) -> Text:
|
93
|
-
return Text(input)
|
94
|
-
|
95
94
|
RENDERERS = {
|
96
95
|
CellType.MARKDOWN: _render_markdown,
|
97
96
|
CellType.CODE: _render_code,
|
98
97
|
CellType.RAW: _render_raw,
|
99
|
-
CellType.HEADING:
|
98
|
+
CellType.HEADING: _render_markdown,
|
100
99
|
}
|
101
100
|
|
102
101
|
rows: list[tuple[str | None, RenderableType]] = []
|
@@ -159,11 +158,14 @@ def main():
|
|
159
158
|
action="version",
|
160
159
|
version=__version__,
|
161
160
|
)
|
161
|
+
parser.add_argument(
|
162
|
+
"--debug", help="enable extended error output", action="store_true", default=False
|
163
|
+
)
|
162
164
|
|
163
165
|
try:
|
164
166
|
argcomplete.autocomplete(parser)
|
165
167
|
args = parser.parse_args()
|
166
|
-
notebook = read_notebook(args.file)
|
168
|
+
notebook = read_notebook(args.file, debug=args.debug)
|
167
169
|
print_notebook(notebook)
|
168
170
|
except Exception as e:
|
169
171
|
sys.exit(f"nbcat: {e}")
|
nbcat/schemas.py
CHANGED
@@ -70,7 +70,7 @@ class Cell(BaseModel):
|
|
70
70
|
@property
|
71
71
|
def input(self) -> str:
|
72
72
|
if self.cell_type == CellType.HEADING and self.level is not None:
|
73
|
-
return f"{'#' * self.level} {self.source}"
|
73
|
+
return f"{'#' * self.level} {''.join(self.source)}"
|
74
74
|
|
75
75
|
if isinstance(self.source, list):
|
76
76
|
return "".join(self.source)
|
@@ -87,7 +87,7 @@ class Notebook(BaseModel):
|
|
87
87
|
def handle_format_versions(cls, data: dict[str, Any]) -> dict[str, Any]:
|
88
88
|
if data.get("worksheets"):
|
89
89
|
try:
|
90
|
-
data["cells"] = data.get("worksheets")[0].get("cells", [])
|
90
|
+
data["cells"] = data.get("worksheets", [{"cells": []}])[0].get("cells", [])
|
91
91
|
except (KeyError, IndexError, TypeError) as e:
|
92
92
|
print(e)
|
93
93
|
raise InvalidNotebookFormatError(f"Invalid v3 notebook structure: {e}")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nbcat
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.3
|
4
4
|
Summary: cat for jupyter notebooks
|
5
5
|
Project-URL: Homepage, https://github.com/akopdev/nbcat
|
6
6
|
Project-URL: Repository, https://github.com/akopdev/nbcat
|
@@ -43,48 +43,39 @@ Description-Content-Type: text/markdown
|
|
43
43
|
|
44
44
|
# 📦 nbcat
|
45
45
|
|
46
|
-
cat for
|
47
|
-
|
48
|
-
[](./LICENSE)
|
49
|
-
[](https://github.com/akopdev/nbcat/actions)
|
50
|
-
|
51
|
-
---
|
46
|
+
`nbcat` lets you preview Jupyter notebooks directly in your terminal. Think of it as `cat`, but for `.ipynb` files.
|
52
47
|
|
53
48
|
## 🚀 Features
|
54
49
|
|
55
|
-
-
|
56
|
-
-
|
57
|
-
-
|
58
|
-
- ⚡ Fast and lightweight
|
59
|
-
- 📦 Available on PyPI
|
60
|
-
|
61
|
-
---
|
50
|
+
- Fast and lightweight with minimal external dependencies
|
51
|
+
- Preview remote notebooks without downloading them
|
52
|
+
- Supports for all Jupyter notebook versions - including legacy formats
|
62
53
|
|
63
54
|
## 📦 Installation
|
64
55
|
|
65
|
-
|
56
|
+
From the command line using pip:
|
66
57
|
|
67
58
|
```bash
|
68
|
-
|
59
|
+
pip install nbcat
|
69
60
|
```
|
70
61
|
|
71
|
-
|
62
|
+
## 🛠️ Quickstart
|
72
63
|
|
73
64
|
```bash
|
74
|
-
|
65
|
+
$ nbcat notebook.ipynb
|
75
66
|
```
|
76
67
|
|
77
|
-
|
78
|
-
|
79
|
-
## 🛠️ Quickstart
|
68
|
+
You can pass URLs as well.
|
80
69
|
|
81
|
-
```
|
82
|
-
|
70
|
+
```bash
|
71
|
+
$ nbcat https://raw.githubusercontent.com/akopdev/nbcat/refs/heads/main/tests/assets/test4.ipynb
|
83
72
|
```
|
84
73
|
|
85
|
-
|
74
|
+
Example use case with `fzf` command that lists all `.ipynb` files and uses `nbcat` for previewing them:
|
86
75
|
|
87
|
-
|
76
|
+
```bash
|
77
|
+
find . -type f -name "*.ipynb" | fzf --preview 'nbcat {}'
|
78
|
+
```
|
88
79
|
|
89
80
|
## 🧪 Testing & Development
|
90
81
|
|
@@ -97,29 +88,17 @@ make test
|
|
97
88
|
Check code quality:
|
98
89
|
|
99
90
|
```bash
|
100
|
-
make lint
|
101
|
-
```
|
102
|
-
|
103
|
-
Format code:
|
104
|
-
|
105
|
-
```bash
|
106
|
-
make format
|
91
|
+
make format lint
|
107
92
|
```
|
108
93
|
|
109
|
-
---
|
110
|
-
|
111
94
|
## 🙌 Contributing
|
112
95
|
|
113
96
|
Contributions are welcome! Please open an issue or [pull request](https://github.com/akopdev/nbcat/pulls).
|
114
97
|
|
115
|
-
---
|
116
|
-
|
117
98
|
## 📄 License
|
118
99
|
|
119
100
|
Distributed under the MIT License. See [`LICENSE`](./LICENSE) for more information.
|
120
101
|
|
121
|
-
---
|
122
|
-
|
123
102
|
## 🔗 Useful Links
|
124
103
|
|
125
104
|
- 📘 Documentation: _coming soon_
|
@@ -128,4 +107,4 @@ Distributed under the MIT License. See [`LICENSE`](./LICENSE) for more informati
|
|
128
107
|
|
129
108
|
---
|
130
109
|
|
131
|
-
|
110
|
+
Made with ❤️ by [Akop Kesheshyan](https://github.com/akopdev)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
nbcat/__init__.py,sha256=xKd3pzbczuMsdB08eLAOqZDUd_q1IRxwZ_ccAFL4c4A,22
|
2
|
+
nbcat/enums.py,sha256=ZsuOwYLF0D4PVwSkS74LwoXY0y0DkeBToLBWnmiS97Y,300
|
3
|
+
nbcat/exceptions.py,sha256=Ho7LQz9K70VtIMDNtAwuAtGmb-lFKxGxSj7MN3-EpDA,321
|
4
|
+
nbcat/main.py,sha256=X1UbLxXF9Y9V4Z8vE_pUz5cG22zx2oBMMlvpJVWITD0,5236
|
5
|
+
nbcat/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
nbcat/schemas.py,sha256=IK1l2a4UcP6Ivh8xRBzV5BIQTbeES1b1cCH-6goEq8Q,2366
|
7
|
+
nbcat-0.9.3.dist-info/METADATA,sha256=IQV8OPxQ0sQFu1BdLK9g6z5-nSv4j36rUhaMJYv0FQ0,3376
|
8
|
+
nbcat-0.9.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
9
|
+
nbcat-0.9.3.dist-info/entry_points.txt,sha256=io_GRDsecAkYuCZALsjyea3VBq91VCoSznqlZEAJshY,42
|
10
|
+
nbcat-0.9.3.dist-info/licenses/LICENSE,sha256=7GjUnahXdd5opdvlpJdb1BisLbiXt2iOFhzIUduhdkE,1072
|
11
|
+
nbcat-0.9.3.dist-info/RECORD,,
|
nbcat-0.9.0.dist-info/RECORD
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
nbcat/__init__.py,sha256=H9NWRZb7NbeRRPLP_V1fARmLNXranorVM-OOY-8_2ug,22
|
2
|
-
nbcat/enums.py,sha256=ZsuOwYLF0D4PVwSkS74LwoXY0y0DkeBToLBWnmiS97Y,300
|
3
|
-
nbcat/exceptions.py,sha256=Ho7LQz9K70VtIMDNtAwuAtGmb-lFKxGxSj7MN3-EpDA,321
|
4
|
-
nbcat/main.py,sha256=YwFqpt_wZLwqFzlxr9Hon_9QbWYEpAaDzLDsi2t-U3s,5072
|
5
|
-
nbcat/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
nbcat/schemas.py,sha256=F5Wl0ZWa5j8RK4H98nDJm69h3oecEuP6wu62823Cxyg,2340
|
7
|
-
nbcat-0.9.0.dist-info/METADATA,sha256=CVTz2g79Sr9_moJraY6pkks5gXqTZMdvFMqszPBnqMY,3412
|
8
|
-
nbcat-0.9.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
9
|
-
nbcat-0.9.0.dist-info/entry_points.txt,sha256=io_GRDsecAkYuCZALsjyea3VBq91VCoSznqlZEAJshY,42
|
10
|
-
nbcat-0.9.0.dist-info/licenses/LICENSE,sha256=7GjUnahXdd5opdvlpJdb1BisLbiXt2iOFhzIUduhdkE,1072
|
11
|
-
nbcat-0.9.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|