Skip to content

Commit f054349

Browse files
authored
Use poetry instead of requirements files (#4151)
1 parent c0652e3 commit f054349

File tree

14 files changed

+4497
-600
lines changed

14 files changed

+4497
-600
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,26 @@ jobs:
4949
- name: Apt install
5050
run: cat Aptfile | sudo xargs apt-get install
5151

52+
- name: Install poetry
53+
uses: snok/install-poetry@v1
54+
with:
55+
version: 1.5.1
56+
virtualenvs-create: true
57+
virtualenvs-in-project: true
58+
5259
- uses: actions/setup-python@v4
5360
with:
5461
python-version: '3.11.4'
55-
cache: 'pip'
56-
cache-dependency-path: |
57-
**/requirements.txt
58-
**/test_requirements.txt
62+
cache: 'poetry'
5963

6064
- name: Install dependencies
61-
run: pip install -r requirements.txt -r test_requirements.txt
65+
run: poetry install --no-interaction
6266

6367
- name: Code formatting
64-
run: black --check .
68+
run: poetry run black --check .
6569

6670
- name: Lint
67-
run: pylint ./**/*.py
71+
run: poetry run pylint ./**/*.py
6872

6973
- name: Create test local state
7074
run: ./scripts/test/stub-data.sh

Dockerfile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ RUN mkdir /src
1818
RUN adduser --disabled-password --gecos "" mitodl
1919
RUN mkdir /var/media && chown -R mitodl:mitodl /var/media
2020

21+
# Poetry env configuration
22+
ENV \
23+
# poetry:
24+
POETRY_VERSION=1.5.1 \
25+
POETRY_VIRTUALENVS_CREATE=false \
26+
POETRY_CACHE_DIR='/tmp/cache/poetry'
27+
28+
# Install poetry
29+
RUN pip install "poetry==$POETRY_VERSION"
30+
2131
# Install project packages
22-
COPY requirements.txt /tmp/requirements.txt
23-
COPY test_requirements.txt /tmp/test_requirements.txt
24-
RUN pip install -r requirements.txt -r test_requirements.txt
32+
COPY pyproject.toml /src
33+
COPY poetry.lock /src
34+
WORKDIR /src
35+
RUN poetry install
2536

2637
# Add project
2738
COPY . /src
@@ -31,9 +42,6 @@ RUN chown -R mitodl:mitodl /src
3142
RUN apt-get clean && apt-get purge
3243
USER mitodl
3344

34-
# Set pip cache folder, as it is breaking pip when it is on a shared volume
35-
ENV XDG_CACHE_HOME /tmp/.cache
36-
3745
EXPOSE 8063
3846
ENV PORT 8063
3947
CMD uwsgi uwsgi.ini

app.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
},
2020
{
2121
"url": "https://github.com/heroku/heroku-buildpack-nginx"
22+
},
23+
{
24+
"url": "https://github.com/moneymeets/python-poetry-buildpack"
2225
}
2326
],
2427
"description": "open-discussions",

channels/views/posts_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from rest_framework.request import Request
1010

1111
from profiles.utils import image_uri
12-
from channels.factories.models import LinkMetaFactory
12+
from channels.factories.models import LinkMetaFactory, PostFactory
1313
from channels.constants import (
1414
EXTENDED_POST_TYPE_ARTICLE,
1515
VALID_POST_SORT_TYPES,
@@ -437,6 +437,7 @@ def test_get_post_no_profile(
437437
def test_get_post_forbidden(client, logged_in_profile):
438438
"""Get a post the user doesn't have permission to"""
439439
post_id = "adc"
440+
PostFactory.create(post_id=post_id)
440441
url = reverse("post-detail", kwargs={"post_id": post_id})
441442
resp = client.get(url)
442443
assert resp.status_code == status.HTTP_403_FORBIDDEN
@@ -445,6 +446,7 @@ def test_get_post_forbidden(client, logged_in_profile):
445446
def test_get_post_not_found(client, logged_in_profile):
446447
"""Get a post the user doesn't have permission to"""
447448
post_id = "missing"
449+
PostFactory.create(post_id=post_id)
448450
url = reverse("post-detail", kwargs={"post_id": post_id})
449451
resp = client.get(url)
450452
assert resp.status_code == status.HTTP_404_NOT_FOUND

course_catalog/etl/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import pytz
2020
import rapidjson
2121
import requests
22-
from boto.s3.bucket import Bucket
2322
from django.conf import settings
2423
from django.utils.functional import SimpleLazyObject
2524
from tika import parser as tika_parser
@@ -442,7 +441,7 @@ def get_learning_course_bucket_name(platform: str) -> str:
442441
return bucket_names.get(platform)
443442

444443

445-
def get_learning_course_bucket(platform: str) -> Bucket:
444+
def get_learning_course_bucket(platform: str) -> object:
446445
"""
447446
Get the platform's learning course S3 Bucket holding content file data
448447

course_catalog/etl/youtube_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ def test_get_youtube_transcripts_with_multiple_consecutive_failures(mocker):
571571
mock_caption_call = mocker.patch(
572572
"course_catalog.etl.youtube.get_captions_for_video"
573573
)
574-
mock_caption_call.side_effect = pytube.exceptions.VideoUnavailable
574+
mock_caption_call.side_effect = pytube.exceptions.VideoUnavailable(1)
575575

576576
mock_parse_call = mocker.patch("course_catalog.etl.youtube.parse_video_captions")
577577
mock_upsert_video = mocker.patch("course_catalog.etl.youtube.upsert_video")

course_catalog/views_stafflist_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from course_catalog.utils import update_editor_group
1616
from open_discussions.factories import UserFactory
1717

18-
# pylint:disable=redefined-outer-name
18+
# pylint:disable=redefined-outer-name,unused-argument
1919

2020

2121
@pytest.fixture()
@@ -118,7 +118,9 @@ def test_staff_list_endpoint_create( # pylint: disable=too-many-arguments
118118
@pytest.mark.parametrize("is_public", [True, False])
119119
@pytest.mark.parametrize("is_editor", [True, False])
120120
@pytest.mark.parametrize("update_topics", [True, False])
121-
def test_staff_list_endpoint_patch(client, update_topics, is_public, is_editor):
121+
def test_staff_list_endpoint_patch(
122+
client, mock_staff_list_index, update_topics, is_public, is_editor
123+
):
122124
"""Test stafflist endpoint for updating a StaffList"""
123125
[original_topic, new_topic] = CourseTopicFactory.create_batch(2)
124126
user = UserFactory.create()

0 commit comments

Comments
 (0)