From 26af9dbbe008dc32703fa942398eb0b1056098d5 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 27 Jun 2024 12:21:56 +0530 Subject: [PATCH] Update to xeus 5 --- CMakeLists.txt | 30 +++++++++++++++++------------- ci/azure_install_macos.sh | 2 +- ci/environment.yml | 7 +++---- doc/src/installation.md | 32 ++++++++++++++++++++++++++++++++ environment_unix.yml | 7 +++++++ environment_win.yml | 8 +++++++- 6 files changed, 67 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e1e2ea0b9..b5bcb622e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,13 +23,16 @@ if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR message(FATAL_ERROR "CMAKE_BUILD_TYPE must be one of: Debug, Release (current value: '${CMAKE_BUILD_TYPE}')") endif () -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(LPYTHON_CXX_NO_RTTI_FLAG "-fno-rtti") -elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) - set(LPYTHON_CXX_NO_RTTI_FLAG "-fno-rtti") -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(LPYTHON_CXX_NO_RTTI_FLAG "/GR-") -endif () +# xeus does use `dynamic_cast` and thus needs rtti (otherwise it segfaults) +if (NOT WITH_XEUS) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(LPYTHON_CXX_NO_RTTI_FLAG "-fno-rtti") + elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) + set(LPYTHON_CXX_NO_RTTI_FLAG "-fno-rtti") + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(LPYTHON_CXX_NO_RTTI_FLAG "/GR-") + endif () +endif(NOT WITH_XEUS) # For CMAKE_INSTALL_BINDIR: @@ -205,19 +208,20 @@ if (WITH_LLVM) set(HAVE_LFORTRAN_LLVM yes) endif() -# XEUS (Fortran kernel) +# XEUS (Python kernel) set(WITH_XEUS no CACHE BOOL "Build with XEUS support") if (WITH_XEUS) - find_package(xeus 0.24.1 REQUIRED) - set(HAVE_LFORTRAN_XEUS yes) + find_package(xeus 5.1.0 REQUIRED) + find_package(xeus-zmq 3.0.0 REQUIRED) + set(HAVE_LPYTHON_XEUS yes) # Generate kernel.json with correct paths configure_file ( - "${CMAKE_CURRENT_SOURCE_DIR}/share/jupyter/kernels/fortran/kernel.json.in" - "${CMAKE_CURRENT_BINARY_DIR}/share/jupyter/kernels/fortran/kernel.json" + "${CMAKE_CURRENT_SOURCE_DIR}/share/jupyter/kernels/python/kernel.json.in" + "${CMAKE_CURRENT_BINARY_DIR}/share/jupyter/kernels/python/kernel.json" ) - # Configuration and data directories for Jupyter and LFortran + # Configuration and data directories for Jupyter and LPython set(XJUPYTER_DATA_DIR "share/jupyter" CACHE STRING "Jupyter data directory") # Install Jupyter kernelspecs diff --git a/ci/azure_install_macos.sh b/ci/azure_install_macos.sh index 5012f14ae7..0f4af45658 100755 --- a/ci/azure_install_macos.sh +++ b/ci/azure_install_macos.sh @@ -5,7 +5,7 @@ set -ex conda config --set always_yes yes --set changeps1 no conda info -a conda update -q conda -conda install -c conda-forge python=3.8 re2c bison=3.4 m4 xonsh llvmdev=11.0.1 toml cmake=3.17.0 jupyter pytest xeus=1.0.1 xtl nlohmann_json cppzmq jupyter_kernel_test +conda install -c conda-forge python=3.8 re2c bison=3.4 m4 xonsh=0.16.0 llvmdev=11.0.1 toml cmake=3.17.0 jupyter pytest xeus=5.1.0 xeus-zmq=3.0.0 nlohmann_json=3.11.3 jupyter_kernel_test export MACOSX_DEPLOYMENT_TARGET="10.12" export CONDA_PREFIX=/usr/local/miniconda export LFORTRAN_CMAKE_GENERATOR="Unix Makefiles" diff --git a/ci/environment.yml b/ci/environment.yml index b9b7fd715f..68c535078c 100644 --- a/ci/environment.yml +++ b/ci/environment.yml @@ -7,10 +7,9 @@ dependencies: - toml - pytest - jupyter - - xeus=1.0.1 - - xtl - - nlohmann_json - - cppzmq + - xeus=5.1.0 + - xeus-zmq=3.0.0 + - nlohmann_json=3.11.3 - jupyter_kernel_test - xonsh - re2c diff --git a/doc/src/installation.md b/doc/src/installation.md index bc02241cab..38916e2592 100644 --- a/doc/src/installation.md +++ b/doc/src/installation.md @@ -185,6 +185,38 @@ You can run the following examples manually in a terminal: ./src/bin/lpython --show-c examples/expr2.py ``` +## Enabling the Jupyter Kernel + +To install the Jupyter kernel, install the following Conda packages also: +``` +conda install xeus=5.1.0 xeus-zmq=3.0.0 nlohmann_json +``` +and enable the kernel by `-DWITH_XEUS=yes` and install into `$CONDA_PREFIX`. For +example: +``` +cmake \ + -DCMAKE_BUILD_TYPE=Debug \ + -DWITH_LLVM=yes \ + -DWITH_XEUS=yes \ + -DCMAKE_PREFIX_PATH="$CONDA_PREFIX" \ + -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX" \ + . +cmake --build . -j4 --target install +``` +To use it, install Jupyter (`conda install jupyter`) and test that the LPython +kernel was found: +``` +jupyter kernelspec list --json +``` +Then launch a Jupyter notebook as follows: +``` +jupyter notebook +``` +Click `New->Python`. To launch a terminal jupyter LPython console: +``` +jupyter console --kernel=python +``` + ## Found a bug? Please report any bugs you find at our issue tracker [here](https://github.com/lcompilers/lpython/issues). Or, even better, fork the repository on GitHub and create a Pull Request (PR). diff --git a/environment_unix.yml b/environment_unix.yml index af7dffcff0..2a4f5b845c 100644 --- a/environment_unix.yml +++ b/environment_unix.yml @@ -7,6 +7,13 @@ dependencies: - make - re2c - toml + - pytest + - jupyter + - xeus=5.1.0 + - xeus-zmq=3.0.0 + - nlohmann_json=3.11.3 + - jupyter_kernel_test + - xonsh=0.16.0 - zlib - cmake - numpy diff --git a/environment_win.yml b/environment_win.yml index 60774b822c..b06852c23a 100644 --- a/environment_win.yml +++ b/environment_win.yml @@ -7,11 +7,17 @@ dependencies: - make - re2c - toml + - pytest + - jupyter + - xeus=5.1.0 + - xeus-zmq=3.0.0 + - nlohmann_json=3.11.3 + - jupyter_kernel_test - zlib - cmake - ninja - numpy - - xonsh + - xonsh=0.16.0 - flake8 - setuptools - python=3.10.2