Skip to content

Commit 205c9ed

Browse files
committed
Added docstrings to several undocumented functions.
1 parent f4f501a commit 205c9ed

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

irrelevant/notebook_generator.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555

5656

5757
def generate_code_block(statements, output):
58+
"""
59+
Generates a code block that executes the given statements.
60+
61+
:param statements: The list of statements to execute.
62+
:type statements: list(str)
63+
"""
5864
global sequence_num
5965
result = {
6066
"type": "code",
@@ -67,6 +73,9 @@ def generate_code_block(statements, output):
6773

6874

6975
def generate_markdown_block(lines):
76+
"""
77+
Generates a markdown block from a list of lines.
78+
"""
7079
global sequence_num
7180
result = {
7281
"type": "markdown",
@@ -85,6 +94,12 @@ def is_interactive_statement(line):
8594

8695

8796
def parse_example_parts(lines, title, current_line):
97+
"""
98+
Parse the given lines and return a dictionary with two keys:
99+
build_up, which contains all the text before an H4 (explanation) is encountered,
100+
and
101+
explanation, which contains all the text after build_up until --- or another H3 is encountered.
102+
"""
88103
parts = {
89104
"build_up": [],
90105
"explanation": []
@@ -191,6 +206,14 @@ def remove_from_beginning(tokens, line):
191206

192207

193208
def inspect_and_sanitize_code_lines(lines):
209+
"""
210+
Remove lines from the beginning of a code block that are not statements.
211+
212+
:param lines: A list of strings, each representing a line in the code block.
213+
:returns is_print_present, sanitized_lines: A boolean indicating whether print was present in the original code and a list of strings representing
214+
sanitized lines. The latter may be an empty list if all input lines were removed as comments or whitespace (and thus did not contain any statements).
215+
This function does not remove blank lines at the end of `lines`.
216+
"""
194217
tokens_to_remove = STATEMENT_PREFIXES
195218
result = []
196219
is_print_present = False
@@ -203,6 +226,23 @@ def inspect_and_sanitize_code_lines(lines):
203226

204227

205228
def convert_to_cells(cell_contents, read_only):
229+
"""
230+
Converts a list of dictionaries containing markdown and code cells into a Jupyter notebook.
231+
232+
:param cell_contents: A list of dictionaries, each
233+
dictionary representing either a markdown or code cell. Each dictionary should have the following keys: "type", which is either "markdown" or "code",
234+
and "value". The value for type = 'markdown' is the content as string, whereas the value for type = 'code' is another dictionary with two keys,
235+
statements and output. The statements key contains all lines in between ```py\n``` (including) until ```\n```, while output contains all lines after
236+
```.output py\n```.
237+
:type cell_contents: List[Dict]
238+
239+
:param read_only (optional): If True then only print outputs are included in converted
240+
cells. Default False
241+
:type read_only (optional): bool
242+
243+
:returns A Jupyter notebook containing all cells from input parameter `cell_contents`.
244+
Each converted cell has metadata attribute collapsed set to true if it's code-cell otherwise None if it's markdow-cell.
245+
"""
206246
cells = []
207247
for stuff in cell_contents:
208248
if stuff["type"] == "markdown":
@@ -269,6 +309,9 @@ def convert_to_cells(cell_contents, read_only):
269309

270310

271311
def convert_to_notebook(pre_examples_content, parsed_json, post_examples_content):
312+
"""
313+
Convert a JSON file containing the examples to a Jupyter Notebook.
314+
"""
272315
result = {
273316
"cells": [],
274317
"metadata": {},

wtfpython-pypi/wtf_python/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414

1515
def fetch_updated_doc():
16+
"""
17+
Fetch the latest version of the file at `url` and save it to `file_path`.
18+
If anything goes wrong, do nothing.
19+
"""
1620
try:
1721
print("Fetching the latest version...")
1822
urlretrieve(url, file_path)

0 commit comments

Comments
 (0)