Skip to content

Commit 265ccb2

Browse files
authored
Make poetry venv path static (#356)
- 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
1 parent 699cd43 commit 265ccb2

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

.devcontainer/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM mcr.microsoft.com/vscode/devcontainers/python:3.12
22

33
ENV POETRY_VERSION="1.7.1"
4+
ENV POETRY_VENV_PATH="/home/vscode/.venv/workspace"
45

56
RUN apt-get update \
67
&& apt-get -y install --no-install-recommends apt-utils 2>&1 \

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"charliermarsh.ruff",
2323
],
2424
"settings": {
25-
"python.pythonPath": "/usr/local/bin/python",
25+
"python.defaultInterpreterPath": "/home/vscode/.venv/workspace/bin/python",
26+
"python.venvPath": "/home/vscode/.venv",
2627
"ruff.lint.ignore": ["F401"],
2728
"ruff.lint.run": "onSave",
2829
"ruff.organizeImports": false,

.devcontainer/scripts/notify-dev-entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@ echo -e "autoload -Uz compinit && compinit"
1414
pip install poetry==${POETRY_VERSION} poetry-plugin-sort \
1515
&& poetry --version
1616

17+
18+
# Disable poetry auto-venv creation
19+
poetry config virtualenvs.create false
20+
1721
# Initialize poetry autocompletions
1822
mkdir ~/.zfunc
1923
touch ~/.zfunc/_poetry
2024
poetry completions zsh > ~/.zfunc/_poetry
2125

26+
# Manually create and activate a virtual environment with a static path
27+
python -m venv "${POETRY_VENV_PATH}"
28+
source "${POETRY_VENV_PATH}/bin/activate"
29+
30+
# Ensure newly created shells activate the poetry venv
31+
echo "source ${POETRY_VENV_PATH}/bin/activate" >> ~/.zshrc
32+
2233
# Install dependencies
2334
poetry install
2435

0 commit comments

Comments
 (0)