Skip to content

Commit b8f6416

Browse files
Fix Poetry 1.2 Support
Poetry 1.2 introduced a regression which broke pip `--user` installs. These types of install where the main way we did installations in docker and CI, which made it much more convenient to control their location, availability, and caching. Poetry's team does not recognize this as a supported use case, so major changes were required to get everything working again. Most of the changes were consolidated into chrislovering/python-poetry-base for docker, and hassanabouelela/setup-python for CI. Signed-off-by: Hassan Abouelela <[email protected]>
1 parent 20a7264 commit b8f6416

File tree

2 files changed

+11
-68
lines changed

2 files changed

+11
-68
lines changed

.github/workflows/lint-test.yaml

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,26 @@ on:
1010
jobs:
1111
lint-test:
1212
runs-on: ubuntu-latest
13-
env:
14-
# Configure pip to cache dependencies and do a user install
15-
PIP_NO_CACHE_DIR: false
16-
PIP_USER: 1
17-
18-
# Make sure package manager does not use virtualenv
19-
POETRY_VIRTUALENVS_CREATE: false
20-
21-
# Specify explicit paths for python dependencies and the pre-commit
22-
# environment so we know which directories to cache
23-
POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/py-user-base
24-
PYTHONUSERBASE: ${{ github.workspace }}/.cache/py-user-base
25-
PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache
2613

2714
steps:
28-
- name: Add custom PYTHONUSERBASE to PATH
29-
run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH
30-
3115
- name: Checkout repository
3216
uses: actions/checkout@v2
3317

34-
- name: Setup python
35-
id: python
36-
uses: actions/setup-python@v2
18+
- name: Install Python Dependencies
19+
uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.1
3720
with:
38-
python-version: '3.9'
21+
dev: true
22+
python_version: '3.9'
3923

4024
# Start the database early to give it a chance to get ready before
4125
# we start running tests.
4226
- name: Run database using docker-compose
4327
run: docker-compose run -d -p 7777:5432 --name pydis_web postgres
4428

45-
# This step caches our Python dependencies. To make sure we
46-
# only restore a cache when the dependencies, the python version,
47-
# the runner operating system, and the dependency location haven't
48-
# changed, we create a cache key that is a composite of those states.
49-
#
50-
# Only when the context is exactly the same, we will restore the cache.
51-
- name: Python Dependency Caching
52-
uses: actions/cache@v2
53-
id: python_cache
54-
with:
55-
path: ${{ env.PYTHONUSERBASE }}
56-
key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\
57-
${{ steps.python.outputs.python-version }}-\
58-
${{ hashFiles('./pyproject.toml', './poetry.lock') }}"
59-
60-
# Install our dependencies if we did not restore a dependency cache
61-
- name: Install dependencies using poetry
62-
if: steps.python_cache.outputs.cache-hit != 'true'
63-
run: |
64-
pip install poetry
65-
poetry install
66-
67-
# This step caches our pre-commit environment. To make sure we
68-
# do create a new environment when our pre-commit setup changes,
69-
# we create a cache key based on relevant factors.
70-
- name: Pre-commit Environment Caching
71-
uses: actions/cache@v2
72-
with:
73-
path: ${{ env.PRE_COMMIT_HOME }}
74-
key: "precommit-0-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\
75-
${{ steps.python.outputs.python-version }}-\
76-
${{ hashFiles('./.pre-commit-config.yaml') }}"
77-
7829
# We will not run `flake8` here, as we will use a separate flake8
79-
# action. As pre-commit does not support user installs, we set
80-
# PIP_USER=0 to not do a user install.
30+
# action.
8131
- name: Run pre-commit hooks
82-
run: export PIP_USER=0; SKIP=flake8 pre-commit run --all-files
32+
run: SKIP=flake8 pre-commit run --all-files
8333

8434
# Run flake8 and have it format the linting errors in the format of
8535
# the GitHub Workflow command to register error annotations. This

Dockerfile

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
FROM --platform=linux/amd64 python:3.9-slim-buster
1+
FROM ghcr.io/chrislovering/python-poetry-base:3.9-slim
22

33
# Allow service to handle stops gracefully
44
STOPSIGNAL SIGQUIT
55

6-
# Set pip to have cleaner logs and no saved cache
7-
ENV PIP_NO_CACHE_DIR=false \
8-
POETRY_VIRTUALENVS_CREATE=false
9-
10-
# Install poetry
11-
RUN pip install -U poetry
12-
136
# Copy the project files into working directory
147
WORKDIR /app
158

169
# Install project dependencies
1710
COPY pyproject.toml poetry.lock ./
18-
RUN poetry install --no-dev
11+
RUN poetry install --without dev
1912

2013
# Set Git SHA environment variable
2114
ARG git_sha="development"
@@ -34,14 +27,14 @@ RUN \
3427
SECRET_KEY=dummy_value \
3528
DATABASE_URL=postgres://localhost \
3629
METRICITY_DB_URL=postgres://localhost \
37-
python manage.py collectstatic --noinput --clear
30+
poetry run python manage.py collectstatic --noinput --clear
3831

3932
# Build static files if we are doing a static build
4033
ARG STATIC_BUILD=false
4134
RUN if [ $STATIC_BUILD = "TRUE" ] ; \
42-
then SECRET_KEY=dummy_value python manage.py distill-local build --traceback --force ; \
35+
then SECRET_KEY=dummy_value poetry run python manage.py distill-local build --traceback --force ; \
4336
fi
4437

4538
# Run web server through custom manager
46-
ENTRYPOINT ["python", "manage.py"]
39+
ENTRYPOINT ["poetry", "run", "python", "manage.py"]
4740
CMD ["run"]

0 commit comments

Comments
 (0)