Skip to content

Commit

Permalink
chore: create python devcontainer first version
Browse files Browse the repository at this point in the history
  • Loading branch information
kjbrak committed Sep 20, 2024
1 parent 2190f99 commit 87bcefc
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 1 deletion.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"git": "latest",
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {}
}
}
}
46 changes: 46 additions & 0 deletions .devcontainer/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
ARG VARIANT="3.11-bookworm"
FROM mcr.microsoft.com/devcontainers/python:${VARIANT}


ARG DEBIAN_FRONTEND=noninteractive
ARG POETRY_VERSION=1.8.3
ARG POETRY_VIRTUALENVS_PATH
ENV USER=vscode

RUN DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y build-essential --no-install-recommends make \
ca-certificates \
git \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncurses5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
default-jre

# Set non-root user
USER $USER
ENV HOME="/home/$USER"
ENV PATH="${HOME}/.local/bin:$PATH"

# Set poetry virtualenv path in writable dir outsde mounted workspace
ENV POETRY_VIRTUALENVS_PATH="$HOME/.venv"

# Python and poetry installation
RUN echo $(which python) && echo $(which python3) \
&& python3 -m pip install --upgrade pip pipx \
&& pipx install "poetry==${POETRY_VERSION}" \
&& pip install pre-commit \
&& poetry --version \
&& pre-commit --version
50 changes: 50 additions & 0 deletions .devcontainer/python/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "eCalc Python Dev Environment",
"build": {
"dockerfile": "Dockerfile",
"context": "../..",
"args": {
"VARIANT": "3.11-bookworm",
"POETRY_VERSION": "1.8.3",
}
},
"containerEnv": {
"POETRY_VIRTUALENVS_CREATE": "true",
"POETRY_VIRTUALENVS_IN_PROJECT": "false",
"PIP_DEFAULT_TIMEOUT": "100",
},
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "${containerEnv:POETRY_VIRTUALENVS_PATH}/bin/python",
"python.testing.pytestArgs": [],
"python.testing.cwd": "${workspaceFolder}/src/tests",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"ruff.enabled": true,
"terminal.integrated.defaultProfile.linux": "bash",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
}
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"github.copilot",
"eamodio.gitlens",
"charliermarsh.ruff",
"shardulm94.trailing-spaces",
]
}
},
"remoteUser": "vscode",
"features": {
"github-cli": "latest"
},
"postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && bash ./.devcontainer/python/post-create.sh",
// "mounts": [
// // TODO: Reuse poetry cache between builds
// "source=,target=/home/vscode/.cache/pypoetry,type=bind,consistency=cached"
// ]
}
14 changes: 14 additions & 0 deletions .devcontainer/python/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e

# Install Poetry dependencies
echo "Installing Poetry dependencies..."
poetry install

# Install Pre-commit hooks
echo "Installing Pre-commit hooks..."
pre-commit install

echo "Post-create script completed successfully."

0 comments on commit 87bcefc

Please sign in to comment.