nbsync 0.1.4__py3-none-any.whl → 0.2.0__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.
nbsync/cell.py CHANGED
@@ -5,10 +5,9 @@ import uuid
5
5
  from dataclasses import dataclass
6
6
  from typing import TYPE_CHECKING
7
7
 
8
+ from nbsync import logger
8
9
  from nbsync.markdown import is_truelike
9
10
 
10
- from .logger import logger
11
-
12
11
  if TYPE_CHECKING:
13
12
  from nbstore.markdown import Image
14
13
 
nbsync/logger.py CHANGED
@@ -1,5 +1,32 @@
1
1
  from __future__ import annotations
2
2
 
3
- from mkdocs.plugins import get_plugin_logger
3
+ import logging
4
+ from logging import Logger
5
+ from typing import Any
4
6
 
5
- logger = get_plugin_logger("nbsync")
7
+ _logger = logging.getLogger("nbsync")
8
+
9
+
10
+ def configure(logger: Logger | None = None) -> Logger:
11
+ global _logger # noqa: PLW0603
12
+
13
+ if logger:
14
+ _logger = logger
15
+
16
+ return _logger
17
+
18
+
19
+ def debug(msg: str, *args: Any, **kwargs: Any) -> None:
20
+ _logger.debug(msg, *args, **kwargs)
21
+
22
+
23
+ def info(msg: str, *args: Any, **kwargs: Any) -> None:
24
+ _logger.info(msg, *args, **kwargs)
25
+
26
+
27
+ def warning(msg: str, *args: Any, **kwargs: Any) -> None:
28
+ _logger.warning(msg, *args, **kwargs)
29
+
30
+
31
+ def error(msg: str, *args: Any, **kwargs: Any) -> None:
32
+ _logger.error(msg, *args, **kwargs)
nbsync/sync.py CHANGED
@@ -10,12 +10,11 @@ from nbstore.markdown import CodeBlock, Image
10
10
  from nbstore.notebook import get_language, get_mime_content, get_source
11
11
 
12
12
  import nbsync.markdown
13
+ from nbsync import logger
13
14
  from nbsync.cell import Cell
14
15
  from nbsync.markdown import is_truelike
15
16
  from nbsync.notebook import Notebook
16
17
 
17
- from .logger import logger
18
-
19
18
  if TYPE_CHECKING:
20
19
  from collections.abc import Iterator
21
20
 
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nbsync
3
- Version: 0.1.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
3
+ Version: 0.2.0
4
+ Summary: A core library to synchronize Jupyter notebooks and Markdown documents, enabling seamless integration and dynamic content execution
5
5
  Project-URL: Documentation, https://daizutabi.github.io/nbsync/
6
6
  Project-URL: Source, https://github.com/daizutabi/nbsync
7
7
  Project-URL: Issues, https://github.com/daizutabi/nbsync/issues
@@ -28,7 +28,7 @@ License: MIT License
28
28
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
29
  SOFTWARE.
30
30
  License-File: LICENSE
31
- Keywords: documentation,dynamic-execution,jupyter,markdown,mkdocs,notebook,python,real-time-sync,visualization
31
+ Keywords: documentation,dynamic-execution,jupyter,markdown,notebook,python,real-time-sync,visualization
32
32
  Classifier: Development Status :: 4 - Beta
33
33
  Classifier: Programming Language :: Python
34
34
  Classifier: Programming Language :: Python :: 3.10
@@ -39,8 +39,7 @@ Classifier: Topic :: Documentation
39
39
  Classifier: Topic :: Software Development :: Documentation
40
40
  Classifier: Topic :: Text Processing :: Markup :: Markdown
41
41
  Requires-Python: >=3.10
42
- Requires-Dist: mkdocs>=1.6
43
- Requires-Dist: nbstore>=0.4.7
42
+ Requires-Dist: nbstore>=0.4.11
44
43
  Description-Content-Type: text/markdown
45
44
 
46
45
  # nbsync
@@ -50,11 +49,9 @@ Description-Content-Type: text/markdown
50
49
  [![Build Status][GHAction-image]][GHAction-link]
51
50
  [![Coverage Status][codecov-image]][codecov-link]
52
51
 
53
- <strong>Connect Jupyter notebooks to your MkDocs documentation</strong>
52
+ <strong>Connect Jupyter notebooks and Markdown documents</strong>
54
53
 
55
- nbsync is a MkDocs plugin that seamlessly embeds Jupyter notebook
56
- visualizations in your documentation, solving the disconnect between
57
- code development and documentation.
54
+ nbsync is a core library that seamlessly bridges Jupyter notebooks and Markdown documents, enabling dynamic content synchronization and execution.
58
55
 
