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)
| 231 | |
| 232 | |
| 233 | def 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 | |
| 271 | def pre_process_data(data, ndim, is_map, is_post): |
no outgoing calls
no test coverage detected
searching dependent graphs…