Coder Social home page Coder Social logo

jupyterlite / xeus Goto Github PK

View Code? Open in Web Editor NEW
22.0 22.0 11.0 804 KB

JupyterLite loader for Xeus kernels

Home Page: https://jupyterlite-xeus.readthedocs.io

License: BSD 3-Clause "New" or "Revised" License

JavaScript 3.09% Python 60.16% TypeScript 36.39% CSS 0.36%
jupyterlite webassembly xeus

xeus's Introduction

JupyterLite

ci-badge lite-badge binder-badge docs-badge

JupyterLite is a JupyterLab distribution that runs entirely in the browser built from the ground-up using JupyterLab components and extensions.

⚡ Status ⚡

Although JupyterLite is currently being developed by core Jupyter developers, the project is still unofficial.

Not all the usual features available in JupyterLab and the Classic Notebook will work with JupyterLite, but many already do!

Don't hesitate to check out the documentation for more information and project updates.

✨ Try it in your browser ✨

JupyterLite works with both JupyterLab and Jupyter Notebook.

Try it with JupyterLab! Try it with Jupyter Notebook!
lab-screenshot notebook-screenshot

🏗️ Build your own JupyterLite 🏗️

You can build your own JupyterLite website in a couple of minutes, with custom extensions and packages.

See the documentation for more details.

Browser-based Interactive Computing

JupyterLite is all about accessible browser-based interactive computing:

  • Python kernel backed by Pyodide running in a Web Worker
    • Initial support for interactive visualization libraries such as altair, bqplot, ipywidgets, matplotlib, and plotly
  • JavaScript kernel running in a Web Worker
  • View hosted example Notebooks and other files, then edit, save, and download from the browser's IndexDB (or localStorage)
  • Support for saving settings for JupyterLab/Lite core and federated extensions
  • Basic session and kernel management to have multiple kernels running at the same time
  • Support for Code Consoles

Ease of Deployment

  • Served via well-cacheable, static HTTP(S), locally or on most static web hosts
  • Embeddable within larger applications
  • Requires no dedicated application server much less a container orchestrator
  • Fine-grained configurability of page settings, including reuse of federated extensions

Showcase

Jupyter Interactive Widgets

widgets

JupyterLab Mimerender Extensions

image

Matplotlib Figures

image

Altair

altair

Plotly

plotly

Development install

See the contributing guide for a development installation.

Related

JupyterLite is a reboot of several attempts at making a full static Jupyter distribution that runs in the browser, without having to start the Python Jupyter Server on the host machine.

The goal is to provide a lightweight computing environment accessible in a matter of seconds with a single click, in a web browser and without having to install anything.

This project is a collection of packages that can be remixed together in variety of ways to create new applications and distributions. Most of the packages in this repo focus on providing server-like components that run in the browser (to manage kernels, files and settings), so existing JupyterLab extensions and plugins can be reused out of the box.

See also:

  • p5-notebook: A minimal Jupyter Notebook UI for p5.js kernels running in the browser
  • jyve: Jupyter Kernels, right inside JupyterLab
  • Starboard Notebook: In-browser literal notebooks
  • Basthon: A Jupyter notebook implementation using Pyodide

👥 Contributors

Join our community and become a contributor today! 🚀

xeus's People

Contributors

derthorsten avatar isabelparedes avatar jtpio avatar katotetsuro avatar martinrenou avatar vipul-cariappa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

xeus's Issues

%load doesn't work as hoped on https

Trying to get this to work

%load  https://raw.githubusercontent.com/MicrosoftDocs/mslearn-introduction-to-machine-learning/main/graphing.py 

I get an error:

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/urllib/request.py in unknown_open(self, req)
   1417     def unknown_open(self, req):
   1418         type = req.type
-> 1419         raise URLError('unknown url type: %s' % type)
   1420 
   1421 def parse_keqv_list(l):

URLError: <urlopen error unknown url type: https>

is it a limitation ? is there a simple workaround ? (via javascript alternative ?)

Kernel binaries missing

Originally opened by @Alberto199810 in voici-demo voila-dashboards/voici-demo#23

