You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -344,6 +344,19 @@ This allows documentation to include "Try this in Jupyter" links that launch int
344
344
345
345
**BINDER_ID Extraction Details**:
346
346
347
+
The `BINDER_ID` marker allows example authors to specify a Git reference (branch name or commit SHA) from the `redis/binder-launchers` repository. This enables the Hugo templates to generate "Run this example in the browser" links that open the example in an interactive Jupyter notebook environment via BinderHub.
348
+
349
+
**Quick Implementation Checklist**:
350
+
-[ ] Add constant: `BINDER_ID = 'BINDER_ID'` (around line 11 in `example.py`)
351
+
-[ ] Add class attribute: `binder_id = None` (around line 49 in `Example` class)
352
+
-[ ] Add regex pattern: `binder = re.compile(...)` (around line 94 in `make_ranges()`)
353
+
-[ ] Add detection logic in `elif` chain (around line 157 in main loop)
354
+
-[ ] Add conditional metadata field in `build/local_examples.py` (around line 183)
355
+
-[ ] Add conditional metadata field in `build/components/component.py` (around line 278)
356
+
-[ ] Test with both branch name and commit SHA
357
+
-[ ] Verify `BINDER_ID` line removed from processed output
358
+
-[ ] Verify `binderId` appears in `data/examples.json`
359
+
347
360
The parser should implement the following logic in `build/components/example.py`:
348
361
349
362
**1. Add Constant and Class Attribute**:
@@ -372,30 +385,40 @@ self.binder_id = None
372
385
373
386
**2. Compile Regex Pattern**:
374
387
375
-
In the `make_ranges()` method, add the regex pattern compilation alongside other patterns (after `exid` pattern):
388
+
In the `make_ranges()` method (around line 94), add the regex pattern compilation alongside other patterns (after `exid` pattern):
**Exact location**: In `build/components/example.py`, class `Example`, method `make_ranges()`, in the section where regex patterns are compiled (after line 93).
396
+
382
397
**Pattern explanation**:
383
398
-`{PREFIXES[self.language]}` - Language-specific comment prefix (e.g., `#` or `//`)
384
399
-`\\s?` - Optional whitespace after comment prefix
385
400
-`{BINDER_ID}` - The literal string "BINDER_ID"
386
-
-`\\s+` - Required whitespace before hash
387
-
-`([a-f0-9]{40})` - Capture group for exactly 40 hexadecimal characters
401
+
-`\\s+` - Required whitespace before identifier
402
+
-`([a-zA-Z0-9_-]+)` - Capture group for Git reference (commit SHA or branch name)
-**Backward compatible**: The old pattern `([a-f0-9]{40})` only matched commit SHAs. The new pattern `([a-zA-Z0-9_-]+)` matches commit SHAs (which are valid under the new pattern) AND branch names.
409
+
-**No breaking changes**: Existing examples with commit SHAs continue to work without modification.
410
+
-**Flexible**: Supports common Git branch naming conventions (kebab-case, snake_case, alphanumeric).
388
411
389
412
**3. Detection and Extraction**:
390
413
391
-
Add detection logic in the main processing loop, **after** the `EXAMPLE:` check and **before** the `GO_OUTPUT` check:
414
+
Add detection logic in the main processing loop (around line 157), **after** the `EXAMPLE:` check and **before** the `GO_OUTPUT` check:
392
415
393
416
```python
394
417
elif re.search(exid, l):
395
418
output =False
396
419
pass
397
420
elif re.search(binder, l):
398
-
# Extract BINDER_ID hash value
421
+
# Extract BINDER_ID value (commit SHA or branch name)
**Exact location**: In `build/components/example.py`, class `Example`, method `make_ranges()`, in the main `while curr < len(self.content):` loop, in the `elif` chain that handles special markers.
432
+
408
433
**Critical implementation details**:
409
434
-**Must set `output = False`**: This prevents the line from being added to the `content` array
410
435
-**Placement matters**: Must be in the `elif` chain, not a separate `if` statement
411
436
-**No `content.append(l)`**: The line is skipped entirely, just like `EXAMPLE:` lines
412
-
-**Extract before setting output**: Get the hash value before marking the line to skip
437
+
-**Extract before setting output**: Get the value before marking the line to skip
438
+
-**Order in elif chain**: Must come after `exid` (EXAMPLE:) but before `go_output` to maintain proper precedence
413
439
414
440
**4. Storage in Metadata**:
415
441
@@ -469,6 +495,9 @@ The `BINDER_ID` line is removed from output through the same mechanism as other
469
495
3.**Using `if` instead of `elif`**: Could cause multiple conditions to match
470
496
4.**Not checking `if match`**: Could cause AttributeError if regex doesn't match
471
497
5.**Adding field unconditionally**: Results in `"binderId": null` in JSON for examples without the marker
498
+
6.**Regex pattern too restrictive**: Using `[a-f0-9]{40}` only matches commit SHAs, not branch names
499
+
7.**Regex pattern too permissive**: Using `.*` or `.+` could match invalid characters or whitespace
500
+
8.**Wrong capture group**: Using `match.group(0)` returns the entire match including comment prefix, not just the value
472
501
473
502
**6. Complete Example Flow**:
474
503
@@ -477,7 +506,7 @@ Here's a complete example showing how a file is processed:
**Recommendation**: Use branch names during development for easier iteration, then switch to commit SHAs when the example is stable and ready for production.
-**Symptom 3**: Link opens but BinderHub shows error
1657
1766
-**Cause 1**: Invalid commit hashin`binderId`
@@ -1982,7 +2091,7 @@ In Markdown files:
1982
2091
| Marker | Purpose | Example | Notes |
1983
2092
|--------|---------|---------|-------|
1984
2093
|`EXAMPLE: id`| Define example ID|`# EXAMPLE: home_vecsets` | **Required**. Must be first line. Removed from processed output. |
1985
-
|`BINDER_IDhash`| Define BinderHub commit hash|`# BINDER_ID 6bbed3da294e8de5a8c2ad99abf883731a50d4dd` | **Optional**. Typically line 2 (after EXAMPLE). Hash must be exactly 40 hexadecimal characters (Git commit SHA). Removed from processed output. Stored as `binderId` in metadata. Used to generate interactive Jupyter notebook links. |
2094
+
|`BINDER_IDref`| Define BinderHub Git reference|`# BINDER_ID python-landing`<br>`# BINDER_ID 6bbed3da294e8de5a8c2ad99abf883731a50d4dd` | **Optional**. Typically line 2 (after EXAMPLE). Value can be a Git branch name (e.g., `python-landing`, `main`) or commit SHA (40 hex chars). Removed from processed output. Stored as `binderId` in metadata. Used to generate interactive Jupyter notebook links. |
1986
2095
|`HIDE_START`| Start hidden block |`# HIDE_START` | Code hidden by default, revealed with eye button |
1987
2096
|`HIDE_END`| End hidden block |`# HIDE_END` | Must close HIDE_START |
0 commit comments