cogent3 / Cogent3Workshop

Materials for the Phylomania workshop
BSD 3-Clause "New" or "Revised" License
8 stars 4 forks source link

Focus the usage on VS code #33

Closed GavinHuttley closed 11 months ago

GavinHuttley commented 11 months ago

Currently getting VS code working is tedious

I get VS code connecting, I also get a notebook created. But when I try to run print() I get

Running cells with '/bin/python3' requires the ipykernel package.
Run the following command to install 'ipykernel' into the Python environment. 
Command: '/bin/python3 -m pip install ipykernel -U --user --force-reinstall'

The VS Code terminal environment is bash, not zsh+ ohmyzh. Possibly configuring this in the VS Code and including the settings json in the Docker image will solve this.

khiron commented 11 months ago

RE: preconfiguring the container for VS Code extensions and settings

When you are asked by VS Code if you want to install an extension in a container, it doesn't change the container, it just adding a file to the host OS for that container.

So in /Users/richard/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/imageConfigs there is a file called my workshop.json which contains everything "installed" to the container

{ "extensions": [ "ms-python.python", "ms-python.vscode-pylance", "ms-toolsai.jupyter", "ms-toolsai.jupyter-keymap", "ms-toolsai.jupyter-renderers", "ms-toolsai.vscode-jupyter-cell-tags", "ms-toolsai.vscode-jupyter-slideshow" ], "workspaceFolder": "/", "settings": { "terminal.integrated.defaultProfile.linux": "zsh" } }

So there is nothing I can put in the container that will install VS Code extensions.

There may be something I can do with DevContainers which is a Microsoft super specification for DockerFiles. Looking into it.

khiron commented 11 months ago

ZSH is installed in the container and set as the default shell as follows;

# Install Oh My Zsh
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended

# Set zsh as the default shell
SHELL ["/usr/bin/zsh", "-c"]

# Create a default .zshrc file with some suggested configurations
RUN echo 'export ZSH="$HOME/.oh-my-zsh"' >> $HOME/.zshrc && \
    echo 'ZSH_THEME="robbyrussell"' >> $HOME/.zshrc && \
    echo 'plugins=(git zsh-autosuggestions zsh-syntax-highlighting autojump)' >> $HOME/.zshrc && \
    echo 'source $ZSH/oh-my-zsh.sh' >> $HOME/.zshrc && \
    echo 'export HISTFILE=~/.zsh_history' >> $HOME/.zshrc && \
    echo 'export HISTSIZE=10000' >> $HOME/.zshrc && \
    echo 'export SAVEHIST=10000' >> $HOME/.zshrc && \
    echo 'setopt appendhistory' >> $HOME/.zshrc && \
    echo 'setopt histignorespace' >> $HOME/.zshrc && \
    echo 'setopt histignorealldups' >> $HOME/.zshrc && \
    echo 'source /c3workshop/bin/activate' >> $HOME/.zshrc

# Install zsh-autosuggestions and zsh-syntax-highlighting plugins
RUN git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions && \
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

So running the container with the run command "/usr/bin/zsh" instead of "bin/bash" should work

I've changed the terminal mode wiki page to reflect that

https://github.com/cogent3/Cogent3Workshop/wiki/terminal-mode

VS needs to be prepopulated with "terminal.integrated.defaultProfile.linux": "zsh" to be the default shell in it's terminal. Working on that

khiron commented 11 months ago

I was mistaken about the vscode-server/extensions. prepopulating with a 45MB extra payload and hard coding the extensions that exist today is a hack but it works.

I have a simpler solution (in branch https://github.com/cogent3/Cogent3Workshop/blob/code-server/ ) by installing code-server (the open source VS code on a browser project) into the container which can populate the extensions by name - downloading the latest automatically upon first time use of the container.

Working on a branch using devcontainer (https://github.com/cogent3/Cogent3Workshop/tree/devcontainer) that appears to be the preferred Microsoft solution for using containers in vs code. All extensions and vs code setting are predefined in the devcontainer file independently of the DockerFile and VS code manages teh building and running of the container ... so it will need almost no command line work. Just point and click in VS code to build a container, run it and work with it