Skip to main content

IPython kernel forwarding C++ cells to clang-repl

Project description

clang-repl based kernel for Jupyter notebooks

Usage/details

  • It is required that clang-repl is installed on the (backend) system
  • On launch, the kernel starts an interactive clang-repl session. The default settings and initial includes/libs can be configured by placing a .clang-repl file in the users home directory (example).
  • The kernel performs the following steps for each source cell
    1. Inspect first line of the cell if starting with these magic commands
      • %status: print kernel status
      • %lib: forward first line of cell directly to clang-repl
    2. Comment the first line (by prepending //) if it starts with %
    3. Transform the cell content if the first line contains a %main: the cell content is wrapped and run via a unique global function, e.g. void mainUUID(){ ... }; mainUUID();
    4. The (transformed) cell content is forwarded to clang-repl by always using a single line command realized via a indirection of, e.g. this form: #include /tmp/cell-e3tp24ne.repl
    5. The result of the interactive session (i.e. incremental compile + execute) is awaited (using a timeout) and printed as output of the cell.
    6. If the cell additionally contained a %undo in the first line (and the incremental compile + execute was successful) the cell is "undone" via sending a subsequent %undo directly to clang-repl

Installation

git clone https://gitlab.tuwien.ac.at/paul.manstetten/clang_repl.git
cd clang_repl
python -m venv .venv
source .venv/bin/activate
python -m pip install -e . # editable install
jupyter kernelspec list # should now also list "clang_repl   .venv/share/jupyter/kernels/clang_repl"
jupyter notebook --kernel clang_repl demo.ipynb
jupyter console --kernel clang_repl

pypi publishing

# test release
git clone https://gitlab.tuwien.ac.at/paul.manstetten/clang_repl_kernel.git
cd clang_repl_kernel
rm -rf .venv .testenv dist data_kernelspec
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade build twine
# note: bump version number (overriding is not supported on upload to pypi)
python -m build
# note: next step needs api token
python -m twine upload --repository testpypi --skip-existing dist/* 
deactivate
# test install of test release (no deps)
rm -rf .venv .testenv dist data_kernelspec
python -m venv .testenv
source .testenv/bin/activate 
python -m pip install --extra-index-url https://pypi.org/simple --index-url https://test.pypi.org/simple clang-repl
jupyter kernelspec list # should list clang_repl
jupyter console --kernel clang_repl # check if works (type: %status)
deactivate
# publish release
git clone https://gitlab.tuwien.ac.at/paul.manstetten/clang_repl_kernel.git
cd clang_repl_kernel
rm -rf .venv .testenv dist data_kernelspec
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade build twine
# note: bump version number (overriding is not supported on upload to pypi)
python -m build
# note: next step needs api token
python -m twine upload --repository pypi --skip-existing dist/* 
deactivate

Related links:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clang_repl-1.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clang_repl-1.0.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file clang_repl-1.0.0.tar.gz.

File metadata

  • Download URL: clang_repl-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for clang_repl-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3e0d6d8a44fcc35b83b6c2b2a1795611930c1b4231d77570f79c32f4855c374e
MD5 c1e210e136ec1737efe15b93dc899043
BLAKE2b-256 c28a6d61c97462cc8a88b92e2bba19a559747f5cceb294f9899c9055aaf20016

See more details on using hashes here.

File details

Details for the file clang_repl-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: clang_repl-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for clang_repl-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b53220f31ef9064610d8449bf5122484bb21c79d9ab0e64b319cedcfe28dd28
MD5 4621d502bde478506269e2a6d9fd49b9
BLAKE2b-256 970b2c42fe85cf6b67a5ac7e8c49ebed392b7c1b4deb760a86a14ee6174821f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page