Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive mode doesn't seem to work when running nbdev_preview #935

Closed
Jaume-JCI opened this issue Aug 25, 2022 · 1 comment
Closed

Recursive mode doesn't seem to work when running nbdev_preview #935

Jaume-JCI opened this issue Aug 25, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Jaume-JCI
Copy link

I followed the nbdev_cards tutorial, but setting recursive=True in settings.ini. I was able to successfully complete all the steps except for the last one, which is previewing the docs. When I run nbdev_preview --port 3012, it throws the following error:

Preparing to preview
Traceback (most recent call last):
  File "/anaconda/envs/nbdevv2_master/lib/python3.10/site-packages/IPython/core/formatters.py", line 222, in catch_format_error
    r = method(self, *args, **kwargs)
  File "/anaconda/envs/nbdevv2_master/lib/python3.10/site-packages/IPython/core/formatters.py", line 343, in __call__
    return method()
  File "/home/jcidatascience/jaume/workspace/other/nbdevv2/nbdev/nbdev/showdoc.py", line 166, in _repr_markdown_
    src = NbdevLookup().code(self.fn)
  File "/home/jcidatascience/jaume/workspace/other/nbdevv2/nbdev/nbdev/doclinks.py", line 204, in code
    line = _lineno(sym, py)
  File "/workspace/nbdev/nbdev/doclinks.py", line 149, in _lineno
    def _lineno(sym, fname): return _get_exps(fname).get(sym.rpartition('.')[2], None) if fname else None
  File "/workspace/nbdev/nbdev/doclinks.py", line 140, in _get_exps
    mf = _find_mod(mod)
  File "/workspace/nbdev/nbdev/doclinks.py", line 135, in _find_mod
    loc = Path(importlib.util.find_spec(mp).origin).parent
AttributeError: 'NoneType' object has no attribute 'origin'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/anaconda/envs/nbdevv2_master/bin/nbdev_filter", line 33, in <module>
    sys.exit(load_entry_point('nbdev', 'console_scripts', 'nbdev_filter')())
  File "/anaconda/envs/nbdevv2_master/lib/python3.10/site-packages/fastcore/script.py", line 117, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/workspace/nbdev/nbdev/cli.py", line 64, in nbdev_filter
    with redirect_stdout(dn): filt.nb_proc(nb).process()
  File "/workspace/nbdev/nbdev/process.py", line 122, in process
    for proc in self.procs: self._proc(proc)
  File "/workspace/nbdev/nbdev/process.py", line 115, in _proc
    for cell in self.nb.cells: self._process_cell(proc, cell)
  File "/workspace/nbdev/nbdev/process.py", line 106, in _process_cell
    if callable(proc) and not _is_direc(proc): cell = opt_set(cell, proc(cell))
  File "/workspace/nbdev/nbdev/processors.py", line 290, in __call__
    if self.k.exc: raise Exception(f"Error{' in notebook: '+title if title else ''} in cell {cell.idx_} :\n{cell.source}") from self.k.exc[1]
Exception: Error in notebook: Additions in cell 6 :
#|output: asis
#| echo: false
show_doc(Other)

I was able to provide a fix (not easy, since ipdb doesn't seem to work well with nbdev_preview). The fix is as follows:
Right before line 135 of nbdev/doclinks.py in _find_mod, we need to do:

mp = str(mp).replace ('/', '.')

before the original line

loc = Path(importlib.util.find_spec(mp).origin).parent

By doing so, importlib.util.find_spec is able to successfully find the module mp. Originally it was returning None.

However, after this fix, I run nbdev_preview and quarto throws the following error:

ERROR: SyntaxError: Unexpected token l in JSON at position 0

I wasn't able to debug this error, unfortunately.

A separate issue I found is that, when running nbdev_new, I need to indicate --recursive True --nbs_path nbs:

nbdev_new --recursive True --nbs_path nbs

Otherwise, if I just run nbdev_new and then edit settings.ini and change recursive in there, it doesn't work. I didn't find this in the tutorial when it talks about using nbdev_new. But this is minor thing, might not be important at all.

Thank you!
Jaume

@jph00 jph00 self-assigned this Aug 26, 2022
@hamelsmu hamelsmu added the bug Something isn't working label Aug 26, 2022
@jph00 jph00 closed this as completed in 1666148 Aug 26, 2022
@jph00
Copy link
Member

jph00 commented Aug 26, 2022

Thanks for the clear issue. Your fix in _find_mod was very close - but the actual fix was to use partition() instead of rpartition().

Please try installing from master, and if you're still having any problems, please open a new issue letting us know how we can repro it (ideally with a link to a github repo showing the problem).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants