I have a code that you can select a jupyter notebook file(by panel) then this code put every cells in seperate python files, for example cell number 1 in 1.py cell number 2 in 2.py and..., after that with pdoc command we create document for each python file(in fact each cell) and then by creating new cells at the end of that jupyter notebook, we add generated document on those cells, below is the for loop to iterate every cell and call related functions. the issue is that for some cells that contains for instance just test() or some annotation like @property, pdoc command doesn't have result and we got an error like 2.py connot import and then process getting stop and remaining cells which already put in separate python file can not be documented. How to fix this so that if for example cell 2(2.py) has an error, it goes to the next cell or file(cell3 or 3.py) and does not stop the for loop completely.
for file in files.value:
source = file
dest = add_suffix(source, " documented")
dest1 = "/home/dqm/pydev/notebook_copy"
shutil.copy(source,dest)
document_note = shutil.copy(dest,dest1)
os.remove(dest)
notebook = get_notebook(document_note)
for filename, code in get_code_cells_content(notebook['cells']):
save_as_python_file(filename, code)
print('documentation starting')
#!pdoc --html ./'{filename}'.py -o ./notebook_copy/document
res = Popen(["pdoc", "--html", f"./{filename}.py", "-o", "./notebook_copy/document"], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() # template
status.value += res[0].decode("utf-8") + "\n"
status.value += res[1] .decode("utf-8") + "\n"
#!pdoc --output-dir=./notebook_copy/document ./'{filename}'.py
res = Popen(["pdoc", "--output-dir=./notebook_copy/document", f"./{filename}.py"], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() # template
status.value += res[0].decode("utf-8") + "\n"
status.value += res[1] .decode("utf-8") + "\n"
create_new_cell(document_note,filename)
os.remove(f'{filename}.py')
remove("./notebook_copy/document")
display(pn.widgets.StaticText(name='documented', value='succesfully'))
pass # call here the documentation creator
Thanks in advance
I treid to put try except but it didn't work