question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set pre-run python codes when open a notebook

See original GitHub issue

Feature Request 1 (already supported) Allow local file path in piplite_urls, so I can cache my private python package.

Feature Request 2 Run python codes defined in config everytime I opened a new notebook. This can be really good for cutomization, like pre-install some packages, ignore uncessary warnings, …

If you think these requests are resonable, I can help file a PR.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
martinRenoucommented, Feb 10, 2022

Supporting the IPython config would be nice indeed! Because we already use IPython it could possibly be done.

On another note, there is a PR related to this issue in replite: https://github.com/jtpio/replite/pull/24

1reaction
psychemediacommented, Feb 10, 2022

Idly wondering about “JupyterLite-Binder” or “repo2jupyterlite” Github Action that could create a JupyterLite distribution from the contents of a repository and then publish it to Github pages, I note the repo2docker/configuration and repo2docker/config_files docs:

File Relevant to JupyterLite? comments
environment.yml N/A? are there conda recipes for pyodide? Other WASM kernel feedstocks?
Pipfile and/or Pipfile.lock ? pipenv config file; a jupyterlite distribution is essentially an environment
requirements.txt Y Install a Python environment
setup.py Y Install Python packages; eg if the repo defines a package and the distribution is demonstrating it
Project.toml Not yet? Install a Julia environment; is there likely to be a jupyterlite Julia kernel (J in Jupyter suggests there should be…)
install.R mid-term? Install an R/RStudio environment ; POC R-WASM build available, kernel at some point?
apt.txt N/A ? Install packages with apt-get
DESCRIPTION mid-term? Install an R package ; POC R-WASM build available, kernel at some point?
postBuild ? Run code after installing the environment; eg run code in sense of the Github action? Moving files etc? Gives CLI access to Action runner over and above jupterlite-build command
start N? In Binder sense, this is run at command-line level; is there a JupyterLite corollary?
runtime.txt Y? Specifying runtimes; eg specifying particular pyolite versions?
default.nix N/A? the nix package manager; but maybe other custom package managers are relevant
Dockerfile ? Advanced environments; this could still be supported for custom builds

I also note that IPython supports environment configuration (IPython/config):

# sample ipython_config.py
# JSON format also supported

c.TerminalIPythonApp.display_banner = True
c.InteractiveShellApp.log_level = 20
c.InteractiveShellApp.extensions = [
    'myextension'
]
c.InteractiveShellApp.exec_lines = [
    'import numpy',
    'import scipy'
]
c.InteractiveShellApp.exec_files = [
    'mycode.py',
    'fancy.ipy'
]
c.InteractiveShell.colors = 'LightBG'
c.InteractiveShell.xmode = 'Context'
c.TerminalInteractiveShell.confirm_exit = False
c.TerminalInteractiveShell.editor = 'nano'

As already noted, IPython also supports startup files and it might make sense for a JupyterLite environment to support something similar, although perhaps with a warning (“Enable startup files: Y/N”) on first load:

If you want some code to be run at the beginning of every IPython session, the easiest way is to add Python (.py) or IPython (.ipy) scripts to your profile_default/startup/ directory. Files here will be executed as soon as the IPython shell is constructed, before any other code or scripts you have specified. The files will be run in order of their names, so you can control the ordering with prefixes, like 10-myimports.py.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to run Python code before every jupyter notebook kernel
Suppose I have a code snippet that I'd like to run every time I open a jupyter notebook (in my case it's opening...
Read more >
How to set up a Python script to run in a Jupyter Notebook on ...
How to set up a Python script to run in a Jupyter Notebook on the cloud ... In it you will be able...
Read more >
How to Execute python code on Jupyter Notebook ... - YouTube
This video will show you steps to use jupyter for executing python code.
Read more >
Debugging in Visual Studio Code
One of the great things in Visual Studio Code is debugging support. Set breakpoints, step-in, inspect variables and more.
Read more >
Live coding discussion - #116 by fmussari - Part 1 2022 - fast.ai ...
You need to open the pre-run.sh file and cd back to /notebooks at the end. It is all described at the beginning of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found