-
-
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?
Conversation
Hello @yasirroni! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-02-21 09:18:18 UTC |
I don't understand what is making the error in the test. Need feedback from author. |
👍 Thanks for the contribution! |
pigar/parser.py
Outdated
transformer = IPython.core.inputtransformer2.TransformerManager() | ||
for cell in nb.cells: | ||
if cell.cell_type == "code": | ||
code += transformer.transform_cell(cell.source) + "\n" |
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.
Tests failed maybe because the transform_cell
transformed the original code, such as adding empty lines.
pigar/parser.py
Outdated
PYTHON_VERSION_3 = True | ||
import IPython | ||
else: | ||
PYTHON_VERSION_3 = False |
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.
What happens if Python 4.x gets released?
I think this is better:
try:
import IPython
_transformer_manager = IPython.core.inputtransformer2.TransformerManager()
except Exception: # ???
_transformer_manager = None
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.
Should I remove the comment? I don't have any idea for the comment nor the Exeption
class.
except Exception:
I escape the Would you like to add a test and let me know the |
You know better what you are doing and I don't know how to write such a test for you, but I will try my best to help you. So how did the |
I don't know about that either. It's just what IPython use to transform
%magic and !system into something like `Ipython.magic()`, so that it can be
passed to Python parser. So yeah, it change the original code if it
contains IPython syntax (%, !, ?, $). I think your test need to be edited,
because your test making sure no code changing (i think).
…On Fri, 19 Feb 2021, 10:09 Xiaochao Dong, ***@***.***> wrote:
You know better what you are doing and I don't know how to write such a
test for you, but I will try my best to help you.
So how did the transform_cell transformed the original code?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#88 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALTUAKDKNIJUWHMEWHOQP4LS7XI67ANCNFSM4XQA6TNQ>
.
|
I will look into details.. 😫 |
pigar/parser.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem is the + "\n"
, could you remove it and run the test to see what happens?
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.
done
I run test with So yeah, I can't run your |
pigar/parser.py
Outdated
import IPython | ||
# untested | ||
# only support IPython >= 6.0.0 | ||
_transformer_manager = IPython.core.inputtransformer2.TransformerManager() |
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 in setup.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 for pigar
on IPython
. If you want to make all support for IPython
, 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).
|
||
# 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 comment
The 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 comment
The 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 comment
The 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
run-tests: | |
python -m unittest discover pigar/tests/ -t . -v |
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I asked stackoverflow, :)
I design this version to:
Because there is exist the third option, a sub-test for IPython needs to be implemented. Your test cli must support if there is exist an IPython and not. Or should we make IPython as a requirements? |
Maybe we can try this: https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#optional-dependencies, if I understand right so that users can do something like this:
For now, I think you should put more details in the comment, such as |
Can you help me to solve this and write a test (also update the PyCl test). |
All tests passed on GitHub CI. |
To be honest, it's not passed. It's skipped (or evaded), because your test cli doesn't install IPython (which will evade my PR, and use the default non-IPython reader/transformer). |
The failed test you posted here isn't related to IPython, you can run the tests in the master branch to see what happens. I have forgotten the reason. BTW, you should make the CI to use IPython if you make it as an optional requirement. |
It's related to IPython, in my case, as far as I know. If I run test
without IPython, it works fine.
Nah, am not understand CI at all. Haven't learnt about that. If you can't
help me write the test, I think we can put a hold on this PR.
Wait someone who want to pick this up or wait till I learnt about CI and
how you wrote your test.
Sadly, I'm not familiar with your test workflow.
…On Sun, 21 Feb 2021, 19:07 Xiaochao Dong, ***@***.***> wrote:
The failed test you posted here isn't related to IPython, you can run the
tests in the master branch to see what happens. I have forgotten the reason.
BTW, you should make the CI to use IPython if you make it as an optional
requirements.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#88 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALTUAKHSMMOIWCYHHDFOKBLTADZRDANCNFSM4XQA6TNQ>
.
|
Anyway, thanks again. |
If you want to merge it to the master, that's good. The point is, it works
flawlessly on my case, reading all my import in notebooks. I just don't
understand your test and what makes my code not passing your test.
but yeah, sadly, it doesn't work on google colab because of ipython 5 issue.
Thank you for the experience.
…On Sun, 21 Feb 2021, 20:31 Xiaochao Dong, ***@***.***> wrote:
Anyway, thanks again. I am tired too.
IMO, It is never about the tests or the ugly code, there is never an easy
way to make things better.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#88 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALTUAKEKW3DGB22NXFNFY43TAEDJ7ANCNFSM4XQA6TNQ>
.
|
Indeed, this project also lack of some documentations to help people to contribute, but this is also the part which people can contribute.. and I think that is what makes open-source great, and there are many things to be done, maintainers is not prefect as well. And yes, I will not write every piece of code for contributors since that is.. I do not know how to describe it.. maybe insane.. As for this PR..
|
After I disable IPython, running
It means that the error of the test is not from my modification? And why the local test fail but CI not fail? *really confused Anyway, |
Two cases:
You can start from here: https://github.com/damnever/pigar/blob/master/pigar/tests/test_core.py Here we parse those files in test cases, and parse_packages can take an arguments to ignore directories, so you can put a |
Now, we are using regex to exclude magics and shell commands: #117 However, I think the approach in this PR is more elegant.. |
Solve #87