To run linter and static analysis tools in your local environment, install the following:
- ruff
- mypy
make build: build docker containermake run HOST_JUPYTER_PORT=8888: run a jupyterlab server locally and expose it to the port 8888make rm: remove the notebook containermake unittest: run unittestsmake unittest TEST_OPTS="-k test_run": run only the tests matching the patternmake logs: show logsmake bash: enter a shell session in the containermake lint: check lint (requires to runmake install-linters)make fix-lint: fixes lint errors (requires to runmake install-linters)make clean: removes all temporary files (may require sudo)
Pre-requisites
- Install vscode
- Recent docker version (>17)
- Install vscode remote-containers extension with
code --install-extension ms-vscode-remote.vscode-remote-extensionpack
How-to 📖
-
🔨 Build the remote container
- Clone and open this repository with vscode
- Open the Command Palette and select Remote-Containers: Rebuild and Reopen in Container...
- Select the root directory of this repo, wait for the container to start, and try things out!
-
📜 Show logs
- Open the Command Palette → select
Output: Focus on Output View
- Open the Command Palette → select
-
⌨️ Open a terminal
- Open the Command Palette → select
Terminal: Create New Terminal
- Open the Command Palette → select
-
✏️ Edit code
- Open
main.py - Try adding some code and check out the language features.
- Try auto-complete: hit
cmd+space
- Open
-
🏃 Run a file
- Go to
src/play/main.py - Open the Command Palette ->
Python: Run python file in terminal
- Go to
-
🐛 Debug
- Open
main.py - Add a breakpoint on any line (at the left of a pan, before the line number)
- Press
F5to launch the debugger -> selectrun the current file in debug mode - Once the breakpoint is hit, try hovering over variables, examining locals, etc.
- Go to the debug console (in the same pane as the terminal) to directly interract with the variables!
- Open
-
✔️ Run test
- Go to
tests/test_main.py - Open the Command Palette ->
Test: Run Test at Cursorto select a single test function - To debug a test:
- set breakpoints
- Open the Command Palette ->
Test: Debug Test at Cursor
- Go to
-
📓 Run a jupyter notebook inside the devcontainer
- Make sure that
"jupyter.jupyterServerType": "local"is set in in.vscode/settings.json - Make sure that your vscode is running in the devcontainer
- Open the
sample.ipynbfile - If requested, select the python interpreter installed in your docker image
- Select a cell and run it with
ctrl+enter(same as in usual jupyter notebook webui)
- Make sure that
-
🔁 Run a python interactive window
- Go to
main.py - Open the Command Palette ->
Jupyter: Run current file in interactive window - If requested, select the python interpreter installed in your docker image
- Type
# %%to split cells in themain.py - Type
shift + enterto run a cell and go to next cell - Type
ctrl + enterto run cell (and stay in the same cell) - Type
help(somefunc)and execute it to show full docstring
- Go to
-
📓 + 🪐 Run a jupyter notebook in a remote jupyter server
- Make sure that your vscode is not running in your decontainer!
- Start manually your jupyter server locally (for instance) by typing
jupyter notebook . - Copy the uri and the token generated in the terminal
- Go to
notebooks/sample.ipynb - Open the Command Palette ->
jupyter: specify local or remote server - Paste the jupyter server uri with the token in the box
- Click on popup to reload workspace
- Try to run a cell in the notebook
- On the popup, select the python kernel you want to use
- You can run the notebook!
Warning! There are several potential issues with using a remote jupyter server: it does not behave as you would expect.
- You cannot connect to an existing kernel.
- The lifecycle if bound to your vscode session:
- When you close your editor, ther kernel will be killed.
- You cannot execute jobs in the remote jupyter kernel overnight because of this! For such use cases, it is recommended to simply use the standard jupyter notebook/lab interface.
- See this github issue for more details and how it should be resolved.
-
🔨🔨 Rebuild a container in vscode devcontainer
This is needed when you change a dependency, the
Dockerfile, extensions or some other setting, etc.- Open the Command Palette -> select
Remote-Containers: Rebuild Container - Open the Command Palette -> select
Remote-Containers: Rebuild Container without cache - Note that your extensions are also cached in a docker volume by default. To force rebuilding it, delete first the volume with
docker volume rm play-vscode-analytics-extensions-cache-volume(the volume is declared insettings.json). Doc.
- Open the Command Palette -> select
- Auto-generate docstring for functions by typing
"""and thenEnter. - Add this to the top of a notebook to enable autoreload of python source files
%load_ext autoreload
%autoreload 2
- If a file is slow to save, try disabling the actions on save such as formatting, linting, etc. in the
settings.json - To improve build time, you may enable
DOCKER_BUILDKIT=1in your environment or in the Docker Desktop app - Type
F8to cycle through errors
- Boostrapped thanks to this vscode-devcontainer-python-cookiecutter
- Vscode documentation: