Skip to content

Commit

Permalink
Make poetry venv path static
Browse files Browse the repository at this point in the history
- Disable auto venv creation for dev containers
- Manually create the poetry venv with a static path
- Set vscode default interpreter path to the static venv
- Ensure all shells started post container creation auto-activate the venv
  • Loading branch information
whabanks committed Feb 28, 2025
1 parent 4f16210 commit 392e2e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM mcr.microsoft.com/vscode/devcontainers/python:3.12

ENV POETRY_VERSION="1.7.1"
ENV POETRY_VENV_PATH="/home/vscode/.venv/workspace"

RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils 2>&1 \
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"charliermarsh.ruff",
],
"settings": {
"python.pythonPath": "/usr/local/bin/python",
"python.defaultInterpreterPath": "/home/vscode/.venv/workspace/bin/python",
"python.venvPath": "/home/vscode/.venv",
"ruff.lint.ignore": ["F401"],
"ruff.lint.run": "onSave",
"ruff.organizeImports": false,
Expand Down
11 changes: 11 additions & 0 deletions .devcontainer/scripts/notify-dev-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ echo -e "autoload -Uz compinit && compinit"
pip install poetry==${POETRY_VERSION} poetry-plugin-sort \
&& poetry --version


# Disable poetry auto-venv creation
poetry config virtualenvs.create false

# Initialize poetry autocompletions
mkdir ~/.zfunc
touch ~/.zfunc/_poetry
poetry completions zsh > ~/.zfunc/_poetry

# Manually create and activate a virtual environment with a static path
python -m venv "${POETRY_VENV_PATH}"
source "${POETRY_VENV_PATH}/bin/activate"

# Ensure newly created shells activate the poetry venv
echo "source ${POETRY_VENV_PATH}/bin/activate" >> ~/.zshrc

# Install dependencies
poetry install

Expand Down

0 comments on commit 392e2e7

Please sign in to comment.