Giter Club home page Giter Club logo

Comments (9)

sgugger avatar sgugger commented on May 17, 2024

The library doesn't support having two different default_exp values. To export a cell in a different module than the default you set, set the flag # export module_name. If you want to export one given to cell to two different modules, you will need to duplicate it with two different export flags for now.
Hope this helps solve your issue!

from nbdev.

raynardj avatar raynardj commented on May 17, 2024

ult_exp values. To export a cell in a different module than the default you set, set the flag # export module_name. If you want to export one given to cell to two different modules, you will need to duplicate it with two different export flags for now.
Hope this helps solve your issue!

Thanks for the reply, yes I realize there is # export module_name
But this will run in to error when nbdev_build_lib,

AttributeError: 'NoneType' object has no attribute 'start'

I pip installed nbdev from the master branch of git source on 2020-02-06, using source code of this committed version

from nbdev.

sgugger avatar sgugger commented on May 17, 2024

What is the exact comment you type, so that I have a reproducer?

from nbdev.

raynardj avatar raynardj commented on May 17, 2024

Reproduce the No such file or directory error

eg. the dummy notebook I was trying to convert,

I ran nbdev_build_lib, the following is the error:

Traceback (most recent call last):
  File "/Users/salvor/anaconda3/bin/nbdev_build_lib", line 8, in <module>
    sys.exit(nbdev_build_lib())
  File "/Users/salvor/.local/lib/python3.7/site-packages/fastscript/core.py", line 73, in _f
    func(**args.__dict__)
  File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/cli.py", line 22, in nbdev_build_lib
    notebook2script(fname=fname)
  File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 371, in notebook2script
    for f in sorted(files): d = _notebook2script(f, silent=silent, to_dict=d)
  File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 310, in _notebook2script
    if to_dict is None: _add2add(fname_out, [f"'{f}'" for f in names if '.' not in f and len(f) > 0] + extra)
  File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 180, in _add2add
    with open(fname, 'r', encoding='utf8') as f: text = f.read()
FileNotFoundError: [Errno 2] No such file or directory: '/Users/salvor/github/forgebox/forgebox/different_file.py

However, the test_nbdev.py was built successfully.

Try the empty file

I guess the pre-existence is important for different_file.py, so I created such empty file, run nbdev_build_lib, following the new error

Traceback (most recent call last):
  File "/Users/salvor/anaconda3/bin/nbdev_build_lib", line 8, in <module>
    sys.exit(nbdev_build_lib())
  File "/Users/salvor/.local/lib/python3.7/site-packages/fastscript/core.py", line 73, in _f
    func(**args.__dict__)
  File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/cli.py", line 22, in nbdev_build_lib
    notebook2script(fname=fname)
  File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 371, in notebook2script
    for f in sorted(files): d = _notebook2script(f, silent=silent, to_dict=d)
  File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 310, in _notebook2script
    if to_dict is None: _add2add(fname_out, [f"'{f}'" for f in names if '.' not in f and len(f) > 0] + extra)
  File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export.py", line 183, in _add2add
    start,end = re_all.start(),re_all.end()
AttributeError: 'NoneType' object has no attribute 'start'

When using another notebook's default_exp

Okay, so the empty one won't suffice, so I created another notebook , solely in purpose to create a fully fledged py file.

This time, nbdev_build_lib turns out fine. all py file are in place

But nbdev_build_docs will have this error

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-e86c8b69e1ff> in <module>
----> 1 show_doc(different_file_func, default_cls_level=2)

NameError: name 'different_file_func' is not defined

from nbdev.

sgugger avatar sgugger commented on May 17, 2024

You have to put a number of your notebooks since they need to run in a certain order during nbdev_build_lib:

  • the notebook creating different_file.py has to run first so that the module exists
  • then the notebook creating test_file.py can run and add its function different_file_func to different_file

This is why all notebooks in our nbdev-generated packages begin with digits.

from nbdev.

raynardj avatar raynardj commented on May 17, 2024

yes I tried, the correct order can generate py files correctly. yes

but nbdev_build_DOCS will have error NameError: name 'different_file_func' is not defined

from nbdev.

sgugger avatar sgugger commented on May 17, 2024

I need more than this as I can't reproduce what you are saying. Please share a whole folder with the numbered notebooks, exported library where the error appears.

from nbdev.

raynardj avatar raynardj commented on May 17, 2024

I added the following 2 files into a nbdev template repo

Then in this step, everything's okay 👌

$ nbdev_build_lib

Then in this step for docs, error ❌

$ nbdev_build_docs

converting: /Users/salvor/github/nbdev_test/00_core.ipynb
converting: /Users/salvor/github/nbdev_test/02test_nbdev.ipynb
converting: /Users/salvor/github/nbdev_test/index.ipynb
converting: /Users/salvor/github/nbdev_test/01_create_different.ipynb
An error occurred while executing the following cell:
------------------
show_doc(different_file_func, default_cls_level=2)
------------------

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-e86c8b69e1ff> in <module>
----> 1 show_doc(different_file_func, default_cls_level=2)

NameError: name 'different_file_func' is not defined
NameError: name 'different_file_func' is not defined

Traceback (most recent call last):
  File "/Users/salvor/anaconda3/bin/nbdev_build_docs", line 8, in <module>
    sys.exit(nbdev_build_docs())
  File "/Users/salvor/.local/lib/python3.7/site-packages/fastscript/core.py", line 73, in _f
    func(**args.__dict__)
  File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/cli.py", line 164, in nbdev_build_docs
    notebook2html(fname=fname, force_all=force_all, n_workers=n_workers)
  File "/Users/salvor/.local/lib/python3.7/site-packages/nbdev/export2html.py", line 412, in notebook2html
    raise Exception(msg + '\n'.join([f.name for p,f in zip(passed,files) if not p]))
Exception: Conversion failed on the following:
02test_nbdev.ipynb

from nbdev.

CEM3H avatar CEM3H commented on May 17, 2024

I encountered the same issue when trying to generate two (or more) .py files from single notebook - I thought it was a good idea to place function definitions and other code into different modules.
So even when I bypassed No such file or directory error (but its behavior is still unclear sometimes)

I noticed that modules created by # export <module> expression expand with each run of nbdev_build_lib which duplicates code and thus quickly makes these modules become messy if one runs nbdev_build_lib or notebook2script often (e.g. as a part of iterative process)

So I found that feature for cleaning lib_path might be useful as an argument for notebook2script to re-create all the modules along with _ndbev.py.

It also occured to me that a little more explicit behavior of creating modules might be useful - I believe it could be achieved by calling create_mod_file func inside _notebook2script when iterating over cells in case module in # export <module> still wasn't created during conversion.

from nbdev.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.