Giter VIP home page Giter VIP logo

vscode-pyolite's Introduction

Pyolite kernel for Visual Studio Code

Python kernel for Visual Studio Code notebooks based on JupyterLite, Pyodide, the Jupyter extension for VS Code.

Development

To build the extension and test it against github.dev:

  1. git clone https://github.com/joyceerhl/vscode-pyolite
  2. cd vscode-pyolite
  3. npm i
  4. npm run watch-web
  5. In one shell, npm run serve
  6. In another shell, npm run tunnel
  7. Click on the local URL printed as a result of running npm run localtunnel and click 'Click to Continue'
  8. Navigate to a repository in vscode.dev
  9. Ctrl+Shift+P > Install Web Extension > paste in the URL printed from running npm run localtunnel
  10. The Pyolite VS Code extension should be installed and ready for local testing!

Acknowledgments

This extension builds on top of:

  1. The VS Code notebooks API
  2. JupyterLite
  3. Pyodide
  4. The Jupyter extension for VS Code

vscode-pyolite's People

Contributors

joaomoreno avatar joyceerhl avatar jtpio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar

vscode-pyolite's Issues

Activating pyolite from a new file

Opening a existing notebook (.ipynb file) activate pyolite as kernel.

What is the workflow to activated pyolite from a newly created a file (.ipynb or .py) i vscode.dev?

EDIT: it seems there is no way to activate the Command Palette "Jupyter: Create Blank New Jupyter Notebook". Just creating a new file and selected language "Jupyter" does not work. This is the same for the desktop version of VS Code.

When I try to create a new notebook and save it as .ipynb, it looks like it is just saved as plain text.

1. new file
2. click select language
3. select Jupyter
4. save file

Move the repo to the `jupyterlite` organization?

Thanks again for putting this repo together!

I was wondering: since some of the development happening here is somewhat related to the efforts happening on JupyterLite: do you think the jupyterlite organization on GitHub could be a new home for the repo?

Maybe it would also be a good opportunity to add support for other kernels than Python? For example p5.js, Lua and Wren are also supported in JupyterLite:

With more Xeus-based kernels on the way: https://blog.jupyter.org/xeus-lite-379e96bb199d

Probably the vscode-pyolite extension for VS Code could either be made more generic to support different kernels? For example the logic should be quite similar for Xeus-based kernels since they also run WebAssembly in a Web Worker.

Another benefit to the move would be an increased visibility for the extension so it's more discoverable.

Finally it would be great to check if it's possible to deploy a static version of VS Code (with extensions). Just like vscode.dev but self-hosted. This means folks would be able to deploy their own VS Code alongside JupyterLite with the JupyterLab and RetroLab interfaces, served via a plain HTTP server. Maybe it's already possible to do a custom static build with the latest web version of VS Code? (directly from https://github.com/microsoft/vscode)

Update pyodide

Pyodide has been updated several times since this demo was released that uses v0.18.1.

Is there any likelihood of this repo being updated? Or is there an official Pyodide kernel available in development somewhere, eg for running in vscode.dev?

I note that elsewhere there is a candidate WASM build for R — https://github.com/georgestagg/webR/ — which might be interesting as another in-browser Jupyter kernel language.

pyodide opencv-python package not available

The opencv-python package available in the pyodide kernel reports not available when running the kernel from vscode.dev

from platform import python_version
print(python_version())
import cv2 as cv

3.9.5
ModuleNotFoundError Traceback (most recent call last)
Cell In[24], line 7
5 from platform import python_version
6 print(python_version())
----> 7 import cv2 as cv

ModuleNotFoundError: No module named 'cv2'

#############################
The test file from the pyodide repo uses import cv2 as cv for importing the package. https://github.com/pyodide/pyodide/blob/main/packages/opencv-python/test_opencv_python.py

Large output in cells is converted to JSON blob.

Expected behavior:
Large output from a cell would still be scrollable within that cell; or, as a stop-gap, when clicking the show more (open the raw output data in the text editor)... option (see below) the cell's output would be shown, appropriately formatted, in a new tab.

Screen Shot 2021-11-07 at 9 36 57 AM

Experienced behavior:
Large cell output is not scrollable. When selecting the show more... link, a new tab is opened, and cell outputs are shown as a JSON blob:
image

Link to reproduce:
https://github.dev/dynamicwebpaige/nanowrimo-2021/blob/main/6_Pandas_explorations_on_DataFrames.ipynb

Paths are relative to the root of the repository - any way to change this?

Hi, I've just discovered this cool extension thanks to @dynamicwebpaige tweet https://twitter.com/DynamicWebPaige/status/1425502379777019909

I have a public python course developed with jupyter notebooks. I was interested in make it working via github.dev and tried it with the pyolite extension.

It works amazingly well, except for the paths.

E.g. in https://github.dev/koldLight/curso-python-analisis-datos/blob/master/notebooks/02_pandas.ipynb if I try to run the first cell:

import pandas as pd

alquiler = pd.read_csv('dat/alquiler-madrid-distritos.csv', index_col=False)
alquiler.head()

It fails. It seems it's taking as base path the root of the git repository (although in a jupyter notebook, the base path is its location). If I change the path to notebooks/dat/alquiler-madrid-distritos.csv it starts working.

So, my question is... is there any way to set the base path for the extension to run? Or to be always relative to the opened notebook?

Thanks!

License?

Hello! I love the project and would love to contribute. Do you have a license for the project? I looked around briefly and couldn't find one.

Pyodide on `github.dev` does not write files back to Github repo.

Expected behavior
I created a couple of files during my Pyodide session with github.dev -- a SQLite database (population.db), as well as an interactive visualization using Plotly (ML-vis.html). When using os.listdir(), I am able to view these files in the session; but do not see them in my Github repo when I refresh the files list.

Experienced behavior
See above; have created files, but do not see them present in my Github repo. Should they be cp-ed to one of the subdirectories below?

Reproducible link
https://github.dev/dynamicwebpaige/githubdev-notebook-features/blob/main/Overview_of_VSCode_Notebook_Features.ipynb

image

Kernel won't start in local notebooks

I'm testing the extension in my local machines (VSCode 1.61.2, macOS 11.6 / elementary OS 6) and it seems the kernel won't start. I can get any code to run on it. Is the extension designed to be used on remote machines? If so, what causes it to not work locally?

Thanks!

Issues using `pandas` to read files.

Expected behavior:

I should be able to use pandas to access a CSV housed in my repo, or to pull in a flat file via URL:

import pandas as pd
pd.read_csv('/path/to/csv')

Experienced behavior:

The only way to access flat files in a Pyodide session on github.dev is to import pyodide, and to use its open_url function:

import pyodide
raw_data = pd.read_csv(pyodide.open_url(data_url))

Screen Shot 2021-10-20 at 12 37 26 PM

Related comment(s):

pyodide/pyodide#351 (comment)

`read_excel()` throws missing dependency `xlrd`

Expected behaviour
That I can use pandas read_excel() without error on vscode.dev, given that it's part of pyodide's stack - pyodide/pyodide#564

Experienced behaviour
A minimum example

Energy = pd.read_excel('assets/Energy Indicators.xls')
print(Energy.head())

This throws the following error on cell execution.

ImportError                               Traceback (most recent call last)
<ipython-input-1-e48ceea6593a> in <module>
     15     print(Energy)
     16 
---> 17 answer_one()

<ipython-input-1-e48ceea6593a> in answer_one()
      2     import pandas as pd
      3     import numpy as np
----> 4     Energy = pd.read_excel('assets/Energy Indicators.xls')
      5     Energy.replace(to_replace='...', value=np.NaN)
      6     Energy = Energy.iloc[17: -38]

/lib/python3.9/site-packages/pandas/io/excel/_base.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, verbose, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, **kwds)
    302 
    303     if not isinstance(io, ExcelFile):
