bigyahu 0.1.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.
bigyahu-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: bigyahu
3
+ Version: 0.1.0
4
+ Summary: Retrieve code snippets stored as ipynb notebooks via by.list() and by.get()
5
+ Author: bigyahu
6
+ Requires-Python: >=3.8
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "bigyahu"
7
+ version = "0.1.0"
8
+ description = "Retrieve code snippets stored as ipynb notebooks via by.list() and by.get()"
9
+ requires-python = ">=3.8"
10
+ authors = [{ name = "bigyahu" }]
11
+ dependencies = []
12
+
13
+ [project.scripts]
14
+ bigyahu = "bigyahu.__main__:main"
15
+
16
+ [tool.setuptools.packages.find]
17
+ where = ["src"]
18
+
19
+ [tool.setuptools.package-data]
20
+ bigyahu = ["codes/*.ipynb"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,83 @@
1
+ """bigyahu - retrieve stored code snippets from ipynb notebooks.
2
+
3
+ Usage::
4
+
5
+ import bigyahu as by
6
+ by.list() # list available code snippet names
7
+ by.get("name") # print the code of snippet "name" as-is
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import json
13
+ from pathlib import Path
14
+ from typing import List
15
+
16
+ # Capture the builtin list type before we shadow the name with our list() function.
17
+ _builtin_list = list
18
+
19
+ __version__ = "0.1.0"
20
+
21
+ # Directory (relative to this package) that holds the stored .ipynb snippets.
22
+ _CODES_DIR = Path(__file__).parent / "codes"
23
+
24
+
25
+ def _notebook_path(name: str) -> Path:
26
+ """Resolve a snippet name to its .ipynb file path."""
27
+ # Accept names with or without the .ipynb extension.
28
+ if name.endswith(".ipynb"):
29
+ return _CODES_DIR / name
30
+ return _CODES_DIR / f"{name}.ipynb"
31
+
32
+
33
+ def list() -> List[str]:
34
+ """Return the list of available code snippet names.
35
+
36
+ Each name corresponds to a ``.ipynb`` file inside the bundled
37
+ ``bigyahu/codes`` directory (extension stripped).
38
+ """
39
+ if not _CODES_DIR.is_dir():
40
+ return []
41
+ names = sorted(p.stem for p in _CODES_DIR.glob("*.ipynb"))
42
+ return names
43
+
44
+
45
+ def _load_cells(name: str):
46
+ """Load and return the code cells of a notebook as a list of source strings."""
47
+ path = _notebook_path(name)
48
+ if not path.exists():
49
+ available = ", ".join(list()) or "(none)"
50
+ raise FileNotFoundError(
51
+ f"Notebook '{name}' not found. Available snippets: {available}"
52
+ )
53
+
54
+ with path.open("r", encoding="utf-8") as fh:
55
+ nb = json.load(fh)
56
+
57
+ cells = nb.get("cells", [])
58
+ code_cells = []
59
+ for cell in cells:
60
+ if cell.get("cell_type") != "code":
61
+ continue
62
+ source = cell.get("source", [])
63
+ if isinstance(source, _builtin_list):
64
+ code_cells.append("".join(source))
65
+ else:
66
+ code_cells.append(str(source))
67
+ return code_cells
68
+
69
+
70
+ def get(name: str) -> str:
71
+ """Print the code of snippet ``name`` as it appears in the ipynb and return it.
72
+
73
+ Only code cells are included (markdown/raw cells are skipped). The code is
74
+ printed exactly as stored, cell by cell.
75
+ """
76
+ code_cells = _load_cells(name)
77
+ code = "\n\n# --- cell ---\n\n".join(code_cells)
78
+ print(code)
79
+ return code
80
+
81
+
82
+ # Expose convenience aliases so both ``by.list()`` and ``by.get()`` work.
83
+ __all__ = ["list", "get"]
@@ -0,0 +1,33 @@
1
+ """Command-line entry point for the bigyahu package."""
2
+
3
+ import sys
4
+ import bigyahu
5
+
6
+
7
+ def main(argv=None) -> int:
8
+ argv = list(sys.argv[1:]) if argv is None else list(argv)
9
+
10
+ if not argv:
11
+ print("Usage: bigyahu list | get <name>")
12
+ return 1
13
+
14
+ command = argv[0].lower()
15
+ if command == "list":
16
+ for name in bigyahu.list():
17
+ print(name)
18
+ return 0
19
+
20
+ if command == "get":
21
+ if len(argv) < 2:
22
+ print("Usage: bigyahu get <name>")
23
+ return 1
24
+ bigyahu.get(argv[1])
25
+ return 0
26
+
27
+ print(f"Unknown command: {command}")
28
+ print("Usage: bigyahu list | get <name>")
29
+ return 1
30
+
31
+
32
+ if __name__ == "__main__":
33
+ raise SystemExit(main())
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,50 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "example-hello",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "print(\"Hello from bigyahu!\")\n",
11
+ "x = 42\n",
12
+ "print(x)\n"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "markdown",
17
+ "id": "example-md",
18
+ "metadata": {},
19
+ "source": [
20
+ "This markdown cell should be skipped by get().\n"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "id": "example-second",
27
+ "metadata": {},
28
+ "outputs": [],
29
+ "source": [
30
+ "def add(a, b):\n",
31
+ " return a + b\n",
32
+ "\n",
33
+ "print(add(2, 3))\n"
34
+ ]
35
+ }
36
+ ],
37
+ "metadata": {
38
+ "kernelspec": {
39
+ "display_name": "Python 3",
40
+ "language": "python",
41
+ "name": "python3"
42
+ },
43
+ "language_info": {
44
+ "name": "python",
45
+ "version": "3.14.6"
46
+ }
47
+ },
48
+ "nbformat": 4,
49
+ "nbformat_minor": 5
50
+ }
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: bigyahu
3
+ Version: 0.1.0
4
+ Summary: Retrieve code snippets stored as ipynb notebooks via by.list() and by.get()
5
+ Author: bigyahu
6
+ Requires-Python: >=3.8
@@ -0,0 +1,10 @@
1
+ pyproject.toml
2
+ src/bigyahu/__init__.py
3
+ src/bigyahu/__main__.py
4
+ src/bigyahu/_version.py
5
+ src/bigyahu.egg-info/PKG-INFO
6
+ src/bigyahu.egg-info/SOURCES.txt
7
+ src/bigyahu.egg-info/dependency_links.txt
8
+ src/bigyahu.egg-info/entry_points.txt
9
+ src/bigyahu.egg-info/top_level.txt
10
+ src/bigyahu/codes/example.ipynb
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ bigyahu = bigyahu.__main__:main
@@ -0,0 +1 @@
1
+ bigyahu