| 27 | } |
| 28 | |
| 29 | def run(self): |
| 30 | example_name = get_normalized_example_name( |
| 31 | self.arguments[0], |
| 32 | # only used if example name starts with "/" |
| 33 | self.get_source_info()[0], |
| 34 | ) |
| 35 | |
| 36 | show_linenos = "linenos" in self.options |
| 37 | live_example_is_default_tab = "result-is-default-tab" in self.options |
| 38 | activate_result = "activate-button" not in self.options |
| 39 | |
| 40 | ex_files = get_example_files_by_name(example_name) |
| 41 | if not ex_files: |
| 42 | src_file, line_num = self.get_source_info() |
| 43 | msg = f"Missing example named {example_name!r} referenced by document {src_file}:{line_num}" |
| 44 | raise ValueError(msg) |
| 45 | |
| 46 | labeled_tab_items: list[tuple[str, Any]] = [] |
| 47 | if len(ex_files) == 1: |
| 48 | labeled_tab_items.append( |
| 49 | ( |
| 50 | "main.py", |
| 51 | _literal_include( |
| 52 | path=ex_files[0], |
| 53 | linenos=show_linenos, |
| 54 | ), |
| 55 | ) |
| 56 | ) |
| 57 | else: |
| 58 | for path in sorted( |
| 59 | ex_files, key=lambda p: "" if p.name == "main.py" else p.name |
| 60 | ): |
| 61 | labeled_tab_items.append( |
| 62 | ( |
| 63 | path.name, |
| 64 | _literal_include( |
| 65 | path=path, |
| 66 | linenos=show_linenos, |
| 67 | ), |
| 68 | ) |
| 69 | ) |
| 70 | |
| 71 | result_tab_item = ( |
| 72 | "🚀 result", |
| 73 | _interactive_widget( |
| 74 | name=example_name, |
| 75 | with_activate_button=not activate_result, |
| 76 | ), |
| 77 | ) |
| 78 | if live_example_is_default_tab: |
| 79 | labeled_tab_items.insert(0, result_tab_item) |
| 80 | else: |
| 81 | labeled_tab_items.append(result_tab_item) |
| 82 | |
| 83 | return TabSetDirective( |
| 84 | "WidgetExample", |
| 85 | [], |
| 86 | {}, |