59
56
  ## Why Use nbsync?
60
57
 
@@ -68,7 +65,7 @@ Data scientists, researchers, and technical writers face a common dilemma:
68
65
 
69
66
  ### Our Solution
70
67
 
71
- This plugin creates a live bridge between your notebooks and documentation by:
68
+ nbsync creates a live bridge between your notebooks and markdown documents by:
72
69
 
73
70
  - **Keeping environments separate** - work in the tool best suited for each task
74
71
  - **Maintaining connections** - reference specific figures from notebooks
@@ -86,7 +83,7 @@ This plugin creates a live bridge between your notebooks and documentation by:
86
83
 
87
84
  - **Automatic Updates**:
88
85
  When you modify your notebooks, your documentation updates
89
- automatically in MkDocs serve mode.
86
+ automatically.
90
87
 
91
88
  - **Clean Source Documents**:
92
89
  Your markdown remains readable and focused on content, without
@@ -104,14 +101,27 @@ This plugin creates a live bridge between your notebooks and documentation by:
104
101
  pip install nbsync
105
102
  ```
106
103
 
107
- ### 2. Configuration
104
+ ### 2. Basic Usage
108
105
 
109
- Add to your `mkdocs.yml`:
106
+ ```python
107
+ from nbsync.sync import Synchronizer
108
+ from nbstore import Store
109
+
110
+ # Initialize with a notebook store
111
+ store = Store("path/to/notebooks")
112
+ sync = Synchronizer(store)
113
+
114
+ # Process markdown with notebook references
115
+ markdown_text = """
116
+ # My Document
117
+
118
+ ![Chart description](my-notebook.ipynb){#my-figure}
119
+ """
110
120
 
111
- ```yaml
112
- plugins:
113
- - nbsync:
114
- src_dir: ../notebooks
121
+ # Convert markdown with notebook references to final output
122
+ for element in sync.convert(markdown_text):
123
+ # Process each element (string or Cell objects)
124
+ print(element)
115
125
  ```
116
126
 
117
127
  ### 3. Mark Figures in Your Notebook
@@ -140,14 +150,14 @@ Creating documentation and developing visualizations involve different
140
150
  workflows and timeframes. When building visualizations in Jupyter notebooks,
141
151
  you need rapid cycles of execution, verification, and modification.
142
152
 
143
- This plugin is designed specifically to address these separation of
153
+ nbsync is designed specifically to address these separation of
144
154
  concerns, allowing you to:
145
155
 
146
156
  - **Focus on code** in notebooks without documentation distractions
147
157
  - **Focus on narrative** in markdown without code interruptions
148
158
  - **Maintain powerful connections** between both environments
149
159
 
150
- Each environment is optimized for its purpose, while the plugin
160
+ Each environment is optimized for its purpose, while nbsync
151
161
  handles the integration automatically.
152
162
 
153
163
  ## Contributing
