infra: fix how Poetry is installed in the dev container (#20521)

Currently, when a new dev container is created, poetry does not work in
it with the error "No module named 'rapidfuzz'".

Install Poetry outside the project venv so that poetry and project
dependencies do not get mixed. Use pipx to install poetry securely in
its own isolated environment.

Issue: #12237

Twitter handle: https://twitter.com/ibratoev

Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
This commit is contained in:
Ivaylo Bratoev 2024-04-25 03:33:25 +03:00 committed by GitHub
parent c2d09a5186
commit 7c5063ef60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,10 +14,14 @@ ARG PYTHON_VIRTUALENV_HOME=/home/vscode/langchain-py-env \
ENV POETRY_VIRTUALENVS_IN_PROJECT=false \ ENV POETRY_VIRTUALENVS_IN_PROJECT=false \
POETRY_NO_INTERACTION=true POETRY_NO_INTERACTION=true
# Create a Python virtual environment for Poetry and install it # Install Poetry outside of the v`irtual environment to avoid conflicts
RUN python3 -m pip install --user pipx && \
python3 -m pipx ensurepath && \
pipx install poetry==${POETRY_VERSION}
# Create a Python virtual environment for the project
RUN python3 -m venv ${PYTHON_VIRTUALENV_HOME} && \ RUN python3 -m venv ${PYTHON_VIRTUALENV_HOME} && \
$PYTHON_VIRTUALENV_HOME/bin/pip install --upgrade pip && \ $PYTHON_VIRTUALENV_HOME/bin/pip install --upgrade pip
$PYTHON_VIRTUALENV_HOME/bin/pip install poetry==${POETRY_VERSION}
ENV PATH="$PYTHON_VIRTUALENV_HOME/bin:$PATH" \ ENV PATH="$PYTHON_VIRTUALENV_HOME/bin:$PATH" \
VIRTUAL_ENV=$PYTHON_VIRTUALENV_HOME VIRTUAL_ENV=$PYTHON_VIRTUALENV_HOME