Skip to content
Closed
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
64 changes: 64 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,67 @@ jobs:
run: |
micromamba activate xeus-python
pytest . -vvv

test-wasm:

runs-on: ubuntu

strategy:
fail-fast: false
matrix:
emsdk_ver: ["3.1.2"]

steps:
- uses: actions/checkout@v2

- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v1

- name: Install mamba
uses: mamba-org/provision-with-micromamba@main

- name: Create micromamba wasm env
run: |
micromamba create -n xeus-python-wasm \
--platform=emscripten-32 --yes \
-c https://repo.mamba.pm/emscripten-forge \
-c https://repo.mamba.pm/conda-forge \
pip python ipython pybind11 jedi xtl nlohmann_json pybind11_json numpy xeus xeus-python-shell>=0.3.0

- name: Setup emsdk (TODO Install from conda-forge when available)
run: |
git clone https://github.com/emscripten-core/emsdk.git
pushd emsdk
./emsdk install ${{matrix.emsdk_ver}}
popd

- name: Install emboa (TODO Install from conda-forge when available)
run: |
micromamba activate xeus-python-wasm
pip install git+https://github.com/emscripten-forge/emboa

- name: Build and pack xeus-python
run: |
micromamba activate xeus-python-wasm

pushd emsdk
./emsdk activate ${{matrix.emsdk_ver}}
source emsdk_env.sh
export FILE_PACKAGER=$(cwd)/upstream/emscripten/tools/file_packager.py
popd

export CMAKE_PREFIX_PATH=$CONDA_PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$CONDA_PREFIX

emcmake cmake \
-DCMAKE_BUILD_TYPE=Release\
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCMAKE_PROJECT_INCLUDE=overwriteProp.cmake \
-DXPYT_EMSCRIPTEN_WASM_BUILD=ON \
..

make -j ${{ steps.cpu-cores.outputs.count }}

emboa pack python core $CONDA_PREFIX --version=3.10

# TODO Add test with node?
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Long story short:

| `xeus-python`| `xeus` | `xtl` | `cppzmq` | `nlohmann_json` | `pybind11` | `pybind11_json` | `pygments` | `debugpy` | `IPython` | `xeus-python-shell` |
|--------------|------------------|-----------------|----------|-----------------|----------------|-------------------|-------------------|-----------|-----------|---------------------|
| master | >=2.0.0,<3.0 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<3.10 | >=2.6.1,<3.0 | >=0.2.8,<0.3 | >=2.3.1,<3.0.0 | >=1.1.0 | | >=0.1.5,<0.3.0 |
| master | >=2.0.0,<3.0 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<3.10 | >=2.6.1,<3.0 | >=0.2.8,<0.3 | >=2.3.1,<3.0.0 | >=1.1.0 | | >=0.3.0,<0.4.0 |
| 0.13.7 | >=2.0.0,<3.0 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<3.10 | >=2.6.1,<3.0 | >=0.2.8,<0.3 | >=2.3.1,<3.0.0 | >=1.1.0 | | >=0.1.5,<0.3.0 |
| 0.13.6 | >=2.0.0,<3.0 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<3.10 | >=2.6.1,<3.0 | >=0.2.8,<0.3 | >=2.3.1,<3.0.0 | >=1.1.0 | | >=0.1.5,<0.3.0 |
| 0.13.5 | >=2.0.0,<3.0 | >=0.7.0,<0.8 | ~4.4.1 | >=3.6.1,<3.10 | >=2.6.1,<3.0 | >=0.2.8,<0.3 | >=2.3.1,<3.0.0 | >=1.1.0 | | >=0.1.5,<0.2.0 |
Expand Down
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
- xtl>=0.7, <0.8
- pybind11>=2.6.1,<3.0
- pybind11_json>=0.2.6,<0.3
- xeus-python-shell>=0.1.6,<0.3
- xeus-python-shell>=0.3.0,<0.4
- debugpy
# Test dependencies
- pytest
Expand Down
2 changes: 0 additions & 2 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <string>
#include <utility>
#include <vector>
#include <iostream>

#include "nlohmann/json.hpp"

Expand All @@ -41,7 +40,6 @@ namespace py = pybind11;
namespace nl = nlohmann;
using namespace pybind11::literals;