Hello guys, I'm working on GitLab, and I'm using your library to deploy the Jupyter Notebook on GL Pages. The Pipeline end in success, and everything seems fine, apart from the fact that when I try to launch the page, it is stuck at the "Running" phase.

It seemed to me that the Kernel was not starting, and indeed in the deploy pipeline I've found this row:
"""
{...}/python3.10/site-packages/jupyterlite_xeus/add_on.py: UserWarning: kernel binaries not found for xpython-raw
"""

And then again same thing:

"""
{...}/python3.10/site-packages/jupyterlite_xeus/add_on.py: UserWarning: kernel binaries not found for xpython
"""

So, my feeling is that apparently it is not recognizing the kernel. Any idea in how to solve this?

Build fails with "Object of type PosixPath is not JSON serializable"

Description

When adding our bw2io package to the environment.yaml as a dependency, I get an error of this kind:

TypeError: Object of type PosixPath is not JSON serializable

Interestingly, the error does not reference the package, nor any of its dependencies. The error trace goes from the micromamba build library to jupyterlite_core/manager > jupyterlite_xeus/add_on > empack/pack and then to the Pyhon JSON decoder.

Any idea what the cause might be?

Reproduce

  1. Run build workflow at michaelweinold/jl_xeus_test

Expected behavior

No error 😇

Context

  • JupyterLite version: jupyterlite-core=0.3.0, jupyterlite-xeus=0.1.9
  • Operating System and version: N/A
  • Browser and version: N/A
Build Log
Transaction finished

To activate this environment, use:

micromamba activate xeus-python-kernel

Or to execute a single command in this environment, use:

micromamba run -n xeus-python-kernel mycommand