@@ -0,0 +1,11 @@
1
+ nbsync/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ nbsync/cell.py,sha256=C7VqQO3mxZ7Nj4ufywTnaqZAegT7zqA6iN2WV6X5X5c,3786
3
+ nbsync/logger.py,sha256=XzkJVBD1SATP5Nhh9tuUL_tS4Mc5MDeVtp8yYiRePxs,688
4
+ nbsync/markdown.py,sha256=xcPhQKWpFDyVQ_xtZCpFrnR0QED_hYs4PAyaT7dF3t4,3830
5
+ nbsync/notebook.py,sha256=Voh-e8RQsoYmWKnaHzAn4bm6Ud5v-aHwmng2Uc0rUts,1009
6
+ nbsync/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ nbsync/sync.py,sha256=3gLLAACjKGiFCODCgxw5lqr0m3_Naxjv-oWizP3J4QY,3833
8
+ nbsync-0.2.0.dist-info/METADATA,sha256=ofKBu3lFz1Nz6PW-2SKB0lrLWHARjfVprdCAqfM6BR4,6552
9
+ nbsync-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ nbsync-0.2.0.dist-info/licenses/LICENSE,sha256=wy1pqn52upuo_qYwY-epWmspwE-3UWJso0xodciGXYc,1062
11
+ nbsync-0.2.0.dist-info/RECORD,,
nbsync/plugin.py DELETED
@@ -1,96 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pathlib import Path
4
- from typing import TYPE_CHECKING, ClassVar
5
-
6
- from mkdocs.config import Config as BaseConfig
7
- from mkdocs.config import config_options
8
- from mkdocs.plugins import BasePlugin
9
- from mkdocs.structure.files import File
10
- from nbstore.store import Store
11
-
12
- from .logger import logger
13
- from .sync import Synchronizer
14
-
15
- if TYPE_CHECKING:
16
- from typing import Any
17
-
18
- from mkdocs.config.defaults import MkDocsConfig
19
- from mkdocs.structure.files import Files
20
- from mkdocs.structure.pages import Page
21
-
22
- from .cell import Cell
23
-
24
-
25
- class Config(BaseConfig):
26
- """Configuration for Nbstore plugin."""
27
-
28
- src_dir = config_options.Type((str, list), default=".")
29
-
30
-
31
- class Plugin(BasePlugin[Config]):
32
- store: ClassVar[Store | None] = None
33
- syncs: ClassVar[dict[str, Synchronizer]] = {}
34
- files: Files
35
-
36
- def on_config(self, config: MkDocsConfig, **kwargs: Any) -> MkDocsConfig:
37
- if isinstance(self.config.src_dir, str):
38
- src_dirs = [self.config.src_dir]
39
- else:
40
- src_dirs = self.config.src_dir
41
-
42
- src_dirs = [(Path(config.docs_dir) / s).resolve() for s in src_dirs]
43
-
44
- store = self.__class__.store
45
-
46
- if store is None or store.src_dirs != src_dirs:
47
- self.__class__.store = Store(src_dirs)
48
- config.watch.extend(x.as_posix() for x in src_dirs)
49
-
50
- for name in ["attr_list", "md_in_html"]:
51
- if name not in config.markdown_extensions:
52
- config.markdown_extensions.append(name)
53
-
54
- return config
55
-
56
- def on_files(self, files: Files, config: MkDocsConfig, **kwargs: Any) -> Files:
57
- self.files = files
58
- return files
59
-
60
- def on_page_markdown(
61
- self,
62
- markdown: str,
63
- page: Page,
64
- config: MkDocsConfig,
65
- **kwargs: Any,
66
- ) -> str:
67
- if self.__class__.store is None:
68
- msg = "Store must be initialized before processing markdown"
69
- logger.error(msg)
70
- return markdown
71
-
72
- src_uri = page.file.src_uri
73
- syncs = self.__class__.syncs
74
-
75
- if src_uri not in syncs:
76
- syncs[src_uri] = Synchronizer(self.__class__.store)
77
-
78
- markdowns = []
79
-
80
- for elem in syncs[src_uri].convert(markdown):
81
- if isinstance(elem, str):
82
- markdowns.append(elem)
83
-
84
- elif markdown := elem.convert():
85
- markdowns.append(markdown)
86
-
87
- if elem.image.url and elem.content:
88
- file = generate_file(elem, src_uri, config)
89
- self.files.append(file)
90
-
91
- return "".join(markdowns)
92
-
93
-
94
- def generate_file(cell: Cell, page_uri: str, config: MkDocsConfig) -> File:
95
- src_uri = (Path(page_uri).parent / cell.image.url).as_posix()
96
- return File.generated(config, src_uri, content=cell.content)
@@ -1,13 +0,0 @@
1
- nbsync/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- nbsync/cell.py,sha256=HNgMDwA1KrMxyoxAL2wUrg3zdA1glveoXY5YbO_uFeM,3788
3
- nbsync/logger.py,sha256=tQK8Z8HdWQNhVohQYLwZtJhdaj2w0UTyhHQak3mPqNc,119
4
- nbsync/markdown.py,sha256=xcPhQKWpFDyVQ_xtZCpFrnR0QED_hYs4PAyaT7dF3t4,3830
5
- nbsync/notebook.py,sha256=Voh-e8RQsoYmWKnaHzAn4bm6Ud5v-aHwmng2Uc0rUts,1009
6
- nbsync/plugin.py,sha256=YywBAD7fcrPg3-_9T_kSuvD8RBzsc_ovlIviGlKR9po,2835
7
- nbsync/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- nbsync/sync.py,sha256=M21moADW2dgvQB46ahbcd2aXOHHqwx9CwfjNO7GR2mQ,3835
9
- nbsync-0.1.4.dist-info/METADATA,sha256=EzIqH3hnebqKZ0N1pFzGuE0zL-LNzyVYUyDKBNaRmRQ,6287
10
- nbsync-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
- nbsync-0.1.4.dist-info/entry_points.txt,sha256=bSqmJTDmrUoSm4yDjk8YDWxI71SShx16judadGdiKbA,47
12
- nbsync-0.1.4.dist-info/licenses/LICENSE,sha256=wy1pqn52upuo_qYwY-epWmspwE-3UWJso0xodciGXYc,1062
13
- nbsync-0.1.4.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [mkdocs.plugins]
2
- nbsync = nbsync.plugin:Plugin
File without changes