pythoncharmers-meta 0.7.3__tar.gz → 0.7.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.
- {pythoncharmers_meta-0.7.3 → pythoncharmers_meta-0.7.4}/PKG-INFO +1 -1
- {pythoncharmers_meta-0.7.3 → pythoncharmers_meta-0.7.4}/pyproject.toml +1 -1
- pythoncharmers_meta-0.7.4/src/pythoncharmers_meta/.claude/settings.local.json +20 -0
- pythoncharmers_meta-0.7.4/src/pythoncharmers_meta/MD_MAGIC.md +182 -0
- {pythoncharmers_meta-0.7.3 → pythoncharmers_meta-0.7.4}/src/pythoncharmers_meta/__init__.py +14 -12
- pythoncharmers_meta-0.7.4/src/pythoncharmers_meta/nb_magic.py +723 -0
- pythoncharmers_meta-0.7.4/src/pythoncharmers_meta/source.ipynb +632 -0
- pythoncharmers_meta-0.7.4/src/pythoncharmers_meta/source2.ipynb +1048 -0
- {pythoncharmers_meta-0.7.3 → pythoncharmers_meta-0.7.4}/uv.lock +1 -1
- pythoncharmers_meta-0.7.3/src/pythoncharmers_meta/nb_magic.py +0 -293
- {pythoncharmers_meta-0.7.3 → pythoncharmers_meta-0.7.4}/.gitignore +0 -0
- {pythoncharmers_meta-0.7.3 → pythoncharmers_meta-0.7.4}/LICENSE +0 -0
- {pythoncharmers_meta-0.7.3 → pythoncharmers_meta-0.7.4}/README.md +0 -0
- {pythoncharmers_meta-0.7.3 → pythoncharmers_meta-0.7.4}/src/pythoncharmers_meta/ai_magic.py +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(python3:*)",
|
|
5
|
+
"Bash(cd:*)",
|
|
6
|
+
"Bash(cd:*)",
|
|
7
|
+
"Bash(rm:*)",
|
|
8
|
+
"Bash(git add:*)",
|
|
9
|
+
"Bash(cd:*)",
|
|
10
|
+
"Bash(cd:*)",
|
|
11
|
+
"Bash(cd:*)",
|
|
12
|
+
"Bash(cd:*)",
|
|
13
|
+
"Bash(cd:*)",
|
|
14
|
+
"Bash(cd:*)",
|
|
15
|
+
"Bash(cd:*)"
|
|
16
|
+
],
|
|
17
|
+
"deny": [],
|
|
18
|
+
"ask": []
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Markdown Cell Magic Implementation Design
|
|
2
|
+
|
|
3
|
+
## Problem Statement
|
|
4
|
+
|
|
5
|
+
Training participants need a way to copy Markdown cells from trainer notebooks during live sessions. Unlike code cells which have visible execution counts, Markdown cells lack visible identifiers, making them difficult to reference.
|
|
6
|
+
|
|
7
|
+
## Design Considerations
|
|
8
|
+
|
|
9
|
+
### Current Magic Commands
|
|
10
|
+
- %code (formerly %nb): Handles code cells (identified by execution_count)
|
|
11
|
+
- %md: Handles markdown cells by sequential index
|
|
12
|
+
- %mdat: Handles markdown cells by position relative to code cells
|
|
13
|
+
- %nb: Kept as alias for %code for backward compatibility
|
|
14
|
+
|
|
15
|
+
### Challenges with Markdown Cells
|
|
16
|
+
1. **No visible numbering**: Markdown cells don't have execution counts
|
|
17
|
+
2. **Cell IDs not user-friendly**: Internal IDs exist but aren't visible in the UI
|
|
18
|
+
3. **Mixed cell types**: Notebooks interleave code and Markdown cells
|
|
19
|
+
4. **Cell type conversion**: Content retrieved needs manual conversion from Code to Markdown
|
|
20
|
+
|
|
21
|
+
## Proposed Solutions
|
|
22
|
+
|
|
23
|
+
### Solution 1: Between Code Cells (Fence Method)
|
|
24
|
+
**Syntax**: `%md 1 2` - Get all Markdown cells between code cells 1 and 2
|
|
25
|
+
|
|
26
|
+
**Pros**:
|
|
27
|
+
- Uses existing visible code cell numbers
|
|
28
|
+
- Intuitive for contiguous Markdown sections
|
|
29
|
+
|
|
30
|
+
**Cons**:
|
|
31
|
+
- Ambiguous for non-contiguous selections
|
|
32
|
+
- Doesn't work for Markdown at notebook start/end
|
|
33
|
+
- May return multiple cells when only one is needed
|
|
34
|
+
|
|
35
|
+
### Solution 2: Position-Based Reference
|
|
36
|
+
**Syntax**: `%md after:3` or `%md before:5` - Get Markdown cell(s) after/before code cell
|
|
37
|
+
|
|
38
|
+
**Pros**:
|
|
39
|
+
- Precise single-cell selection
|
|
40
|
+
- Clear intent
|
|
41
|
+
- Works at notebook boundaries
|
|
42
|
+
|
|
43
|
+
**Cons**:
|
|
44
|
+
- Requires multiple commands for multiple cells
|
|
45
|
+
- User needs to know exact positions
|
|
46
|
+
|
|
47
|
+
### Solution 3: Content Pattern Matching
|
|
48
|
+
**Syntax**: `%md "# Section Title"` - Find Markdown cells containing pattern
|
|
49
|
+
|
|
50
|
+
**Pros**:
|
|
51
|
+
- Natural for users who can see content
|
|
52
|
+
- Works without knowing cell positions
|
|
53
|
+
- Can use distinctive headers/keywords
|
|
54
|
+
|
|
55
|
+
**Cons**:
|
|
56
|
+
- Pattern might not be unique
|
|
57
|
+
- Requires exact string matching or regex
|
|
58
|
+
|
|
59
|
+
### Solution 4: Hybrid Cell Magic (Recommended)
|
|
60
|
+
**Syntax**: `%%md 3` - Cell magic that fetches Markdown after code cell 3
|
|
61
|
+
|
|
62
|
+
**Pros**:
|
|
63
|
+
- Automatically converts cell type to Markdown
|
|
64
|
+
- No manual cleanup needed
|
|
65
|
+
- Clear one-to-one mapping
|
|
66
|
+
- Can extend to support ranges
|
|
67
|
+
|
|
68
|
+
**Cons**:
|
|
69
|
+
- Different from line magic pattern
|
|
70
|
+
- Requires cell magic implementation
|
|
71
|
+
|
|
72
|
+
### Solution 5: Smart Sequential Indexing (Recommended Alternative)
|
|
73
|
+
**Syntax**: `%md 3` or `%md 3-5` - Use sequential index for all Markdown cells
|
|
74
|
+
|
|
75
|
+
**Implementation**:
|
|
76
|
+
- Build index of all Markdown cells in order
|
|
77
|
+
- Reference by position (1st, 2nd, 3rd Markdown cell)
|
|
78
|
+
- Optional: `%md --list` to show available Markdown cells with previews
|
|
79
|
+
|
|
80
|
+
**Pros**:
|
|
81
|
+
- Simple, consistent interface
|
|
82
|
+
- Works like %nb for code cells
|
|
83
|
+
- No ambiguity
|
|
84
|
+
- Can show preview list
|
|
85
|
+
|
|
86
|
+
**Cons**:
|
|
87
|
+
- Users need to count Markdown cells
|
|
88
|
+
- Numbers change if trainer adds cells
|
|
89
|
+
|
|
90
|
+
## Recommended Implementation
|
|
91
|
+
|
|
92
|
+
Implement **two complementary approaches**:
|
|
93
|
+
|
|
94
|
+
### 1. Primary: Sequential Markdown Index (`%md`)
|
|
95
|
+
```python
|
|
96
|
+
%md 1 # Get 1st Markdown cell
|
|
97
|
+
%md 3-5 # Get 3rd through 5th Markdown cells
|
|
98
|
+
%md --list # List all Markdown cells with previews
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 2. Secondary: Position-Based Reference (`%mdat`)
|
|
102
|
+
```python
|
|
103
|
+
%mdat after:3 # Markdown cell(s) after code cell 3
|
|
104
|
+
%mdat before:5 # Markdown cell(s) before code cell 5
|
|
105
|
+
%mdat between:3:5 # All Markdown between code cells 3 and 5
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Implementation Details
|
|
109
|
+
|
|
110
|
+
### Cell Type Handling
|
|
111
|
+
- Unlike %nb, the %md and %mdat magics do NOT add a comment header
|
|
112
|
+
- Content is inserted directly without any prefix
|
|
113
|
+
- Users manually convert cell type (Ctrl+M, M in Jupyter)
|
|
114
|
+
- Future: Investigate IPython API for automatic cell type conversion
|
|
115
|
+
|
|
116
|
+
### Preview Feature
|
|
117
|
+
```python
|
|
118
|
+
%md --list
|
|
119
|
+
# Output:
|
|
120
|
+
# 1: # Introduction
|
|
121
|
+
# This notebook covers...
|
|
122
|
+
# 2: ## Data Loading
|
|
123
|
+
# We'll use pandas to...
|
|
124
|
+
# 3: ### Important Notes
|
|
125
|
+
# Remember to check...
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Error Handling
|
|
129
|
+
- Clear messages for invalid ranges
|
|
130
|
+
- Warnings when no Markdown cells found
|
|
131
|
+
- Handle notebooks without code cells gracefully
|
|
132
|
+
|
|
133
|
+
## Alternative Approaches Considered
|
|
134
|
+
|
|
135
|
+
### Invisible Anchors
|
|
136
|
+
Add hidden HTML comments as anchors in Markdown cells:
|
|
137
|
+
```markdown
|
|
138
|
+
<!-- md-anchor: section1 -->
|
|
139
|
+
# Introduction
|
|
140
|
+
```
|
|
141
|
+
**Rejected**: Requires modifying trainer notebooks
|
|
142
|
+
|
|
143
|
+
### Visual Cell Numbers
|
|
144
|
+
Propose Jupyter enhancement to show Markdown cell numbers in UI.
|
|
145
|
+
**Rejected**: Outside our control, long-term solution
|
|
146
|
+
|
|
147
|
+
### Dual Output
|
|
148
|
+
Return both code and Markdown versions, let user choose.
|
|
149
|
+
**Rejected**: Clutters interface, still requires manual work
|
|
150
|
+
|
|
151
|
+
## Migration Path
|
|
152
|
+
|
|
153
|
+
1. Rename `%nb` to `%code` as the canonical command for code cells
|
|
154
|
+
2. Keep `%nb` as an alias for backward compatibility
|
|
155
|
+
3. Add `%md` for Markdown cells by index
|
|
156
|
+
4. Add `%mdat` for position-based Markdown cell retrieval
|
|
157
|
+
5. Document all commands in help text
|
|
158
|
+
|
|
159
|
+
## Usage Examples
|
|
160
|
+
|
|
161
|
+
### Trainer notebook structure:
|
|
162
|
+
```
|
|
163
|
+
[Code 1] Import statements
|
|
164
|
+
[Markdown] # Data Analysis Workshop
|
|
165
|
+
[Markdown] ## Prerequisites
|
|
166
|
+
[Code 2] Load data
|
|
167
|
+
[Markdown] ### Understanding the dataset
|
|
168
|
+
[Code 3] Explore data
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Participant commands:
|
|
172
|
+
```python
|
|
173
|
+
%code 1 # Get code cell 1 (preferred)
|
|
174
|
+
%nb 1 # Same as %code 1 (backward compatibility)
|
|
175
|
+
%md 1 # Get "# Data Analysis Workshop"
|
|
176
|
+
%md 2-3 # Get "## Prerequisites" and "### Understanding the dataset"
|
|
177
|
+
%mdat after:1 # Get markdown after code cell 1
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Conclusion
|
|
181
|
+
|
|
182
|
+
The recommended approach balances usability with implementation simplicity. The sequential index method (`%md`) provides a familiar interface similar to `%nb`, while the position-based method (`%mdat`) offers precision when needed. Together, they cover all common use cases without requiring notebook modifications or complex UI changes.
|
|
@@ -10,23 +10,26 @@ You can load the IPython extension like so:
|
|
|
10
10
|
assuming the pythoncharmers_meta packages has been installed system-wide.
|
|
11
11
|
|
|
12
12
|
This package depends on packages used in Python Charmers training courses. It
|
|
13
|
-
also provides an IPython extension that enables
|
|
13
|
+
also provides an IPython extension that enables several magic commands:
|
|
14
14
|
|
|
15
|
-
- %
|
|
16
|
-
- %
|
|
15
|
+
- %code: Grab code cells from a notebook
|
|
16
|
+
- %md: Grab markdown cells from a notebook (by sequential index)
|
|
17
|
+
- %mdat: Grab markdown cells by position relative to code cells
|
|
18
|
+
- %nb: Alias for %code (for backward compatibility)
|
|
19
|
+
- %ai: Invoke the `llm` package for quick use of an LLM like gpt-4o-mini
|
|
17
20
|
|
|
18
|
-
The %
|
|
19
|
-
|
|
20
|
-
notebook in the latest ~/Trainer_XYZ folder.
|
|
21
|
-
|
|
22
|
-
The %ai magic invokes the `llm` package for quick use of an LLM like gpt-4o-mini.
|
|
21
|
+
The %code, %md, and %mdat magics grab cells from a notebook on the filesystem,
|
|
22
|
+
defaulting to the most recently modified notebook in the latest ~/Trainer_XYZ folder.
|
|
23
23
|
|
|
24
24
|
For help on the magics, add a trailing question mark. For example:
|
|
25
25
|
|
|
26
|
-
%
|
|
26
|
+
%code?
|
|
27
|
+
%md?
|
|
28
|
+
%mdat?
|
|
29
|
+
%ai?
|
|
27
30
|
|
|
28
31
|
Two additional magics are available for getting and setting the current
|
|
29
|
-
path and/or file that %
|
|
32
|
+
path and/or file that %code, %md, and %mdat query. To get help on these, run:
|
|
30
33
|
|
|
31
34
|
%nbfile?
|
|
32
35
|
%nbpath?
|
|
@@ -34,6 +37,7 @@ path and/or file that %nb queries. To get help on these, run:
|
|
|
34
37
|
"""
|
|
35
38
|
|
|
36
39
|
from .nb_magic import NotebookMagic
|
|
40
|
+
|
|
37
41
|
try:
|
|
38
42
|
from .ai_magic import AIMagic
|
|
39
43
|
except Exception as e:
|
|
@@ -54,5 +58,3 @@ def load_ipython_extension(ipython):
|
|
|
54
58
|
ipython.register_magics(AIMagic)
|
|
55
59
|
except Exception as e:
|
|
56
60
|
print(e)
|
|
57
|
-
|
|
58
|
-
|