fastai/nbprocess-old

showdoc method bug

Isaac-Flath opened this issue · 0 comments

@jph00

If I use show_doc on a method, I am unable the render using nbprocess_quarto. show_doc works properly on the class. After getting the error, if I comment out the show_doc function call on the method and rerun, no error and everything works.

Code to reproduce the error

#|default_exp showdoctest

from nbprocess.showdoc import show_doc

#|export
def say_hello(to):
    "Say hello to somebody"
    return f'Hello {to}!'
   
#|export
class HelloSayer:
    "Say hello to `to` using `say_hello`"
    def __init__(self, to): self.to = to

    def say(self):
        "Do the saying"
        return say_hello(self.to)
       
       
# show_doc(HelloSayer) # This works
show_doc(HelloSayer.say) # This does not work

If the method is in show_doc and I use nbprocess_quarto, I get the following stack trace.

Traceback (most recent call last):
  File "/Users/isaacflath/opt/miniconda3/bin/nbprocess_filter", line 33, in <module>
    sys.exit(load_entry_point('nbprocess', 'console_scripts', 'nbprocess_filter')())
  File "/Users/isaacflath/opt/miniconda3/lib/python3.9/site-packages/fastcore/script.py", line 113, in _f
    tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/Users/isaacflath/github/nbprocess/nbprocess/cli.py", line 93, in nbprocess_filter
    NBProcessor(nb=nb, procs=filt.procs(), preprocs=filt.preprocs(), postprocs=filt.postprocs()).process()
  File "/Users/isaacflath/github/nbprocess/nbprocess/process.py", line 86, in process
    self.nb = opt_set(self.nb, proc(self.nb))
  File "/Users/isaacflath/github/nbprocess/nbprocess/processors.py", line 145, in add_show_docs
    shown_docs = {t.value.args[0].id for t in _show_docs(trees)}
  File "/Users/isaacflath/github/nbprocess/nbprocess/processors.py", line 145, in <setcomp>
    shown_docs = {t.value.args[0].id for t in _show_docs(trees)}
AttributeError: 'Attribute' object has no attribute 'id'
Traceback (most recent call last):
  File "/Users/isaacflath/opt/miniconda3/bin/nbprocess_filter", line 33, in <module>
    sys.exit(load_entry_point('nbprocess', 'console_scripts', 'nbprocess_filter')())
  File "/Users/isaacflath/opt/miniconda3/lib/python3.9/site-packages/fastcore/script.py", line 113, in _f
    tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/Users/isaacflath/github/nbprocess/nbprocess/cli.py", line 93, in nbprocess_filter
    NBProcessor(nb=nb, procs=filt.procs(), preprocs=filt.preprocs(), postprocs=filt.postprocs()).process()
  File "/Users/isaacflath/github/nbprocess/nbprocess/process.py", line 86, in process
    self.nb = opt_set(self.nb, proc(self.nb))
  File "/Users/isaacflath/github/nbprocess/nbprocess/processors.py", line 145, in add_show_docs
    shown_docs = {t.value.args[0].id for t in _show_docs(trees)}
  File "/Users/isaacflath/github/nbprocess/nbprocess/processors.py", line 145, in <setcomp>
    shown_docs = {t.value.args[0].id for t in _show_docs(trees)}
AttributeError: 'Attribute' object has no attribute 'id'
Traceback (most recent call last):
  File "/Users/isaacflath/opt/miniconda3/lib/python3.9/shutil.py", line 814, in move
    os.rename(src, real_dst)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/isaacflath/github/quarto-debug/nbs/docs/README.md' -> '/Users/isaacflath/github/quarto-debug/README.md'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/isaacflath/opt/miniconda3/bin/nbprocess_quarto", line 33, in <module>
    sys.exit(load_entry_point('nbprocess', 'console_scripts', 'nbprocess_quarto')())
  File "/Users/isaacflath/opt/miniconda3/lib/python3.9/site-packages/fastcore/script.py", line 113, in _f
    tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/Users/isaacflath/github/nbprocess/nbprocess/cli.py", line 123, in nbprocess_quarto
    shutil.move(docs/'README.md', cfg_path)
  File "/Users/isaacflath/opt/miniconda3/lib/python3.9/shutil.py", line 834, in move
    copy_function(src, real_dst)
  File "/Users/isaacflath/opt/miniconda3/lib/python3.9/shutil.py", line 443, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/Users/isaacflath/opt/miniconda3/lib/python3.9/shutil.py", line 265, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/isaacflath/github/quarto-debug/nbs/docs/README.md'