code_context
Module providing a class and context manager for tracking code.
The way of tracking code and displaying it is handled through a context manager, which is the return value obtained when adding an object to a page.
The context manager gives different options on how to display the code and the results such as:
- A code block at the top followed by the output similar to standard jupyter notebooks.
- A Tab-format where output and code are on separate tabs
- A collapsed code block followed by the output or the output followed by a collapsed code block.
CodeContext
Context manager for the code tracking and content accumulation.
Source code in mkreports/code_context.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
__init__(layout, relative_to=None, name_only=False, add_bottom=True, stack_level=2)
Initialize the context manager. This should usually not be needed by end users.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layout |
Layouts
|
The layout to use. One of 'tabbed', 'top-o', 'top-c', 'bottom-o', 'bottom-c' or 'nocode'. |
required |
relative_to |
Optional[Path]
|
Path relative to where the code file will be named. |
None
|
name_only |
bool
|
For the code file, use name instead of path? |
False
|
add_bottom |
bool
|
Should content be added to bottom or top of page? |
True
|
stack_level |
int
|
Levels lower in the stack where the code is to be tracked. |
2
|
Source code in mkreports/code_context.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
active()
Indicates if the context-manager is active.
Source code in mkreports/code_context.py
132 133 134 135 |
|
add(md_obj)
Add a new content object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
md_obj |
MdObj
|
The content to be added. |
required |
Source code in mkreports/code_context.py
137 138 139 140 141 142 143 144 145 146 147 |
|
md_obj(page_info)
Return the markdown object that represents output and code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_info |
PageInfo
|
PageInfo object about the page where the content is to be added. |
required |
Returns:
Name | Type | Description |
---|---|---|
MdObj |
MdObj
|
Markdown object representing the formatted output in the requested layout |
Source code in mkreports/code_context.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
do_layout(code, content, layout, page_info)
Do the layouting for a content and code block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code |
Optional[MdObj]
|
The MdObj for the code. If layout is 'nocode', can be None. |
required |
content |
MdObj
|
The content to add. Can't be missing. |
required |
layout |
Layouts
|
Type of layout for code-tracking. One of 'tabbed', 'top-o', 'top-c', 'bottom-o', 'bottom-c' or 'nocode'. |
required |
page_info |
PageInfo
|
PageInfo object corresponding to the page to which it should be added. |
required |
Returns:
Type | Description |
---|---|
MdObj
|
A MdObj with the requested layout. |
Source code in mkreports/code_context.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|