Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade template #4

Merged
merged 2 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2017-2020, Project Jupyter Contributors
Copyright (c) 2017-2023, Project Jupyter Contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
52 changes: 31 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
# JupyterLab debug-config-cookiecutter
# JupyterLab Visual Studio Code configurator

A [cookiecutter](https://github.com/audreyr/cookiecutter) template for creating the IDE config needed to debug the Python and Typescript code in Jupyter projects. Works with both JupyterLab core and any extension.
A [copier](https://copier.readthedocs.io/en/stable/) template for creating
the Visual Studio Code configuration needed to debug the Python and Typescript
code in Jupyter extension projects.

Currently only supports vscode. PRs for setting up other debug tools/techniques are welcome.
It will add:

## Setup vscode debugging for any JupyterLab Extension
- Debug configuration to debug your code in Visual Studio Code
- Development container (can be used to develop within a container)

Install cookiecutter.
## Setup Visual Studio Code for extensions

> The best is to run this on project generated by the [extension template](https://github.com/jupyterlab/extension-template).

1. Install copier.

```bash
pip install cookiecutter
pip install copier
```

Navigate to the root of your Jupyter project, then run
2. Navigate to the root of your Jupyter project, then run

```bash
cookiecutter gh:jupyterlab/debug-config-cookiecutter
copier -a .copier-answer.vscode.yml copy https://github.com/jupyterlab/vscode-config-template .
```

A number of prompts will pop up. DO NOT CHANGE `vscode_config_path`. Answer the rest of the prompts as appropriate for your project
3. Answer the options questions

Install the debug dev dependencies
4. Install the extension

```bash
jlpm install
```shell
pip install -e ".[test]"
jupyter labextension develop . --overwrite
# Server extension must be manually enabled in develop mode
# jupyter server extension enable <python_name>
```

Build the extension, this will generate the source maps for front-end debugging
5. Optional, start watching your extension source changes

```bash
jlpm build
```shell
jlpm run watch
```

Inside vscode, use the newly added "jlab debug" or "jlab debug (watch)" targets to start debugging.
6. Inside Visual Studio Code Debug panel, use _Debug JupyterLab with Chrome_.

## Troubleshooting
## Update configuration

- `Error: ".vscode" directory already exists`: you'll need to delete the existing `.vscode` dir at your project's root. You can force cookiecutter to overwrite the existing dir with:
To update the configuration to a newer version of the template, execute:

```bash
cookiecutter gh:jupyterlab/debug-config-cookiecutter -f
```
```shell
copier -a .copier-answer.vscode.yml update
```
7 changes: 0 additions & 7 deletions cookiecutter.json

This file was deleted.

14 changes: 14 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
_min_copier_version: "7.1.0"
_subdirectory: template
_tasks:
# Create notebooks_dir
- ["{{ _copier_python }}", "-c", "from pathlib import Path; Path('{{ notebooks_dir }}').mkdir(parents=True, exist_ok=True)"]

notebooks_dir:
type: str
help: Directory to start JupyterLab with in
default: "notebooks"
virtual_env_root:
type: str
help: Python virtual env prefix (leave empty if you use Python extension)
default: ""
17 changes: 17 additions & 0 deletions template/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM mcr.microsoft.com/devcontainers/miniconda:0-3

# Copy environment.yml (if found) to a temp location so we update the environment.
COPY environment.yml /tmp/conda-tmp/
RUN /opt/conda/bin/conda config --add channels conda-forge \
&& /opt/conda/bin/conda config --remove channels defaults \
&& /opt/conda/bin/conda install -y mamba
RUN umask 0002 && /opt/conda/bin/mamba env update -n base -f /tmp/conda-tmp/environment.yml

# [Optional] Uncomment to install a different version of Python than the default
# RUN mamba install -y python=3.6 \
# && pip install --no-cache-dir pipx \
# && pipx reinstall-all

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
33 changes: 33 additions & 0 deletions template/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/miniconda
{
"name": "Miniconda (Python 3)",
"build": {
"context": "..",
"dockerfile": "Dockerfile"
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "python --version",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"meganrogge.template-string-converter",
"ms-python.python"
]
}
}

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% if cookiecutter.virtual_env_root -%}
{% if virtual_env_root -%}
# set VIRTUAL_ENV to the root of your venv
VIRTUAL_ENV="{{ cookiecutter.virtual_env_root }}"
VIRTUAL_ENV="{{ virtual_env_root }}"

# jupyter env vars
JUPYTER_CONFIG_DIR="${VIRTUAL_ENV}/etc/jupyter"
Expand Down
8 changes: 8 additions & 0 deletions template/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"meganrogge.template-string-converter",
"ms-python.python"
]
}
47 changes: 47 additions & 0 deletions template/.vscode/launch.json.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
// To debug jupyterlab running in a venv or conda env:
// - set up Python env in your workspace as per https://code.visualstudio.com/docs/python/environments
// - add an "envFile" prop to each backend config pointing to .vscode/debug.env
// - configure the .vscode/debug.env file as needed
"version": "0.2.0",
"configurations": [
{
"name": "JupyterLab backend",
"type": "python",
"request": "launch",
"args": [
"--notebook-dir={{ notebooks_dir }}",
"--no-browser",
"--ServerApp.token=''",
"--port=9999"
],
"justMyCode": false,
"module": "jupyterlab.labapp",
"presentation": {
"hidden": true
}{% if virtual_env_root -%},
"envFile": "${workspaceFolder}/.vscode/debug.env"{%- endif %}
},
{
"name": "JupyterLab in Chrome",
"type": "chrome",
"request": "launch",
"timeout": 180000,
"url": "http://localhost:9999/lab",
// set webroot to the parent dir of your project's top level package.json
"webRoot": "${workspaceFolder}",
"presentation": {
"hidden": true
}
}
],
"compounds": [
{
"name": "Debug JupyterLab with Chrome",
"configurations": [
"JupyterLab backend",
"JupyterLab in Chrome"
]
}
]
}
5 changes: 5 additions & 0 deletions template/.vscode/settings.json.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
{% if virtual_env_root -%}
"python.defaultInterpreterPath": "{{ virtual_env_root }}/bin/python"
{%- endif %}
}
12 changes: 12 additions & 0 deletions template/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Extension development environment
channels:
- conda-forge
- conda-forge/label/jupyterlab_beta

dependencies:
# runtime dependencies
- python >=3.10,<3.11.0a0
- jupyterlab >=4.0.0b0,<5
# labextension build dependencies
- nodejs >=18,<19
- pip
2 changes: 2 additions & 0 deletions template/{{_copier_conf.answers_file}}.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
{{_copier_answers|to_nice_yaml}}
79 changes: 0 additions & 79 deletions {{cookiecutter.vscode_config_path}}/launch.json

This file was deleted.

5 changes: 0 additions & 5 deletions {{cookiecutter.vscode_config_path}}/settings.json

This file was deleted.