MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / update_docstring

Function update_docstring

monai/transforms/utils_create_transform_ims.py:233–268  ·  view source on GitHub ↗

Find the documentation for a given transform and if it's missing, add a pointer to the transform's example image.

(code_path, transform_name)

Source from the content-addressed store, hash-verified

231
232
233def update_docstring(code_path, transform_name):
234 """
235 Find the documentation for a given transform and if it's missing,
236 add a pointer to the transform's example image.
237 """
238 with open(code_path) as f:
239 contents = f.readlines()
240 doc_start = None
241 for i, line in enumerate(contents):
242 # find the line containing start of the transform documentation
243 if "`" + transform_name + "`" in line:
244 doc_start = i
245 break
246 if doc_start is None:
247 raise RuntimeError("Couldn't find transform documentation")
248
249 # if image is already in docs, nothing to do
250 image_line = doc_start + 2
251 if ".. image" in contents[image_line]:
252 return
253
254 # add the line for the image and the alt text
255 contents_orig = deepcopy(contents)
256 contents.insert(
257 image_line,
258 ".. image:: https://github.com/Project-MONAI/DocImages/raw/main/transforms/" + transform_name + ".png\n",
259 )
260 contents.insert(image_line + 1, " :alt: example of " + transform_name + "\n")
261
262 # check that we've only added two lines
263 if len(contents) != len(contents_orig) + 2:
264 raise AssertionError
265
266 # write the updated doc to overwrite the original
267 with open(code_path, "w") as f:
268 f.writelines(contents)
269
270
271def pre_process_data(data, ndim, is_map, is_post):

Callers 1

create_transform_imFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…