Skip to content

Commit

Permalink
Restructure repo
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed May 10, 2022
1 parent cd9505e commit 5976be1
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 80 deletions.
52 changes: 31 additions & 21 deletions .github/workflows/main.yml
Expand Up @@ -133,7 +133,7 @@ jobs:
test-wasm:

runs-on: ubuntu
runs-on: ubuntu-latest

strategy:
fail-fast: false
Expand All @@ -148,14 +148,10 @@ jobs:

- 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
with:
environment-file: environment-dev-wasm.yml
environment-name: xeus-python-wasm
micromamba-version: "0.22.0"

- name: Setup emsdk (TODO Install from conda-forge when available)
run: |
Expand All @@ -176,21 +172,35 @@ jobs:
pushd emsdk
./emsdk activate ${{matrix.emsdk_ver}}
source emsdk_env.sh
export FILE_PACKAGER=$(cwd)/upstream/emscripten/tools/file_packager.py
export FILE_PACKAGER=$(pwd)/upstream/emscripten/tools/file_packager.py
popd
export CMAKE_PREFIX_PATH=$CONDA_PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$CONDA_PREFIX
micromamba create -n xeus-python-build-wasm \
--platform=emscripten-32 \
-c https://repo.mamba.pm/emscripten-forge \
-c https://repo.mamba.pm/conda-forge \
--yes \
python ipython pybind11 jedi xtl nlohmann_json pybind11_json numpy xeus "xeus-python-shell>=0.3"
mkdir build
pushd build
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-python-build-wasm
export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
emcmake cmake \
-DCMAKE_BUILD_TYPE=Release\
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCMAKE_PROJECT_INCLUDE=overwriteProp.cmake \
-DXPYT_EMSCRIPTEN_WASM_BUILD=ON \
..
emcmake cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCMAKE_PROJECT_INCLUDE=cmake/overwriteProp.cmake \
-DXPYT_EMSCRIPTEN_WASM_BUILD=ON \
..
make -j ${{ steps.cpu-cores.outputs.count }}
make -j5
emboa pack python core $CONDA_PREFIX --version=3.10
emboa pack python core $MAMBA_ROOT_PREFIX/envs/xeus-python-build-wasm --version=3.10
popd
# TODO Add test with node?
# Patch output
python wasm_patches/patch_it.py
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -51,3 +51,6 @@ build/

# Jupyter artefacts
.ipynb_checkpoints/

# JS artifacts
node_modules/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -74,7 +74,7 @@ OPTION(XPYT_BUILD_TESTS "xeus-python test suite" OFF)
OPTION(XPYT_DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)

if(XPYT_EMSCRIPTEN_WASM_BUILD)
configure_file(post.js ${CMAKE_CURRENT_BINARY_DIR}/post.js COPYONLY)
configure_file(wasm_patches/post.js ${CMAKE_CURRENT_BINARY_DIR}/post.js COPYONLY)

add_compile_definitions(XPYT_EMSCRIPTEN_WASM_BUILD)

Expand Down
39 changes: 0 additions & 39 deletions build_all.sh

This file was deleted.

File renamed without changes.
9 changes: 9 additions & 0 deletions environment-dev-wasm.yml
@@ -0,0 +1,9 @@
name: xeus-python-wasm
channels:
- conda-forge
dependencies:
- cmake
- pip
- python=3.10
- yarn
- click
6 changes: 5 additions & 1 deletion include/xeus-python/xinterpreter.hpp
Expand Up @@ -73,7 +73,6 @@ namespace xpyt
nl::json internal_request_impl(const nl::json& content) override;

void redirect_output();
void instanciate_ipython_shell();

py::object m_ipython_shell_app;
py::object m_ipython_shell;
Expand All @@ -95,7 +94,12 @@ namespace xpyt
bool m_release_gil_at_startup = true;
gil_scoped_release_ptr m_release_gil = nullptr;

bool m_redirect_output_enabled;
bool m_redirect_display_enabled;

private:

virtual void instanciate_ipython_shell();
};
}

Expand Down
4 changes: 1 addition & 3 deletions include/xeus-python/xinterpreter_wasm.hpp
Expand Up @@ -28,14 +28,12 @@ namespace xpyt
{
public:

using gil_scoped_release_ptr = std::unique_ptr<py::gil_scoped_release>;

wasm_interpreter();
virtual ~wasm_interpreter();

protected:

void instanciate_ipython_shell();
void instanciate_ipython_shell() override;

py::scoped_interpreter m_interpreter;
};
Expand Down
10 changes: 0 additions & 10 deletions patch_it.py

This file was deleted.

11 changes: 6 additions & 5 deletions src/xinterpreter.cpp
Expand Up @@ -44,13 +44,9 @@ namespace xpyt
{

interpreter::interpreter(bool redirect_output_enabled /*=true*/, bool redirect_display_enabled /*=true*/)
: m_redirect_display_enabled{redirect_display_enabled}
: m_redirect_output_enabled{redirect_output_enabled}, m_redirect_display_enabled{redirect_display_enabled}
{
xeus::register_interpreter(this);
if (redirect_output_enabled)
{
redirect_output();
}
}

interpreter::~interpreter()
Expand Down Expand Up @@ -106,6 +102,11 @@ namespace xpyt
// Initializing the compiler
m_ipython_shell.attr("compile").attr("filename_mapper") = traceback_module.attr("register_filename_mapping");
m_ipython_shell.attr("compile").attr("get_filename") = traceback_module.attr("get_filename");

if (m_redirect_output_enabled)
{
redirect_output();
}
}

nl::json interpreter::execute_request_impl(int /*execution_count*/,
Expand Down
9 changes: 9 additions & 0 deletions wasm_patches/patch_it.py
@@ -0,0 +1,9 @@
with open('./build/xpython_wasm.js', 'r') as f:
content = f.read()


query = 'Module["preloadPlugins"].push(audioPlugin);'
content = content.replace(query, '')

with open('./build/xpython_wasm.js', 'w') as f:
f.write(content)
File renamed without changes.

0 comments on commit 5976be1

Please sign in to comment.