change comment flags to magic flags#18
Conversation
|
Check out this pull request on Review Jupyter notebook visual diffs & provide feedback on notebooks. Powered by ReviewNB |
|
@jph00 - please take a look when you get a minute |
|
Thanks for the at-mention - sorry I didn't notice it before (and do feel free to mention me, since I don't always notice otherwise). I'd rather leave comments instead of magic flags in the template. They're a bit easier to handle (i.e no need to import anything, no issues in colab, etc) |
|
@jph00 - if we don't update this template, would you like me to revert changes to the tutorial - which was updated on the assumption that "comment flags" would be deprecated - but before you say yes ... Maybe this approach to working in colab might convince you that magic flags could be the preferred option? I've put a little more detail in this forum discussion |
|
@pete88b Personally I've found the flags awkward to use, and I haven't noticed any particular improvements for my particular workflow. I really tried to use them for a couple of months but in the end I just wasn't seeing benefits, and was seeing problems. What's your thinking behind why they could be the preferred option in Colab? |
|
@jph00 until now, I thought that magics would be the preferred option everywhere - Sylvain and I had a plan to update fastai2 etc - so here are my thoughts on the benefits:
For me, the only downside is:
I hear that you don't want to import nbdev just to get magic flags but ... this is fine for me - i always want Can you share other downsides and problems you've seen? i'm totally open to the idea that magics don't work that well - but i'd love to be able to find ways to improve everyone's nbdev/fastpages workflow and experience |
|
I think there are pros and cons, and all the things you mention certainly make sense. For me, the issue really is that magics add an additional layer of complexity, and you can't even run a cell that contains them unless you've first imported a module. But they don't change the behavior of running a cell, so that's an unnecessary burden on the user IMO.
It's also an extra concept the users have to learn - everyone already knows about comments, but people that's aren't too familiar with Jupyter won't know about magics, and the `%` thing is something they'll need to learn about.
I had to revert the magic flags functionality because it was causing various build errors. In general, we need to be very careful of using `eval` - in fact we really should avoid it if at all possible! And we should also be very careful of running code directly in a module, other than defining functions and classes in the usual way. Having eval in code executed at imported is rather problematic, and I got so many confusing bugs I had to work around that I eventually decided I better just remove it! I think it should become just an `nbdev_flag` magic that takes an argument, where the argument is the name of the flag, if that's possible.
I do agree that comments should not accidentally become flags! I suspect a good compromise here is to require the prefix `flag_` on all comment flags. Does that sound reasonable to you?
|
|
Morning @jph00 I need a little time to think about changes to magics/comments but having just seen the bits you commented, I think the real problem you saw was that both building docs The recently added Code complete for test flags is one of the best bits of magic flags for me - and I'm as sure as I can be that this code is solid. Here's the kind of error I think you were seeing: |
|
The recently added `_re_notebook2script` check fixes this in both 03_export2html.ipynb and 04_test.ipynb.
Code complete for test flags is one of the best bits of magic flags for me - and I'm as sure as I can be that this code is solid.
I realize that this is a big ask but ... can I undo the changes to `__init.py__` and `flags.py` to see if the `_re_notebook2script` check fixes your issues?
Can you re-write it to patch the module directly, rather than using `eval`?
|
|
@jph00 done AnswerDotAI/nbdev#232 please let me know if you see any problems or have any test scenarios you need me to run through. |
if you're happy with these changes i'll create an equivalent PR against https://gitlab.com/thomas.capelle/nbdev_template/