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

Add python-jl CLI #200

Merged
merged 17 commits into from
Oct 24, 2018
Merged

Add python-jl CLI #200

merged 17 commits into from
Oct 24, 2018

Conversation

tkf
Copy link
Member

@tkf tkf commented Sep 13, 2018

This PR adds a CLI python-jl which acts like python CLI but executed as a julia process. This way, PyCall can use normal precompilation cache so that PyJulia can be used with Python installed in Debian/Ubuntu and conda #185.

The users just have to use python-jl script.py instead of python script.py.

(previously: JuliaPy/PyCall.jl#562)

@coveralls
Copy link

coveralls commented Sep 13, 2018

Pull Request Test Coverage Report for Build 506

  • 157 of 218 (72.02%) changed or added relevant lines in 3 files are covered.
  • 7 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.7%) to 74.599%

Changes Missing Coverage Covered Lines Changed/Added Lines %
julia/core.py 1 3 33.33%
julia/python_jl.py 23 32 71.88%
julia/pseudo_python_cli.py 133 183 72.68%
Files with Coverage Reduction New Missed Lines %
julia/find_libpython.py 2 73.42%
julia/core.py 5 80.82%
Totals Coverage Status
Change from base Build 505: -0.7%
Covered Lines: 605
Relevant Lines: 811

💛 - Coveralls

@tkf
Copy link
Member Author

tkf commented Sep 13, 2018

In Windows, Launching python-jl fails due to ERROR: syntax: incomplete: premature end of input:

https://ci.appveyor.com/project/Keno/pyjulia/build/1.0.203/job/kgic6eicchk4chx7#L776

Replacing \n with \r\n 7c395e3 (appveyor) and \n with ; 0a61076 (appveyor) didn't help.

Can we not support python-jl in Windows? In Windows Python is dynamically linked so no one has to use python-jl anyway.

@tkf
Copy link
Member Author

tkf commented Sep 15, 2018

There is a bit of limitation in argparse (and optparse) for mimicking the behavior of python CLI. Namely, it's hard to tell the parser to stop parsing (even with argparse.REMAINDER and parse_known_args). I tried to do a simple workaround by pre-processing the arguments 4bcf109 but it didn't work in all the cases. So I gave up and cooked up a small CLI parser. Now it works identical to python CLI for all the cases I've tried.

Interestingly, python-jl can now be used to launch IPython kernel (to be used from Jupyter notebook/qtconsole/console). You only need to make (say) ~/.local/share/jupyter/kernels/python-jl/kernel.json with:

{
  "argv": [
    "/PATH/TO/bin/python-jl",
    "-m",
    "ipykernel_launcher",
    "-f",
    "{connection_file}"
  ],
  "display_name": "Python.jl",
  "language": "python"
}

Note that all I needed to do was to replace python in normal kernel.json generated by python -m ipykernel install --user --name python-jl --display-name "Python.jl" with python-jl.

Everything should work almost like normal IPython kernel. The only way to know that you are in Julia process is to do something like:

import os
!ps -f {os.getpid()}

which should show julia -e ....

@@ -650,6 +657,10 @@ def __init__(self, init_julia=True, jl_init_path=None, runtime=None,
self.sprint = self.eval('sprint')
self.showerror = self.eval('showerror')

if self.eval('VERSION >= v"0.7-"'):
self.eval("@eval Main import Base.MainInclude: eval, include")
# https://github.com/JuliaLang/julia/issues/28825
Copy link
Member Author

Choose a reason for hiding this comment

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

This should fix #202. The reason why it's in this PR is that this fix depends on b908e6b.

@tkf tkf merged commit 90aec01 into JuliaPy:master Oct 24, 2018
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.

2 participants