[LiteBuildApp] ERROR | [lite] [post_build] [jupyterlite-xeus] [ERR] Object of type PosixPath is not JSON serializable
Traceback (most recent call last):
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/doit_cmd.py", line 294, in run
return command.parse_execute(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/cmd_base.py", line 150, in parse_execute
return self.execute(params, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/cmd_base.py", line 570, in execute
return self._execute(**exec_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/cmd_run.py", line 265, in _execute
return runner.run_all(self.control.task_dispatcher())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/runner.py", line 254, in run_all
self.run_tasks(task_dispatcher)
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/runner.py", line 213, in run_tasks
node = task_dispatcher.generator.send(node)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/control.py", line 629, in _dispatcher_generator
next_step = node.step()
^^^^^^^^^^^
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/control.py", line 336, in step
return next(self.generator)
^^^^^^^^^^^^^^^^^^^^
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/control.py", line 345, in _func
for value in decorated(*args, **kwargs):
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/control.py", line 473, in _add_task
new_tasks = generate_tasks(to_load, task_gen, ref.doc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/loader.py", line 390, in generate_tasks
for task_dict, x_doc in flat_generator(gen_result, gen_doc):
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/doit/loader.py", line 27, in flat_generator
for item in gen:
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/jupyterlite_core/manager.py", line 138, in _delayed_gather
yield from _gather()
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/jupyterlite_core/manager.py", line 131, in _gather
raise error
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/jupyterlite_core/manager.py", line 123, in _gather
for task in getattr(addon, attr)(self):
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/jupyterlite_xeus/add_on.py", line 127, in post_build
yield from self.copy_kernels_from_prefix()
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/jupyterlite_xeus/add_on.py", line 179, in copy_kernels_from_prefix
yield from self.copy_kernel(kernel_dir, kernel_wasm, kernel_js)
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/jupyterlite_xeus/add_on.py", line 261, in copy_kernel
yield from self.pack_prefix(kernel_dir=kernel_dir)
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/jupyterlite_xeus/add_on.py", line 288, in pack_prefix
pack_env(
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/empack/pack.py", line 186, in pack_env
pack_pkg_impl(
File "/home/runner/micromamba/envs/build-env/lib/python3.11/site-packages/empack/pack.py", line 54, in pack_pkg_impl
json.dump(pkg_meta, f)
File "/home/runner/micromamba/envs/build-env/lib/python3.11/json/init.py", line 179, in dump
for chunk in iterable:
File "/home/runner/micromamba/envs/build-env/lib/python3.11/json/encoder.py", line 432, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/home/runner/micromamba/envs/build-env/lib/python3.11/json/encoder.py", line 406, in _iterencode_dict
yield from chunks
File "/home/runner/micromamba/envs/build-env/lib/python3.11/json/encoder.py", line 326, in _iterencode_list
yield from chunks
File "/home/runner/micromamba/envs/build-env/lib/python3.11/json/encoder.py", line 439, in _iterencode
o = _default(o)
^^^^^^^^^^^
File "/home/runner/micromamba/envs/build-env/lib/python3.11/json/encoder.py", line 180, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type PosixPath is not JSON serializable

Huge navbar in the documentation

Problem

Currently the navbar in the documentation takes two lines, and the layout looks off:

image

Suggested Improvement

It would be nice to make it look better, maybe with a config option if available, by changing the names of the sections, or by tweaking the CSS.

empack_config file filter does not seem to be working

Description

The file filter specified in XeusAddon.empack_config is not used.

https://github.com/jupyterlite/xeus/blob/main/jupyterlite_xeus/add_on.py#L263-L287

Reproduce

jupyter lite build --XeusAddon.empack_config=empack_config.yml

Context

It might be better handled as follows

https://github.com/jupyterlite/xeus-python-kernel/blob/main/jupyterlite_xeus_python/build.py#L321

pack_env(
      env_prefix=self.prefix,
      relocate_prefix="/",
      outdir=out_path,
      use_cache=True,
      **pack_kwargs,
)

Please add more detail and examples in installing a local Python package

In https://xeus-python-kernel.readthedocs.io/en/latest/configuration.html, it says that: "You can also install a local Python package, this is very practical if you want to embed a jupyterlite deployment in your Package documentation, allowing to test the very latest dev version:

name: xeus-python-kernel
channels:
  - https://repo.mamba.pm/emscripten-forge
  - conda-forge
dependencies:
  - pip:
      - .."

If I want to install a wheel named "a.wheel", it seems the following YAML works

dependencies:
  - pip:
      - "./a.wheel"

To install wheels of a folder named b, it seems the following YAML does not work.

dependencies:
  - pip:
      - "./b/*.wheel"

I am wondering what is the right way to do so.

mounts as lists where better..

I believe mounts as a List where better than comma-separated strings.

with lists I could do the following for three relatively long mounts

jupyter lite build  \
        --XeusAddon.prefix=$XEUS_PYTHON_WASM_ENV_PREFIX 
        --XeusAddon.mounts="$WASM_ENV_PREFIX/lib/python3.11/site-packages/nxtgm:/lib/python3.11/site-packages/nxtgm"
        --XeusAddon.mounts="$WASM_ENV_PREFIX/lib/nxtgm/__extra__/:/lib/"
        --XeusAddon.mounts="$WASM_ENV_PREFIX/lib/nxtgm/plugins:/lib/nxtgm/plugins"

With the comma separated this looks like the follwoing (horrible)

jupyter lite build  \
        --XeusAddon.prefix=$XEUS_PYTHON_WASM_ENV_PREFIX 
        --XeusAddon.mounts="$WASM_ENV_PREFIX/lib/python3.11/site-packages/nxtgm:/lib/python3.11/site-packages/nxtgm,XeusAddon.mounts="$WASM_ENV_PREFIX/lib/nxtgm/__extra__/:/lib/,$WASM_ENV_PREFIX/lib/nxtgm/plugins:/lib/nxtgm/plugins"

So to make this somewhat sane with the comma-separated list I have to introduce some variables
and call it with the variables.

MOUNT_PYTHON_PKG="$WASM_ENV_PREFIX/lib/python3.11/site-packages/nxtgm:/lib/python3.11/site-packages/nxtgm"
MOUNT_LIBNXTGM="$WASM_ENV_PREFIX/lib/nxtgm/__extra__/:/lib/"
MOUNT_NXTGM_PLUGINS="$WASM_ENV_PREFIX/lib/nxtgm/plugins:/lib/nxtgm/plugins"

# jupyterlite
jupyter lite build \
        --XeusAddon.prefix=$XEUS_PYTHON_WASM_ENV_PREFIX \
        --XeusAddon.mounts=$MOUNT_PYTHON_PKG,$MOUNT_LIBNXTGM,$MOUNT_NXTGM_PLUGINS

I suggest using a list of strings, and each entry can be comma-separated.
That way we get the best of both worlds

how to get sspyrs module included

Would it be possible to get the module sspyrs working, or a replacement ?
If I put it or its requirement requests-ntlm in the "environment.yml", the build fails.

... yet "requets" seems to be there

# requests works in  jupyterlite/xeus-python-demo !
import requests
from datetime import date, timedelta, datetime

today = date.today()
yesterday = today - timedelta(days=10)
country =  "germany"
endpoint = f"https://api.covid19api.com/country/{country}/status/confirmed"
params = {"from": str(yesterday), "to": str(today)}
print(params)
endpoint_via_browser = f"https://api.covid19api.com/country/germany/status/confirmed?from=2022-12-06&to=2022-12-22"

response = requests.get(endpoint, params=params).json()
total_confirmed = 0
for day in response:
    date_python = datetime.fromisoformat(day.get("Date", 0)[:-1] + '+00:00')
    print(date_python.strftime('%Y-%m-%d'), f'{day.get("Cases", 0):_.0f}')
    cases = day.get("Cases", 0)
    total_confirmed += cases

print(f"Total Confirmed Covid-19 cases in {country}: {total_confirmed:_.0f}")

image

Add an option to disable the logs in the dev tools console

Problem

Currently there are quite a few messages in the dev tools console when starting a kernel:

image

These messages can add a bit of noise and some deployments might want to silent them.

Proposed Solution

  • Provide an option to disable the logs
  • Show the logs by default or not?

Additional context

Testing with:

  • jupyterlite-xeus-python 0.9.0
  • empack 3.0.0

Load SVG icons for kernels

There are some kernels providing an SVG icon as part of their kernel spec. We should make use of it when available.

Improve error messages for the end-user

When not having an environment.yml file around, the error Either prefix or environment_file must be set shows up, not giving any clue to the user what to do next. We should provide solutions like:

"Either a prefix or an environment_file must be provided for jupyterlite-xeus. You should try to create an environment.yml file in the location where you build the JupyterLite site. See https://jupyterlite-xeus.readthedocs.io/en/latest/environment.html for examples."

Support for https in `urllib`

Description

urllib can't handle https URLs in XPython kernel.

A similar issue was reported for Pyodide kernel (jupyterlite/jupyterlite#413), but the proposed solution is Pyodide specific.

Reproduce

Using xeus-python-kernel, try to execute a cell:

import pandas as pd
pd.read_csv('https://raw.githubusercontent.com/jupyterlite/jupyterlite/main/examples/data/iris.csv')

You will get the error: <urlopen error unknown url type: https>

Detailed error report shows the exception is raised inside the urllib module.

Expected behavior

The referenced CSV file should be loaded into a data frame.

Context

  • JupyterLite version: latest
  • Operating System and version: Win 10
  • Browser and version: Chrome, latest
  • jupyter_lite_config.json:
{
  "XeusPythonEnv": {
    "packages": ["openpyxl","pandas","matplotlib","openssl","pyopenssl"]
  },
  "LiteBuildConfig": {
    "contents": ["_contents"]
  }
}
Error traceback
---------------------------------------------------------------------------
URLError                                  Traceback (most recent call last)
Input In [3], in ()
----> 1 pd.read_csv('https://raw.githubusercontent.com/jupyterlite/jupyterlite/main/examples/data/iris.csv')

File /lib/python3.10/site-packages/pandas/util/_decorators.py:311, in deprecate_nonkeyword_arguments..decorate..wrapper(*args, **kwargs)
305 if len(args) > num_allow_args:
306 warnings.warn(
307 msg.format(arguments=arguments),
308 FutureWarning,
309 stacklevel=stacklevel,
310 )
--> 311 return func(*args, **kwargs)

File /lib/python3.10/site-packages/pandas/io/parsers/readers.py:680, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, error_bad_lines, warn_bad_lines, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)
665 kwds_defaults = _refine_defaults_read(
666 dialect,
667 delimiter,
(...)
676 defaults={"delimiter": ","},
677 )
678 kwds.update(kwds_defaults)
--> 680 return _read(filepath_or_buffer, kwds)

File /lib/python3.10/site-packages/pandas/io/parsers/readers.py:575, in _read(filepath_or_buffer, kwds)
572 _validate_names(kwds.get("names", None))
574 # Create the parser.
--> 575 parser = TextFileReader(filepath_or_buffer, **kwds)
577 if chunksize or iterator:
578 return parser

File /lib/python3.10/site-packages/pandas/io/parsers/readers.py:933, in TextFileReader.init(self, f, engine, **kwds)
930 self.options["has_index_names"] = kwds["has_index_names"]
932 self.handles: IOHandles | None = None
--> 933 self._engine = self._make_engine(f, self.engine)

File /lib/python3.10/site-packages/pandas/io/parsers/readers.py:1217, in TextFileReader._make_engine(self, f, engine)
1213 mode = "rb"
1214 # error: No overload variant of "get_handle" matches argument types
1215 # "Union[str, PathLike[str], ReadCsvBuffer[bytes], ReadCsvBuffer[str]]"
1216 # , "str", "bool", "Any", "Any", "Any", "Any", "Any"
-> 1217 self.handles = get_handle( # type: ignore[call-overload]
1218 f,
1219 mode,
1220 encoding=self.options.get("encoding", None),
1221 compression=self.options.get("compression", None),
1222 memory_map=self.options.get("memory_map", False),
1223 is_text=is_text,
1224 errors=self.options.get("encoding_errors", "strict"),
1225 storage_options=self.options.get("storage_options", None),
1226 )
1227 assert self.handles is not None
1228 f = self.handles.handle

File /lib/python3.10/site-packages/pandas/io/common.py:670, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
667 codecs.lookup_error(errors)
669 # open URLs
--> 670 ioargs = _get_filepath_or_buffer(
671 path_or_buf,
672 encoding=encoding,
673 compression=compression,
674 mode=mode,
675 storage_options=storage_options,
676 )
678 handle = ioargs.filepath_or_buffer
679 handles: list[BaseBuffer]

File /lib/python3.10/site-packages/pandas/io/common.py:339, in _get_filepath_or_buffer(filepath_or_buffer, encoding, compression, mode, storage_options)
337 # assuming storage_options is to be interpreted as headers
338 req_info = urllib.request.Request(filepath_or_buffer, headers=storage_options)
--> 339 with urlopen(req_info) as req:
340 content_encoding = req.headers.get("Content-Encoding", None)
341 if content_encoding == "gzip":
342 # Override compression based on Content-Encoding header

File /lib/python3.10/site-packages/pandas/io/common.py:239, in urlopen(*args, **kwargs)
233 """
234 Lazy-import wrapper for stdlib urlopen, as that imports a big chunk of
235 the stdlib.
236 """
237 import urllib.request
--> 239 return urllib.request.urlopen(*args, **kwargs)

File /lib/python3.10/urllib/request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
214 else:
215 opener = _opener
--> 216 return opener.open(url, data, timeout)

File /lib/python3.10/urllib/request.py:519, in OpenerDirector.open(self, fullurl, data, timeout)
516 req = meth(req)
518 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 519 response = self._open(req, data)
521 # post-process response
522 meth_name = protocol+"_response"

File /lib/python3.10/urllib/request.py:541, in OpenerDirector._open(self, req, data)
538 if result:
539 return result
--> 541 return self._call_chain(self.handle_open, 'unknown',
542 'unknown_open', req)

File /lib/python3.10/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
494 for handler in handlers:
495 func = getattr(handler, meth_name)
--> 496 result = func(*args)
497 if result is not None:
498 return result

File /lib/python3.10/urllib/request.py:1419, in UnknownHandler.unknown_open(self, req)
1417 def unknown_open(self, req):
1418 type = req.type
-> 1419 raise URLError('unknown url type: %s' % type)

URLError: <urlopen error unknown url type: https>

add parameter to Worker Constructor?

Within the worker.ts we import the kernel specific js file (here it is still xeus_lua.js)
https://github.com/jupyterlite/xeus-kernel/blob/ded2690d2a0a706dfa3b7dc2608cf41a5a57429e/src/worker.ts#L3
The question is, can we pass the actual import to the constructor here https://github.com/jupyterlite/xeus-kernel/blob/ded2690d2a0a706dfa3b7dc2608cf41a5a57429e/src/xeus_server_kernel.ts#L20
or do we need to send the import statement as a message to the worker?

I would like to avoid sending the actual import path (like xeus_lua.js / xeus_wren.js) to the worker via message and would prefer if that could be done at construction time of the worker, if possible.

@jtpio any suggestions =)

Show a warning if there is no kernel installed

If there is no kernel installed, the extension fails with:

   File "/home/runner/micromamba/envs/build-env/lib/python3.12/pathlib.py", line 1056, in iterdir
    for name in os.listdir(self):
                ^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmp2ay0_eyo/env/envs/xeus-env/share/jupyter/kernels'

It would be nice to have a nice user-friendly message instead.

Update the JupyterLite main documentation to mention this new package

Problem

In https://jupyterlite.readthedocs.io/en/stable/howto/xeus-python/preinstalled_packages.html, there is a link pointing to https://github.com/jupyterlite/xeus-python-kernel.

image

For reference this piece of documentation was added to the main JupyterLite documentation for visibility and discoverability of the Xeus Python kernel.

Suggested Improvement

We should update the JupyterLite main documentation to point to this new repo.

This can wait until jupyterlite-xeus is considered ready for general use.

Automatically add the `emscripten-forge` channel if it is missing?

Problem

Currently the default channels are only added if there is no environment file:

# open the env yaml file if it's provided
if env_file.exists():
with open(env_file, "r") as file:
yaml_content = yaml.safe_load(file)
env_name = yaml_content.get("name", "xeus-env")
env_prefix = root_prefix / "envs" / env_name
self.prefix = str(env_prefix)
create_conda_env_from_env_file(root_prefix, yaml_content, env_file.parent)
else:
create_conda_env_from_specs(
env_name=env_name,
root_prefix=root_prefix,
specs=["xeus-python"],
channels=["https://repo.mamba.pm/emscripten-forge", "conda-forge"],
)

Proposed Solution

Maybe the add-on should check if the user-provided environment.yml includes https://repo.mamba.pm/emscripten-forge in the list of channels, and add it automatically otherwise?

Additional context

This could help improving compatibility with existing environment.yml files without having to create a copy of the file with https://repo.mamba.pm/emscripten-forge in it.

And also for use cases such as repo2jupyterlite: jupyterlite/repo2jupyterlite#19

todos to make jupyterlite/xeus the default (ie steps to deprectate jupyterlite/xeus-<lang>-kernels

What is needed to replace jupyterlite/xeus--kernels (in particular jupyterlite/xeus-python-kernel):

  • at least some documentation on how to use this (#8)
    • usage with kernels installed from emscripten-forge
    • usage with kernels installed from local PREFIX
    • usage with additional directories mounted
  • expose empack filtering configuration as a parameter (like xeus-python-kernel) (#12)
  • make tests pass #14
  • add / port tests jupyterlite/xeus-python-kernel (#7)
  • release on PyPI / release on conda-forge (does this need to be also on npm?) (#15)

Probably needed:

  • documentation on readthedocs #17

Unexpected behavior using `ipympl` called from `sympy_plot_backends`, same code works as expected using `pyodide` kernel

Description

With sympy_plot_backends I create an interactive plot that shows the graph of a parameter dependent function. With a slider it is possible to change the parameter value. After changing the slider value, the plot should be updated. In sympy_plot_backends interactive matplotlib is used.

With pyodide-kernel for jupyterlite this feature is working as expected. With xeus-python there is a glitch: After changing the slider value, the graph is not directly updated. As soon as I click into the drawing pane, the graph gets updated.

Reproduce

Execute the following code in a notebook:

import sympy
%matplotlib widget
import spb

x = sympy.Symbol('x', real=True)
a = sympy.Symbol('a', real=True)

f = sympy.cos(x)/(x**2 + 1)

spb.plot(
    f.subs(x, x-a),
    params = {
        a: (0, -5, 5)
    }
)
  • Now change the slider value for a from the default 0.0 to something nonzero.
  • Observe that the plot does not change.
  • Click into the plot.
  • Observe that now the plot has been updated as expected.

Expected behavior

The plot should update without clicking into the plot pane. With pyodide kernel it is working as expected.

Context

Xeus Python Environment file:

name: xeus-python-kernel

channels:
  - https://repo.mamba.pm/emscripten-forge
  - conda-forge

dependencies:
  - ipympl
  - matplotlib
  - numpy
  - sympy
  - sympy_plot_backends
  • JupyterLite version: 0.2.1
  • Operating System and version: OS X
  • Browser and version: Chrome 120.0.6099.71 and Safari 17.2 (19617.1.17.11.9)

Support for package data

Description

I have a Python package which includes package data, to be accessed
through importlib.resources. However, within jupyterlite, importlib.resources
fails do find the data.

Reproduce

  1. Clone https://github.com/jupyterlite/xeus-python-demo

  2. Add these dependencies to environment.yml

      - pip
      - pip:
        - "git+https://gitlab.dsi.universite-paris-saclay.fr/nicolas.thiery/Laby.git"
    
  3. Build JupyterLite

    mamba env create --force -f build-environment.yml
    conda activate build-env
    cp README.md content
    jupyter lite build --contents content --output-dir dist
    
  4. Check the log, and notice the copying of the package data when building the wheel:

    creating build/bdist.linux-x86_64/wheel/laby/resources/tiles_png
    copying build/lib/laby/resources/tiles_png/nweb.png -> build/bdist.linux-x86_64/wheel/laby/resources/tiles_png
    ...
    
  5. Browse dist/extensions/@jupyterlite/xeus-python-kernel/static/laby_python-0.0.5-pip.tar.gz

    Expected behavior: the archive contain the package data.
    Got: the package contains only the Python code

  6. Run JupyterLite and from a python kernel run:

    tiles_dir = importlib.resources.files("laby").joinpath("resources", "tiles_png")
    list(tiles_dir.glob("*"))
    

    Expected behavior: a list of files including 'nweb.png`.
    Got: the empty list

Context

  • JupyterLite version: 0.1.2
  • Operating System and version: Ubuntu 22.04
  • Browser and version: Firefox/chromium

xeus python does not load logo.

Description

a pip installed jupyterlite-xeus does not yield a xeus-python with a proper logo.
Xeus python is installed with micromamba and and xeus-lite is build with the prefix option.
This is very likely related to #36

Console says:
logo-svg.svg:1 Failed to load resource: the server responded with a status of 404 (File not found)

xhr is called synchronously

Description

getJson helper is using XMLHttpRequest synchronously, which is deprecated and does not work well with service worker. Is there any technical season to avoid async call here or can we convert this function to use fetch?

xeus/src/index.ts

Lines 15 to 20 in 6504866

function getJson(url: string) {
const json_url = URLExt.join(PageConfig.getBaseUrl(), url);
const xhr = new XMLHttpRequest();
xhr.open('GET', json_url, false);
xhr.send(null);

Add scripts to build the documentation

Problem

Currently there is no easy way to build the documentation locally.

Suggested Improvement

  • Add scripts to build the documentation. For example similar to:

https://github.com/voila-dashboards/voila/blob/5aa861dc153215c66d8ccdff040f4ac868d7af3a/pyproject.toml#L145-L151

[tool.hatch.envs.docs]
features = ["docs"]

[tool.hatch.envs.docs.scripts]
build = "sphinx-build -W -b html docs docs/build/html"
watch = "sphinx-autobuild -W -b html docs docs/build/html --host 0.0.0.0"
serve = "python -m http.server --directory docs/build/html"
  • Add a section to the contributing guide about contributing to the documentation

UnicodeEncodeError on open()

Description

This may not be the problem with jupyterlite-xeus,
If I try to open a file with a path that contains Unicode characters, such as open('あ'), I get a UnicodeEncodeError.

Reproduce

  1. Go to https://jupyterlite-xeus.readthedocs.io/en/latest/
  2. execute open('あ')
  3. UnicodeEncodeError: 'ascii' codec can't encode character '\u3042' in position 14: ordinal not in range(128)

Context

import locale
locale.getencoding()
> 'ASCII'

Unlike pyodide, the result of locale.getencoding() is 'ASCII', so if I could set the locale somewhere, it would solve the problem.

Is the locale in empack or conda env affecting it?

make tests pass / fix integration tests

  • Integration tests (testing it shows kernels with icons properly in the lite UI)
  • Unit tests (testing it correctly generates the expected output in the build directory)

Fetch and http request

A follow up on jupyterlite/pyodide-kernel#96

Description

I tried xeus because adding additional pkgs seems far easier then in pyodide. But I ran into issues with network requests.

Reproduce

Using fetch seems to work in principle but gave me this error:

import js
import json

json.loads(await (await js.fetch("http://localhost:8000/jupyter/lab/jupyter-lite.json")).text())
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File /lib/python3.11/site-packages/IPython/__init__.py:44, in patch_asyncio.<locals>.asyncio_call(self, coro)
     41     task.add_done_callback(done_cb)
     43 raw_js_py_callback = pyjs.JsValue(py_callback)
---> 44 js_py_callback = raw_js_py_callback['__usafe_void_val_val__'].bind(raw_js_py_callback)
     45 js_promise = pyjs.js.Promise.new(js_py_callback)
     47 pyjs.js.globalThis.toplevel_promise = js_promise

AttributeError: has no attribute/key __usafe_void_val_val__

Then I tried httpx which seems to require openssl (I added it to my environment.yml). This made the kernel unusable with the condole error: LinkError: WebAssembly.instantiate(): Import #92 module="env" function="time": imported function does not match the expected type. Complete output below.

I can confirm that requests lib works but I could not test it with https so far.

Context

  • JupyterLite version: 0.2.3
  • Operating System and version: debian bookworm
  • Browser and version: Chrome, Version 122.0.6261.111 (Official Build) (64-bit)
Browser Output

870.1260b274e8c70c250b274e8c70c25c3c4:2
Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #92 module="env" function="time": imported function does not match the expected type
  | deserialize | @ | 870.1260b274e8c70c25…0b274e8c70c25c3c4:2 -- | -- | -- | --   | S | @ | 870.1260b274e8c70c25…0b274e8c70c25c3c4:2   | Promise.then (async) |   |     | apply | @ | 870.1260b274e8c70c25…0b274e8c70c25c3c4:2   | h | @ | 413.df2804f5ae3431aa…804f5ae3431aa4c17:1   | create | @ | 413.df2804f5ae3431aa…804f5ae3431aa4c17:1   | startNew | @ | kernels.js:123   | startNew | @ | sessions.js:105   | (anonymous) | @ | index.js:366   | route | @ | router.js:85   | await in route (async) |   |     | fetch | @

ia-expanded="true" tabindex="-1" style="box-sizing: border-box; min-width: 0px; min-height: 0px; flex: 0 0 auto;">
870.1260b274e8c70c250b274e8c70c25c3c4:2
Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #92 module="env" function="time": imported function does not match the expected type



deserialize@870.1260b274e8c70c250b274e8c70c25c3c4:2
S@870.1260b274e8c70c250b274e8c70c25c3c4:2
Promise.then (async)
apply@870.1260b274e8c70c250b274e8c70c25c3c4:2
h@413.df2804f5ae3431aa804f5ae3431aa4c17:1
create@413.df2804f5ae3431aa804f5ae3431aa4c17:1
startNew@kernels.js:123
startNew@sessions.js:105
(anonymous)@index.js:366
route@router.js:85
await in route (async)
fetch@

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.