-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
support ipynb ipython parser for magic and system #88
base: main
Are you sure you want to change the base?
Changes from 6 commits
6239181
c951b89
d3c0ffb
a07d6b9
08c5fd8
73c1ac6
83c9069
8e1dc0b
0a58cfe
568365a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,18 @@ | |||||
from .helpers import parse_git_config, trim_suffix | ||||||
|
||||||
import nbformat | ||||||
try: | ||||||
import IPython | ||||||
# untested | ||||||
# only support IPython >= 6.0.0 | ||||||
_transformer_manager = IPython.core.inputtransformer2.TransformerManager() | ||||||
|
||||||
# future: support IPython LTS 5.0.0 used by Google Colab | ||||||
# _transformer_manager = ... | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It means that the current transformer (parser) only supports IPython > 6, and someone needs to add functionality to support IPython 5 LTS that is used by Google Colab. I don't have IPython 5 LTS to test it and I don't use it anyway. So, Installing all the dependecy from scratch and make virtual environment is too much hassle (furthermore, I can't run your unittest). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of them seems to be an issue to me, also to you. You can run the tests like that: Lines 10 to 11 in 823a3c2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using IPython 7.0: ======================================================================
FAIL: test_py3_requirements (pigar.tests.test_core.ReqsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "P:\GitHub\pigar\pigar\tests\test_core.py", line 64, in test_py3_requirements
self.assertListEqual(sorted(guess.keys()), ['foobar'])
AssertionError: Lists differ: ['foobar', 'subbar', 'subfoo'] != ['foobar']
First list contains 2 additional elements.
First extra element 1:
'subbar'
- ['foobar', 'subbar', 'subfoo']
+ ['foobar']
---------------------------------------------------------------------- There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, for IPython 5.0 LTS: transformer I haven't figured out how to use it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I asked stackoverflow, :) |
||||||
except Exception: | ||||||
import warnings | ||||||
_transformer_manager = None | ||||||
|
||||||
Module = collections.namedtuple('Module', ['name', 'try_', 'file', 'lineno']) | ||||||
|
||||||
|
@@ -61,7 +73,16 @@ def _read_code(fpath): | |||||
code = "" | ||||||
for cell in nb.cells: | ||||||
if cell.cell_type == "code": | ||||||
code += cell.source + "\n" | ||||||
if _transformer_manager: | ||||||
code += _transformer_manager.transform_cell(cell.source) \ | ||||||
+ "\n" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the problem is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
else: | ||||||
# allow without !magic and !system support | ||||||
warning_msg = """No IPython >= 6.0.0 | ||||||
Not using IPython to parse notebooks | ||||||
""" | ||||||
warnings.warn(warning_msg, Warning) | ||||||
code += cell.source + "\n" | ||||||
yasirroni marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return code | ||||||
elif fpath.endswith(".py"): | ||||||
with open(fpath, 'rb') as f: | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPython
should be present insetup.py
,There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, for the parser to works (my version), it requires IPython >= 6, whereas in colab, it's IPython 5. The problem, both versions have different Transformer API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove IPython from the
setup.py
because it's not the core for pigar. It's just forpigar
onIPython
. If you want to make all support forIPython
, that's good, but sadly I can't help because I can't run the test (can't debug your codes, i don't know why).