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

support ipynb ipython parser for magic and system #88

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

yasirroni
Copy link

Solve #87

@pep8speaks
Copy link

pep8speaks commented Feb 12, 2021

Hello @yasirroni! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 22:80: E501 line too long (82 > 79 characters)

Comment last updated at 2021-02-21 09:18:18 UTC

@yasirroni
Copy link
Author

I don't understand what is making the error in the test.

Need feedback from author.

@damnever
Copy link
Owner

👍 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"
Copy link
Owner

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
Copy link
Owner

@damnever damnever Feb 18, 2021

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

Copy link
Author

@yasirroni yasirroni Feb 18, 2021

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: 

pigar/parser.py Show resolved Hide resolved
@yasirroni
Copy link
Author

I escape the test. Need to add IPython >= 6.0.0 test. The relative import of your test file throws an error in my VSCode. I don't want to go to the bottom of the problem of the test for now. It just works in my machine (the IPython 7.0.0 transformer), I'm satisfied. :)

Would you like to add a test and let me know the diff of using IPython transformer before using Python parser and not using IPython transformer?

@damnever
Copy link
Owner

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?

@yasirroni
Copy link
Author

yasirroni commented Feb 19, 2021 via email

@damnever
Copy link
Owner

I will look into details.. 😫

pigar/parser.py Outdated
code += cell.source + "\n"
if _transformer_manager:
code += _transformer_manager.transform_cell(cell.source) \
+ "\n"
Copy link
Owner

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?

Ref:
https://github.com/ipython/ipython/blob/86d24741188b0cedd78ab080d498e775ed0e5272/IPython/core/inputtransformer2.py#L588-L597

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@yasirroni
Copy link
Author

yasirroni commented Feb 19, 2021

I run test with python -m unittest discover -s tests, what is that with pyppeteer and syncer?

So yeah, I can't run your unittest in my machine.

pigar/parser.py Outdated
import IPython
# untested
# only support IPython >= 6.0.0
_transformer_manager = IPython.core.inputtransformer2.TransformerManager()
Copy link
Owner

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,

Copy link
Author

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.

Copy link
Author

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 = ...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?

Copy link
Author

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).

Copy link
Owner

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:

pigar/makefile

Lines 10 to 11 in 823a3c2

run-tests:
python -m unittest discover pigar/tests/ -t . -v

Copy link
Author

@yasirroni yasirroni Feb 20, 2021

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']

----------------------------------------------------------------------

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yasirroni
Copy link
Author

I design this version to:

  1. Allow the use of IPython >= 7
  2. Allow the use of IPython 5.x LTS and IPython 6.x (still not implemented, because I don't understand the doc).
  3. Without IPython (or we should not support this)?

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?

@damnever damnever linked an issue Feb 21, 2021 that may be closed by this pull request
@damnever
Copy link
Owner

Without IPython (or we should not support this)?

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: pip install pigar[extra-dep]

Allow the use of IPython 5.x LTS and IPython 6.x (still not implemented, because I don't understand the doc).

For now, I think you should put more details in the comment, such as TODO(username): xxx

@yasirroni
Copy link
Author

Can you help me to solve this and write a test (also update the PyCl test).

#88 (comment)

@damnever
Copy link
Owner

All tests passed on GitHub CI.

@yasirroni
Copy link
Author

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).

@damnever
Copy link
Owner

damnever commented Feb 21, 2021

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.

@yasirroni
Copy link
Author

yasirroni commented Feb 21, 2021 via email

@damnever
Copy link
Owner

damnever commented Feb 21, 2021

Anyway, thanks again.

@yasirroni
Copy link
Author

yasirroni commented Feb 21, 2021 via email

@damnever
Copy link
Owner

damnever commented Feb 21, 2021

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..

  1. I think there is a misunderstanding for the "IPython5?" part:

    Allow the use of IPython 5.x LTS and IPython 6.x (still not implemented, because I don't understand the doc).

    For now, I think you should put more details in the comment, such as TODO(username): xxx

    but yeah, sadly, it doesn't work on google colab because of ipython 5 issue.

    We can ignore it for now, but for the people who are running into the same problem or interested in this, we should let them know why and where to find more contexts.

  2. The workflow is just GitHub Actions, I do not know which part you do not understand exactly, I understand that you want to get it done, but that is never ok to me because I am maintaining this project, at least for now (not a good maintainer as well), and the tests is so important so that others won't break things.

@yasirroni
Copy link
Author

yasirroni commented Feb 24, 2021

After I disable IPython, running python -m unittest discover pigar/tests/ -t . -v also retrunt error

ine 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']

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,
If you want me to add test for IPython transformer, I don't know what should be tested? What is considered as failure? If Python ast.parse can't read it?

@damnever
Copy link
Owner

Two cases:

  1. IPython available: .ipynb file with magic marks should pass the test case
  2. IPython not available: ignore the .ipynb file with magic marks and skip case 1

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 .ipynb file with magic marks under some directory, skip test cases and ignore directory by condition.

@damnever
Copy link
Owner

damnever commented Nov 7, 2022

Now, we are using regex to exclude magics and shell commands: #117

However, I think the approach in this PR is more elegant..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IPython % magic and ! exclamation mark throws error
3 participants