nbsync 0.1.3__tar.gz → 0.1.4__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.
Files changed (36) hide show
  1. {nbsync-0.1.3 → nbsync-0.1.4}/PKG-INFO +1 -1
  2. {nbsync-0.1.3 → nbsync-0.1.4}/docs/index.md +1 -1
  3. {nbsync-0.1.3 → nbsync-0.1.4}/pyproject.toml +1 -1
  4. {nbsync-0.1.3 → nbsync-0.1.4}/src/nbsync/sync.py +22 -8
  5. {nbsync-0.1.3 → nbsync-0.1.4}/tests/test_sync.py +12 -5
  6. {nbsync-0.1.3 → nbsync-0.1.4}/.devcontainer/devcontainer.json +0 -0
  7. {nbsync-0.1.3 → nbsync-0.1.4}/.devcontainer/postCreate.sh +0 -0
  8. {nbsync-0.1.3 → nbsync-0.1.4}/.devcontainer/starship.toml +0 -0
  9. {nbsync-0.1.3 → nbsync-0.1.4}/.gitattributes +0 -0
  10. {nbsync-0.1.3 → nbsync-0.1.4}/.github/workflows/ci.yaml +0 -0
  11. {nbsync-0.1.3 → nbsync-0.1.4}/.github/workflows/docs.yaml +0 -0
  12. {nbsync-0.1.3 → nbsync-0.1.4}/.github/workflows/publish.yaml +0 -0
  13. {nbsync-0.1.3 → nbsync-0.1.4}/.gitignore +0 -0
  14. {nbsync-0.1.3 → nbsync-0.1.4}/LICENSE +0 -0
  15. {nbsync-0.1.3 → nbsync-0.1.4}/README.md +0 -0
  16. {nbsync-0.1.3 → nbsync-0.1.4}/docs/getting-started/configuration.md +0 -0
  17. {nbsync-0.1.3 → nbsync-0.1.4}/docs/getting-started/first-steps.md +0 -0
  18. {nbsync-0.1.3 → nbsync-0.1.4}/docs/getting-started/installation.md +0 -0
  19. {nbsync-0.1.3 → nbsync-0.1.4}/mkdocs.yaml +0 -0
  20. {nbsync-0.1.3 → nbsync-0.1.4}/notebooks/analysis.ipynb +0 -0
  21. {nbsync-0.1.3 → nbsync-0.1.4}/scripts/__init__.py +0 -0
  22. {nbsync-0.1.3 → nbsync-0.1.4}/scripts/plot.py +0 -0
  23. {nbsync-0.1.3 → nbsync-0.1.4}/scripts/plotting.py +0 -0
  24. {nbsync-0.1.3 → nbsync-0.1.4}/src/nbsync/__init__.py +0 -0
  25. {nbsync-0.1.3 → nbsync-0.1.4}/src/nbsync/cell.py +0 -0
  26. {nbsync-0.1.3 → nbsync-0.1.4}/src/nbsync/logger.py +0 -0
  27. {nbsync-0.1.3 → nbsync-0.1.4}/src/nbsync/markdown.py +0 -0
  28. {nbsync-0.1.3 → nbsync-0.1.4}/src/nbsync/notebook.py +0 -0
  29. {nbsync-0.1.3 → nbsync-0.1.4}/src/nbsync/plugin.py +0 -0
  30. {nbsync-0.1.3 → nbsync-0.1.4}/src/nbsync/py.typed +0 -0
  31. {nbsync-0.1.3 → nbsync-0.1.4}/tests/__init__.py +0 -0
  32. {nbsync-0.1.3 → nbsync-0.1.4}/tests/conftest.py +0 -0
  33. {nbsync-0.1.3 → nbsync-0.1.4}/tests/test_cell.py +0 -0
  34. {nbsync-0.1.3 → nbsync-0.1.4}/tests/test_markdown.py +0 -0
  35. {nbsync-0.1.3 → nbsync-0.1.4}/tests/test_notebook.py +0 -0
  36. {nbsync-0.1.3 → nbsync-0.1.4}/tests/test_plugin.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nbsync
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: MkDocs plugin treating Jupyter notebooks, Python scripts and Markdown files as first-class citizens for documentation with dynamic execution and real-time synchronization
5
5
  Project-URL: Documentation, https://daizutabi.github.io/nbsync/
6
6
  Project-URL: Source, https://github.com/daizutabi/nbsync
@@ -118,7 +118,7 @@ traditional execution methods.
118
118
  ```python exec="1" source="tabbed-left"
119
119
  import numpy as np
120
120
  from PIL import Image
121
- x = np.random.randint(0, 255, (100, 100), dtype=np.uint8)
121
+ x = np.random.randint(0, 255, (50, 200), dtype=np.uint8)
122
122
  Image.fromarray(x)
123
123
  ```
124
124
  ````
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "nbsync"
7
- version = "0.1.3"
7
+ version = "0.1.4"
8
8
  description = "MkDocs plugin treating Jupyter notebooks, Python scripts and Markdown files as first-class citizens for documentation with dynamic execution and real-time synchronization"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -35,7 +35,7 @@ class Synchronizer:
35
35
  yield elem