namespace xpyt
{

Expand Down
94 changes: 34 additions & 60 deletions src/xinterpreter_raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include <string>
#include <utility>
#include <vector>
#include <iostream>


#include "nlohmann/json.hpp"

Expand Down Expand Up @@ -49,15 +47,11 @@ namespace xpyt
raw_interpreter::raw_interpreter(bool redirect_output_enabled /*=true*/, bool redirect_display_enabled /*=true*/) :m_redirect_display_enabled{ redirect_display_enabled }

{
std::cout<<"in ctr\n";
xeus::register_interpreter(this);
std::cout<<"in ctr 2\n";
if (redirect_output_enabled)
{
std::cout<<"in ctr 2b\n";
redirect_output();
}
std::cout<<"in ctr 3\n";
}

raw_interpreter::~raw_interpreter()
Expand All @@ -66,68 +60,51 @@ namespace xpyt

void raw_interpreter::configure_impl()
{
try {

std::cout<<"Configure IMPL 1\n";
if (m_release_gil_at_startup)
{
std::cout<<"Configure IMPL 1a\n";
// The GIL is not held by default by the interpreter, so every time we need to execute Python code we
// will need to acquire the GIL
m_release_gil = gil_scoped_release_ptr(new py::gil_scoped_release());
}
if (m_release_gil_at_startup)
{
// The GIL is not held by default by the interpreter, so every time we need to execute Python code we
// will need to acquire the GIL
m_release_gil = gil_scoped_release_ptr(new py::gil_scoped_release());
}

std::cout<<"Configure IMPL 2\n";
py::gil_scoped_acquire acquire;
py::gil_scoped_acquire acquire;

std::cout<<"Configure IMPL 3\n";
py::module sys = py::module::import("sys");
std::cout<<"Configure IMPL 4\n";
py::module jedi = py::module::import("jedi");
std::cout<<"Configure IMPL 5\n";
jedi.attr("api").attr("environment").attr("get_default_environment") = py::cpp_function([jedi]() {
py::module sys = py::module::import("sys");
py::module jedi = py::module::import("jedi");
jedi.attr("api").attr("environment").attr("get_default_environment") = py::cpp_function([jedi]() {
jedi.attr("api").attr("environment").attr("SameEnvironment")();
});

py::module display_module = get_display_module(true);
m_displayhook = display_module.attr("DisplayHook")();

if (m_redirect_display_enabled)
{
sys.attr("displayhook") = m_displayhook;
}

// Expose display functions to Python
py::globals()["display"] = display_module.attr("display");
py::globals()["update_display"] = display_module.attr("update_display");
// Monkey patching "import IPython.core.display"
sys.attr("modules")["IPython.core.display"] = display_module;
});

py::module display_module = get_display_module(true);
m_displayhook = display_module.attr("DisplayHook")();

py::module kernel_module = get_kernel_module(true);
// Monkey patching "from ipykernel.comm import Comm"
sys.attr("modules")["ipykernel.comm"] = kernel_module;
if (m_redirect_display_enabled)
{
sys.attr("displayhook") = m_displayhook;
}

// Monkey patching "from IPython import get_ipython"
sys.attr("modules")["IPython.core.getipython"] = kernel_module;
// Expose display functions to Python
py::globals()["display"] = display_module.attr("display");
py::globals()["update_display"] = display_module.attr("update_display");
// Monkey patching "import IPython.core.display"
sys.attr("modules")["IPython.core.display"] = display_module;

// Add get_ipython to global namespace
py::globals()["get_ipython"] = kernel_module.attr("get_ipython");
kernel_module.attr("get_ipython")();
py::module kernel_module = get_kernel_module(true);
// Monkey patching "from ipykernel.comm import Comm"
sys.attr("modules")["ipykernel.comm"] = kernel_module;

py::globals()["_i"] = "";
py::globals()["_ii"] = "";
py::globals()["_iii"] = "";
// Monkey patching "from IPython import get_ipython"
sys.attr("modules")["IPython.core.getipython"] = kernel_module;

} catch (std::exception &e) {
std::cout<<"ewhat "<<e.what()<<"\n";

}
// Add get_ipython to global namespace
py::globals()["get_ipython"] = kernel_module.attr("get_ipython");
kernel_module.attr("get_ipython")();

py::globals()["_i"] = "";
py::globals()["_ii"] = "";
py::globals()["_iii"] = "";
}



nl::json raw_interpreter::execute_request_impl(
int execution_count,
const std::string& code,
Expand Down Expand Up @@ -194,7 +171,6 @@ namespace xpyt
}
catch (py::error_already_set& e)
{
std::cout<<"ewhat "<<e.what()<<"\n";
xerror error = extract_already_set_error(e);

if (error.m_ename == "SyntaxError")
Expand All @@ -215,9 +191,7 @@ namespace xpyt
kernel_res["evalue"] = error.m_evalue;
kernel_res["traceback"] = error.m_traceback;
}
catch(std::exception & e){
std::cout<<"exception.what "<<e.what()<<"\n";
}

// Cache inputs
py::globals()["_iii"] = py::globals()["_ii"];
py::globals()["_ii"] = py::globals()["_i"];
Expand Down