--> 304         io = ExcelFile(io, engine=engine)
    305     elif engine and engine != io.engine:
    306         raise ValueError(

/lib/python3.9/site-packages/pandas/io/excel/_base.py in __init__(self, io, engine)
    822         self._io = stringify_path(io)
    823 
--> 824         self._reader = self._engines[engine](self._io)
    825 
    826     def __fspath__(self):

/lib/python3.9/site-packages/pandas/io/excel/_xlrd.py in __init__(self, filepath_or_buffer)
     18         """
     19         err_msg = "Install xlrd >= 1.0.0 for Excel support"
---> 20         import_optional_dependency("xlrd", extra=err_msg)
     21         super().__init__(filepath_or_buffer)
     22 

/lib/python3.9/site-packages/pandas/compat/_optional.py in import_optional_dependency(name, extra, raise_on_missing, on_version)
     90     except ImportError:
     91         if raise_on_missing:
---> 92             raise ImportError(msg) from None
     93         else:
     94             return None

ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

read and write CSVs in the local folder

Hi,

First of all... this is great, keep pushing!

And, although I have seen a few issues that are quite similar, I want to explain my use case that doesn't work and I see it as a core one:

  • From vscode opening a local folder:
    -- read a csv from the local folder using pandas
    -- work with it
    -- save the result to another file in the folder <-- this also didn't work for me.

When people can do this, I think it will be the best tool for learning python or casual programming.

Thanks

`time.sleep(...)` fails to suspend execution for indicated number of seconds.

Expected behavior:
When importing Python's time module and using the sleep() function, I expect to suspend execution of the calling thread for the given number of seconds.

Experienced behavior:
42 seconds passed in the blink of an eye. I knew it was a special number, but not that special! ☺

Reproducible example:

import time
print("The meaning of life...")
time.sleep(42)
print("...is learning the superpower of patience.")

image

Failed to import scikit-learn.

scikit-learn failed to install after 14+ seconds, issuing this warning message:

/lib/python3.8/site-packages/scipy/linalg/special_matrices.py:845: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if kind is 'lower':

Strange behavior when testing string interpolation on github.dev.

Intended behavior:
Expected to see either the output ['VS Code is great!', 'VS Code is great!'] (what appears in Colab) or ['$message', '$message'] (what appears in VS Code locally, and in Codespaces) when testing string interpolation in github.dev using the Pyolite extension.

message = 'VS Code is great!'
foo = !echo -e '$message\n$message'
foo

Experienced behavior:
See error logs below.

Reproducible example:
https://github.dev/dynamicwebpaige/githubdev-notebook-features/blob/main/Overview_of_VSCode_Notebook_Features.ipynb

Error Message:

---------------------------------------------------------------------------
BlockingIOError                           Traceback (most recent call last)
<ipython-input-2-dd18482e0536> in <module>
      1 message = 'VS Code is great!'
----> 2 foo = get_ipython().getoutput("echo -e '$message\\n$message'")
      3 foo

/lib/python3.9/site-packages/IPython/core/interactiveshell.py in getoutput(self, cmd, split, depth)
   2574             # this is *far* from a rigorous test
   2575             raise OSError("Background processes not supported.")
-> 2576         out = getoutput(self.var_expand(cmd, depth=depth+1))
   2577         if split:
   2578             out = SList(out.splitlines())

/lib/python3.9/site-packages/IPython/utils/_process_common.py in getoutput(cmd)
    128     correct order as would be seen if running the command in a terminal).
    129     """
--> 130     out = process_handler(cmd, lambda p: p.communicate()[0], subprocess.STDOUT)
    131     if out is None:
    132         return ''

/lib/python3.9/site-packages/IPython/utils/_process_common.py in process_handler(cmd, callback, stderr)
     77     if shell and os.name == 'posix' and 'SHELL' in os.environ:
     78         executable = os.environ['SHELL']
---> 79     p = subprocess.Popen(cmd, shell=shell,
     80                          executable=executable,
     81                          stdin=subprocess.PIPE,

/lib/python3.9/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask)
    949                             encoding=encoding, errors=errors)
    950 
--> 951             self._execute_child(args, executable, preexec_fn, close_fds,
    952                                 pass_fds, cwd, env,
    953                                 startupinfo, creationflags, shell,

/lib/python3.9/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
   1752                     fds_to_keep = set(pass_fds)
   1753                     fds_to_keep.add(errpipe_write)
-> 1754                     self.pid = _posixsubprocess.fork_exec(
   1755                             args, executable_list,
   1756                             close_fds, tuple(sorted(map(int, fds_to_keep))),

BlockingIOError: [Errno 6] Resource temporarily unavailable

Open implementation questions

  • Bundle modules with the extension vs hit a CDN (desktop)
    • Which modules should we bundle
    • What extension bundle size is tolerable
    • Investigate cost of loading libraries from CDN
  • Spawn web worker
    • Can VS Code expose the ability to create web workers to extensions, so that extension authors can move long running computation out of the main renderer process
  • Explore loading Pyodide and packages in Node instead of in the renderer preloads or web worker
    • Test: are existing packages trivially supported with the tweaks to Pyodide that @rebornix has made?
  • How will users transition from Pyolite to a 'real' Python kernel?

🏆 FR: Add logo to `vscode-pyolite`.

Long-term request:
Official logo for the Pyolite extension in the VS Code marketplace. As it stands, the extension looks quite experimental, which could be reducing the number of organic downloads:

Screen Shot 2021-10-21 at 9 28 07 AM

Short-term request:
Could we perhaps use the Pyodide logo, instead?

image

Reusing upstream packages?

At the moment it looks like some types and interfaces are vendored in the repo:

https://github.com/joyceerhl/vscode-pyolite/tree/main/src/web/kernel

This is just a quick heads up that @jupyterlite packages are now published to npm. For example: https://www.npmjs.com/package/@jupyterlite/kernel

These are still alpha and things can change quickly. But they might already make it easier to reuse the types and interfaces without having to vendor them.

Also there are plans to extract the pyolite kernel from the main repo in jupyterlite/jupyterlite#386. So maybe this would also help reuse pyolite outside of the default JupyterLite interfaces (lab / retro) more easily!

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.