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

Use IPython #400

Merged
merged 1 commit into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install:
- conda update -q conda
- conda info -a
# Host dependencies
- conda install xeus=1.0.0 nlohmann_json cppzmq xtl jedi pybind11=2.6.0 pybind11_json=0.2.6 pygments gtest=1.8.0 debugpy ipython=7.14.0 -c conda-forge
- conda install xeus=1.0.0 nlohmann_json cppzmq xtl pybind11=2.6.0 pybind11_json=0.2.8 gtest=1.8.0 debugpy ipython=7.14.0 -c conda-forge
# Build dependencies
- conda install cmake -c conda-forge
# Build and install xeus-python
Expand All @@ -38,10 +38,9 @@ install:
- nmake install
# Install test dependencies
- conda install mamba -c conda-forge
- mamba install jupyter_kernel_test -c conda-forge
- pip install example_magic
- mamba install pytest nbval ipympl -c conda-forge

build_script:
- cd test
- test_xeus_python
- cd.. && cd.. && cd test && python test_xeus_python_kernel.py -vvv
- cd.. && cd.. && cd test && pytest . -vvv
3 changes: 1 addition & 2 deletions .azure-pipelines/unix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ steps:

- script: |
source activate xeus-python
pip install example_magic
mkdir build
cd build
if [[ $(xpyt_used_shared_xeus_python) == '0' ]]; then
Expand Down Expand Up @@ -49,6 +48,6 @@ steps:

- script: |
source activate xeus-python
python test_xeus_python_kernel.py -vvv
pytest . -vvv
displayName: Test xeus-python (Python)
workingDirectory: $(Build.sourcesDirectory)/test
18 changes: 5 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ OPTION(XPYT_DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)
set(xtl_REQUIRED_VERSION 0.6.23)
set(xeus_REQUIRED_VERSION 0.25.0)
set(pybind11_REQUIRED_VERSION 2.6.0)
set(pybind11_json_REQUIRED_VERSION 0.2.2)
set(pybind11_json_REQUIRED_VERSION 0.2.8)

if (NOT TARGET xtl)
find_package(xtl ${xtl_REQUIRED_VERSION} REQUIRED)
Expand Down Expand Up @@ -120,29 +120,21 @@ endif ()
# ============