36
36
 
37
37
  if isinstance(elem, Image | CodeBlock):
38
- update_notebooks(notebooks, elem, self.store)
38
+ update_notebooks(elem, notebooks, self.store)
39
39
 
40
40
  for url, notebook in notebooks.items():
41
41
  if url not in self.notebooks or not self.notebooks[url].equals(notebook):
@@ -58,17 +58,13 @@ class Synchronizer:
58
58
  if isinstance(elem, str):
59
59
  yield elem
60
60
 
61
- elif elem.identifier not in [".", "_"]:
62
- if isinstance(elem, Image):
63
- nb = self.notebooks[elem.url].nb
64
- yield convert_image(elem, nb)
65
- elif code_block := convert_code_block(elem):
66
- yield code_block
61
+ elif cell := convert(elem, self.notebooks):
62
+ yield cell
67
63
 
68
64
 
69
65
  def update_notebooks(
70
- notebooks: dict[str, Notebook],
71
66
  elem: Image | CodeBlock,
67
+ notebooks: dict[str, Notebook],
72
68
  store: Store,
73
69
  ) -> None:
74
70
  url = elem.url
@@ -93,6 +89,24 @@ def update_notebooks(
93
89
  notebook.add_cell(elem.identifier, source)
94
90
 
95
91
 
92
+ def convert(
93
+ elem: Image | CodeBlock,
94
+ notebooks: dict[str, Notebook],
95
+ ) -> str | Cell:
96
+ if elem.identifier not in [".", "_"]:
97
+ if isinstance(elem, Image):
98
+ if elem.url not in notebooks:
99
+ logger.warning(f"Notebook not found: {elem.url}")
100
+ return ""
101
+
102
+ nb = notebooks[elem.url].nb
103
+ return convert_image(elem, nb)
104
+
105
+ return convert_code_block(elem)
106
+
107
+ return ""
108
+
109
+
96
110
  def convert_image(image: Image, nb: NotebookNode) -> Cell:
97
111
  try:
98
112
  image.source = get_source(nb, image.identifier)
@@ -57,7 +57,7 @@ def test_update_notebooks(store: Store):
57
57
  from nbsync.sync import Notebook, update_notebooks
58
58
 
59
59
  notebooks: dict[str, Notebook] = {}
60
- update_notebooks(notebooks, Image("abc", "id", [], {}, "", "a.ipynb"), store)
60
+ update_notebooks(Image("abc", "id", [], {}, "", "a.ipynb"), notebooks, store)
61
61
  assert len(notebooks) == 1
62
62
  nb = notebooks["a.ipynb"].nb
63
63
  assert nbstore.notebook.get_source(nb, "id") == "print(1+1)"
@@ -68,7 +68,7 @@ def test_update_notebooks_exec(store: Store):
68
68
 
69
69
  notebooks: dict[str, Notebook] = {}
70
70
  image = Image("abc", "id", [], {"exec": "1"}, "", "a.ipynb")
71
- update_notebooks(notebooks, image, store)
71
+ update_notebooks(image, notebooks, store)
72
72
  assert len(notebooks) == 1
73
73
  assert notebooks["a.ipynb"].execution_needed
74
74
 
@@ -78,7 +78,7 @@ def test_update_notebooks_add_cell(store: Store):
78
78
 
79
79
  notebooks: dict[str, Notebook] = {}
80
80
  code_block = CodeBlock("abc", "id2", [], {}, "123", "a.ipynb")
81
- update_notebooks(notebooks, code_block, store)
81
+ update_notebooks(code_block, notebooks, store)
82
82
  assert len(notebooks) == 1
83
83
  notebook = notebooks["a.ipynb"]
84
84
  assert notebook.execution_needed
@@ -91,7 +91,7 @@ def test_update_notebooks_self(store: Store):
91
91
 
92
92
  notebooks: dict[str, Notebook] = {}
93
93
  code_block = CodeBlock("abc", "id2", [], {}, "123", ".md")
94
- update_notebooks(notebooks, code_block, store)
94
+ update_notebooks(code_block, notebooks, store)
95
95
  assert len(notebooks) == 1
96
96
  notebook = notebooks[".md"]
97
97
  assert len(notebook.nb.cells) == 1
@@ -102,7 +102,7 @@ def test_update_notebooks_error(store: Store):
102
102
 
103
103
  notebooks: dict[str, Notebook] = {}
104
104
  code_block = CodeBlock("abc", "id2", [], {}, "123", "invalid.md")
105
- update_notebooks(notebooks, code_block, store)
105
+ update_notebooks(code_block, notebooks, store)
106
106
  assert len(notebooks) == 0
107
107
 
108
108
 
@@ -160,3 +160,10 @@ def test_sync_code_block(sync: Synchronizer):
160
160
  x = next(sync.convert("```a b.md#c source=1\nc\n```"))
161
161
  assert isinstance(x, str)
162
162
  assert x == "```a \nc\n```"
163
+
164
+
165
+ def test_sync_notebook_not_found():
166
+ from nbsync.sync import convert
167
+
168
+ image = Image("abc", "id", [], {}, "", "a.ipynb")
169
+ assert convert(image, {}) == ""
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes