Skip to content

Commit 68a63ed

Browse files
authored
Convert to use Poetry for Python dependency management (#1060)
1 parent 4bed671 commit 68a63ed

File tree

14 files changed

+3573
-378
lines changed

14 files changed

+3573
-378
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ jobs:
3232

3333
- name: Apt install
3434
run: cat Aptfile | sudo xargs apt-get install
35+
36+
- name: Install poetry
37+
uses: snok/install-poetry@v1
38+
with:
39+
version: 1.5.1
40+
virtualenvs-create: true
41+
virtualenvs-in-project: true
3542

3643
- name: Set up Python
37-
uses: actions/setup-python@v2
44+
uses: actions/setup-python@v4
3845
with:
3946
python-version: "3.9.13"
40-
41-
- id: cache
42-
uses: actions/cache@v1
43-
with:
44-
path: ~/.cache/pip
45-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/test_requirements.txt') }}
46-
restore-keys: |
47-
${{ runner.os }}-pip-
47+
cache: poetry
4848

4949
- name: Install dependencies
50-
run: pip install -r requirements.txt -r test_requirements.txt
50+
run: poetry install --no-interaction
5151

5252
- name: Code formatting
53-
run: black --check .
53+
run: poetry run black --check .
5454

5555
- name: Lint
56-
run: pylint ./**/*.py
56+
run: poetry run pylint ./**/*.py
5757

5858
- name: Tests
5959
run: |

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ repos:
44
hooks:
55
- id: detect-secrets
66
args: ['--baseline', '.secrets.baseline']
7-
exclude: .*_test.*|.*\.rst
7+
exclude: .*_test.*|.*\.rst|poetry.lock

Dockerfile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,27 @@ RUN mkdir /src
2727
RUN adduser --disabled-password --gecos "" mitodl
2828
RUN mkdir /var/media && chown -R mitodl:mitodl /var/media
2929

30+
# Poetry env configuration
31+
ENV \
32+
# poetry:
33+
POETRY_VERSION=1.5.1 \
34+
POETRY_VIRTUALENVS_CREATE=false \
35+
POETRY_CACHE_DIR='/tmp/cache/poetry'
36+
37+
# Install poetry
38+
RUN pip install "poetry==$POETRY_VERSION"
39+
3040
# Install project packages
31-
COPY requirements.txt /tmp/requirements.txt
32-
RUN pip install -r requirements.txt
41+
COPY pyproject.toml /src
42+
COPY poetry.lock /src
43+
WORKDIR /src
44+
RUN poetry install --no-dev
3345

3446
# Add project
3547
COPY . /src
36-
WORKDIR /src
3748
RUN chown -R mitodl:mitodl /src
3849
USER mitodl
3950

40-
# Set pip cache folder, as it is breaking pip when it is on a shared volume
41-
ENV XDG_CACHE_HOME /tmp/.cache
42-
4351
EXPOSE 8089
4452
ENV PORT 8089
4553
CMD uwsgi uwsgi.ini
@@ -56,7 +64,5 @@ USER mitodl
5664
# like to run alone for some reasont
5765
FROM base AS development
5866
USER root
59-
COPY test_requirements.txt /tmp/test_requirements.txt
60-
RUN pip install -r /tmp/requirements.txt -r /tmp/test_requirements.txt
61-
RUN chown -R mitodl:mitodl /tmp/.cache
67+
RUN poetry install
6268
USER mitodl

conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ def warnings_as_errors():
2424
message="'async' and 'await' will become reserved keywords in Python 3.7",
2525
category=DeprecationWarning,
2626
)
27-
27+
warnings.filterwarnings(
28+
"ignore",
29+
message="stream argument is deprecated. Use stream parameter in request directly",
30+
category=DeprecationWarning,
31+
)
2832
yield
2933
finally:
3034
warnings.resetwarnings()

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ services:
4343
DOCKER_HOST: ${DOCKER_HOST:-missing}
4444
WEBPACK_DEV_SERVER_HOST: ${WEBPACK_DEV_SERVER_HOST:-localhost}
4545
DOCKER_HOST: ${DOCKER_HOST:-missing}
46-
FIELD_ENCRYPTION_KEY: jtma0CL1QMRLaJgjXNlJh3mtPNcgok0G5ajRCMZ_XNI=
46+
FIELD_ENCRYPTION_KEY: jtma0CL1QMRLaJgjXNlJh3mtPNcgok0G5ajRCMZ_XNI= # pragma: allowlist secret
4747
env_file: .env
4848

4949

0 commit comments

Comments
 (0)