set(XEUS_PYTHON_SRC
src/xcomm.cpp
src/xcomm.hpp
src/xcompiler.cpp
src/xcompiler.hpp
src/xdebugger.cpp
src/xdebugpy_client.hpp
src/xdebugpy_client.cpp
src/xdisplay.cpp
src/xdisplay.hpp
src/xinput.cpp
src/xinput.hpp
src/xinspect.cpp
src/xinspect.hpp
src/xinteractiveshell.cpp
src/xinteractiveshell.hpp
src/xinternal_utils.cpp
src/xinternal_utils.hpp
src/xinterpreter.cpp
src/xis_complete.cpp
src/xis_complete.hpp
src/xlinecache.cpp
src/xlinecache.hpp
src/xnullcontext.cpp
src/xnullcontext.hpp
src/xpaths.cpp
src/xpython_kernel.cpp
src/xpython_kernel.hpp
src/xstream.cpp
src/xstream.hpp
src/xtraceback.cpp
Expand Down
45 changes: 22 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The ongoing effort to package xeus-python for pip takes place in the [xeus-pytho
Or you can install it from the sources, you will first need to install dependencies

```bash
conda install cmake xeus nlohmann_json cppzmq xtl pybind11 pybind11_json jedi pygments notebook -c conda-forge
conda install cmake xeus nlohmann_json cppzmq xtl pybind11 pybind11_json ipython debugpy jupyterlab -c conda-forge
```

Then you can compile the sources
Expand All @@ -115,10 +115,9 @@ http://xeus-python.readthedocs.io

Check-out this blog post for the answer: https://blog.jupyter.org/a-new-python-kernel-for-jupyter-fcdf211e30a8.
Long story short:
xeus-python does not cover 100% of the features of ipykernel. For example, only some magics are supported for now (Matplotlib magics are not supported, but nothing prevents from using the Matplotlib API directly). However:

- xeus-python is a lot lighter than ipykernel and IPython combined, which makes it a lot easier to implement new features on top of it.
- as an example, xeus-python already works with the **Jupyter Lab debugger**: https://github.com/jupyterlab/debugger
- xeus-python is a lot lighter than ipykernel, which makes it a lot easier to implement new features on top of it.
- xeus-python already works with the **Jupyter Lab debugger**: https://github.com/jupyterlab/debugger
- xeus-based kernels are more versatile in that one can overload e.g. the concurrency model. This is something that Kitware’s SlicerJupyter project takes advantage of to integrate with the Qt event loop of their Qt-based desktop application.

## Dependencies
Expand All @@ -132,25 +131,25 @@ xeus-python does not cover 100% of the features of ipykernel. For example, only
- [nlohmann_json](https://github.com/nlohmann/json)


| `xeus-python`| `xeus` | `xtl` | `cppzmq` | `nlohmann_json` | `pybind11` | `pybind11_json` | `jedi` | `pygments` | `ptvsd` | `debugpy` |
|--------------|------------------|-----------------|----------|-----------------|----------------|-------------------|-------------------|-------------------|---------|-----------|
| master | >=1.0.0,<0.26 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.19 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.10.2 | >=1.0.0,<0.26 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.19 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.10.1 | >=1.0.0,<0.26 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.18.0,<0.19 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.10.0 | >=1.0.0,<0.26 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.18.0,<0.19 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.9.5 | >=0.25.3,<0.26 | >=0.6.23,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.18.0,<0.19 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.9.4 | >=0.25.3,<0.26 | >=0.6.23,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.18 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.9.3 | >=0.25.3,<0.26 | >=0.6.23,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.15.1 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.9.2 | >=0.25.3,<0.26 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.15.1 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.9.1 | >=0.25.0,<0.26 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.9.0 | >=0.25.0,<0.26 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.8.7 | >=0.24.2,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1 | >=2.3.1,<3.0.0 | | >=1.1.0 |
| 0.8.6 | >=0.24.2,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | |
| 0.8.5 | >=0.24.2,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | |
| 0.8.4 | >=0.24.1,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | |
| 0.8.3 | >=0.24.1,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | |
| 0.8.2 | >=0.24.1,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | |
| 0.8.1 | >=0.24.1,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | |
| `xeus-python`| `xeus` | `xtl` | `cppzmq` | `nlohmann_json` | `pybind11` | `pybind11_json` | `jedi` | `pygments` | `ptvsd` | `debugpy` | `IPython` |
|--------------|------------------|-----------------|----------|-----------------|----------------|-------------------|-------------------|-------------------|---------|-----------|-----------|
| master | >=1.0.0,<0.26 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.8,<0.3 | | | | >=1.1.0 | >=7.20,<8 |
| 0.10.2 | >=1.0.0,<0.26 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.19 | >=2.3.1,<3.0.0 | | >=1.1.0 | |
| 0.10.1 | >=1.0.0,<0.26 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.18.0,<0.19 | >=2.3.1,<3.0.0 | | >=1.1.0 | |
| 0.10.0 | >=1.0.0,<0.26 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.18.0,<0.19 | >=2.3.1,<3.0.0 | | >=1.1.0 | |
| 0.9.5 | >=0.25.3,<0.26 | >=0.6.23,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.18.0,<0.19 | >=2.3.1,<3.0.0 | | >=1.1.0 | |
| 0.9.4 | >=0.25.3,<0.26 | >=0.6.23,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.18 | >=2.3.1,<3.0.0 | | >=1.1.0 | |
| 0.9.3 | >=0.25.3,<0.26 | >=0.6.23,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.15.1 | >=2.3.1,<3.0.0 | | >=1.1.0 | |
| 0.9.2 | >=0.25.3,<0.26 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.6.0,<3.0 | >=0.2.6,<0.3 | >=0.15.1 | >=2.3.1,<3.0.0 | | >=1.1.0 | |
| 0.9.1 | >=0.25.0,<0.26 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1 | >=2.3.1,<3.0.0 | | >=1.1.0 | |
| 0.9.0 | >=0.25.0,<0.26 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1 | >=2.3.1,<3.0.0 | | >=1.1.0 | |
| 0.8.7 | >=0.24.2,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1 | >=2.3.1,<3.0.0 | | >=1.1.0 | |
| 0.8.6 | >=0.24.2,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | | |
| 0.8.5 | >=0.24.2,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | | |
| 0.8.4 | >=0.24.1,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | | |
| 0.8.3 | >=0.24.1,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | | |
| 0.8.2 | >=0.24.1,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | | |
| 0.8.1 | >=0.24.1,<0.25 | >=0.6.8,<0.7 | ~4.4.1 | >=3.6.1,<4.0 | >=2.2.4,<3.0 | >=0.2.6,<0.3 | >=0.15.1,<0.16.0 | >=2.3.1,<3.0.0 | >=4.3.2 | | |


## Contributing
Expand Down
13 changes: 7 additions & 6 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ name: xeus-python
channels:
- conda-forge
dependencies:
# Builde dependencies
# Build dependencies
- cmake
# Host dependencies
- xeus=1.0.0
- nlohmann_json
- cppzmq
- xtl=0.7.0
- jedi>=0.15.1,<0.19
- jedi>=0.15.1,<0.18
- pybind11=2.6.0
- pybind11_json=0.2.6
- pygments
- ipython=7.14.0
- pybind11_json>=0.2.6,<0.3
- ipython>=7.14.0,<8
- debugpy
# Test dependencies
- jupyter_kernel_test
- pytest
- nbval
- ipympl
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ dependencies:
- ipywidgets>=7.6
- jupyterlab=3
- itkwidgets
- matplotlib
- ipympl
6 changes: 3 additions & 3 deletions include/xeus-python/xinterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ namespace xpyt
nl::json internal_request_impl(const nl::json& content) override;

void redirect_output();
void redirect_display(bool install_hook=true);
void load_extensions();

py::object m_ipython_shell;
py::dict m_user_ns;
py::object m_displayhook;

// The interpreter has the same scope as a `gil_scoped_release` instance
Expand All @@ -92,7 +92,7 @@ namespace xpyt
bool m_release_gil_at_startup = true;
gil_scoped_release_ptr m_release_gil = nullptr;

bool m_has_ipython;
bool m_redirect_display_enabled;
};
}

Expand Down
7 changes: 6 additions & 1 deletion include/xeus-python/xtraceback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ namespace xpyt
std::vector<std::string> m_traceback;
};

XEUS_PYTHON_API py::module get_traceback_module();

XEUS_PYTHON_API void register_filename_mapping(const std::string& filename, int execution_count);

XEUS_PYTHON_API XPYT_FORCE_PYBIND11_EXPORT
xerror extract_error(py::error_already_set& error);

XEUS_PYTHON_API XPYT_FORCE_PYBIND11_EXPORT
xerror extract_error(const py::object& type, const py::object& value, const py::object& traceback);
}

#endif
2 changes: 1 addition & 1 deletion include/xeus-python/xutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace xpyt

XEUS_PYTHON_API XPYT_FORCE_PYBIND11_EXPORT
void exec(const py::object& code, const py::object& scope = py::globals());

XEUS_PYTHON_API XPYT_FORCE_PYBIND11_EXPORT
py::object eval(const py::object& code, const py::object& scope = py::globals());
}
Expand Down
4 changes: 2 additions & 2 deletions notebooks/xeus-magics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,15 @@
],
"metadata": {
"kernelspec": {
"display_name": "xpython",
"display_name": "Python 3.9 (XPython)",
"language": "python",
"name": "xpython"
},
"language_info": {
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.8.2"
"version": "3.9.1"
}
},
"nbformat": 4,
Expand Down
Loading