Skip to main content

A Jupyter/nbdev notebook decomposition core for context graphs: a notebook IS a CodeModule whose authored source is an ordered sequence of VERBATIM cells (the lossless source substrate), composing the python decomposer (code cells -> symbols) and the markdown decomposer (markdown cells -> prose) with interleaving edges. The first step toward graph-as-source-of-truth (notebook -> graph).

Project description

cjm-notebook-decompose-core

A Jupyter/nbdev notebook decomposition core for context graphs: a notebook IS a CodeModule whose authored source is an ordered sequence of VERBATIM cells (the lossless source substrate), composing the python decomposer (code cells -> symbols) and the markdown decomposer (markdown cells -> prose) with interleaving edges. The first step toward graph-as-source-of-truth (notebook -> graph).

Modules

  • cjm_notebook_decompose_core.__init__
  • cjm_notebook_decompose_core.compose — Compose a parsed notebook onto dev-graph-schema nodes (the compositor).
  • cjm_notebook_decompose_core.ingest — Flatten decomposed notebooks into graph elements (the queue-free half).
  • cjm_notebook_decompose_core.project — Project a notebook BACK out of the graph (graph -> .ipynb) — the round-trip leg.
  • cjm_notebook_decompose_core.read — Schema-free Jupyter/nbdev notebook parsing (stdlib json).
  • tests.test_compose — Compositor: read + compose a notebook onto CodeModule/Cell/CodeSymbol nodes + edges.
  • tests.test_project — Round-trip: regenerate a notebook from its verbatim cells (graph/cells -> .ipynb).
  • tests.test_reattribution — Cross-cell method re-attribution (@patch + incremental Class.method = fn idioms).
  • tests_manual.real_notebook — Dogfood the compositor on a REAL ecosystem nbdev notebook (against a scratch graph).

API

cjm_notebook_decompose_core.compose

  • DecomposedNotebook class — A notebook bound to schema nodes: the module + verbatim cells + code symbols + edges.
  • decompose_notebook function — Bind a parsed notebook onto a notebook CodeModule + verbatim cells + symbols + edges.
  • decompose_notebook_file function — Read + decompose a notebook file (module path from default_exp/package, else the path).
  • module_path_for_notebook function — Pick the notebook module path: the export target when known, else the .ipynb path.

cjm_notebook_decompose_core.ingest

  • notebook_graph_elements function — Collect decomposed notebooks into the node + edge wire-dict lists for extend_graph.

cjm_notebook_decompose_core.project

  • cells_for_module function — Filter queried Cell nodes down to one notebook module (by module_id property).
  • notebook_dict_from_cells function — Rebuild the .ipynb JSON from verbatim cells (ordered by index).
  • render_notebook function — Serialize regenerated cells to .ipynb JSON text.

cjm_notebook_decompose_core.read

  • ParsedCell class — One notebook cell, parsed but not yet schema-bound.
  • ParsedNotebook class — The structural decomposition of one notebook.
  • parse_directives function — Extract nbdev #| directive bodies (the text after #|) from a cell.
  • parse_notebook function — Parse a notebook's JSON into ordered cells + the #| default_exp target.
  • parse_notebook_file function — Read + parse a notebook file (UTF-8).

tests.test_compose

  • test_every_cell_is_verbatim_with_contains_and_next function
  • test_export_cells_yield_symbols_under_the_module function
  • test_ingest_flattens_and_is_idempotent function
  • test_interleaving_markdown_documents_following_code function
  • test_markdown_cell_prose_and_references function
  • test_module_path_for_notebook function
  • test_non_export_code_cells_harvest_call_names function — A non-export code cell (nbdev's test/example vehicle) gets its bare call names
  • test_non_python_export_cell_keeps_verbatim_cell function
  • test_notebook_is_a_codemodule function
  • test_read_cells_directives_and_default_exp function
  • test_within_notebook_calls_resolve function

tests.test_project

  • test_cells_for_module_filters_by_module function
  • test_outputs_are_not_restored_but_source_is_exact function
  • test_render_from_cellnodes_round_trips_source function
  • test_render_from_graph_wire_dicts function

tests.test_reattribution

  • test_class_defines_the_reattributed_methods function
  • test_patch_and_assign_methods_reattributed_to_class function
  • test_reattributed_method_keeps_cell_key function
  • test_reattribution_preserves_verbatim_round_trip function
  • test_unrecognized_method_shaped_is_surfaced_not_reattributed function

tests_manual.real_notebook

  • main function

Dependencies

Depends on: cjm-context-graph-projection, cjm-dev-graph-schema, cjm-markdown-decompose-core, cjm-python-decompose-core Used by: cjm-context-graph-projection

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cjm_notebook_decompose_core-0.0.4.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cjm_notebook_decompose_core-0.0.4-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file cjm_notebook_decompose_core-0.0.4.tar.gz.

File metadata

File hashes

Hashes for cjm_notebook_decompose_core-0.0.4.tar.gz
Algorithm Hash digest
SHA256 478c3067e081edcc957374eaf0430731d81bcb7ee9eb45d365fc4d5e248231ec
MD5 64cf5af7d37c9113eebe13d9a93caf72
BLAKE2b-256 667e9c0fb2087745591e041077c9723e9c03990b35752bb3b583f9c174ae78d8

See more details on using hashes here.

File details

Details for the file cjm_notebook_decompose_core-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for cjm_notebook_decompose_core-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 23473481af5c757b1d6101558b283506c6491de437e4334ab277eafb335c8ee9
MD5 1a6a38b44b3adeed038b12bf611d0cb6
BLAKE2b-256 895290176880a73fbe8664af61237bbe6019391bc6183afe381d30e67e2f4cce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page