Skip to content

Commit

Permalink
Use poetry for python dependency management (#1766)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertrand authored Aug 3, 2023
1 parent e14ce1b commit 2195a66
Show file tree
Hide file tree
Showing 14 changed files with 4,426 additions and 618 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,27 @@ jobs:
- name: Apt install
run: cat Aptfile | sudo xargs apt-get install

- name: Install poetry
uses: snok/install-poetry@v1
with:
version: 1.5.1
virtualenvs-create: true
virtualenvs-in-project: true

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9.6"

- id: cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/test_requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: pip install -r requirements.txt -r test_requirements.txt
run: poetry install --no-interaction

# disabled for now because it's broken for some reason
# - name: Lint
# run: pylint ./**/*.py

- name: Code Formatting (Black)
run: black --check .
run: poetry run black --check .

# Configurations required for elasticsearch.
- name: Configure sysctl limits
Expand Down
30 changes: 25 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,36 @@ RUN mkdir /app
RUN adduser --disabled-password --gecos "" mitodl
RUN mkdir /var/media && chown -R mitodl:mitodl /var/media

# Poetry env configuration
ENV \
# poetry:
POETRY_VERSION=1.5.1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR='/tmp/cache/poetry' \
POETRY_HOME='/home/mitodl/.local' \
VIRTUAL_ENV="/opt/venv"
ENV PATH="$VIRTUAL_ENV/bin:$POETRY_HOME/bin:$PATH"

# Install project packages
COPY requirements.txt /tmp/requirements.txt
COPY test_requirements.txt /tmp/test_requirements.txt
RUN pip install -r requirements.txt -r test_requirements.txt
COPY pyproject.toml /app
COPY poetry.lock /app
RUN chown -R mitodl:mitodl /app
RUN mkdir ${VIRTUAL_ENV} && chown -R mitodl:mitodl ${VIRTUAL_ENV}

USER mitodl
RUN curl -sSL https://install.python-poetry.org \
| \
POETRY_VERSION=${POETRY_VERSION} \
POETRY_HOME=${POETRY_HOME} \
python3 -q
WORKDIR /app
RUN python3 -m venv $VIRTUAL_ENV
RUN poetry install

# Add project
COPY . /app
WORKDIR /app
RUN chown -R mitodl:mitodl /app

USER root
RUN apt-get clean && apt-get purge

# Set pip cache folder, as it is breaking pip when it is on a shared volume
Expand Down
1 change: 0 additions & 1 deletion RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1681,4 +1681,3 @@ Version 0.1.0 (Released August 04, 2021)
- Fix flaky util test
- Add courses app
- Added Wagtail and initial model definitions

3 changes: 3 additions & 0 deletions app.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
{
"url": "https://github.com/heroku/heroku-buildpack-nodejs"
},
{
"url": "https://github.com/moneymeets/python-poetry-buildpack"
},
{
"url": "https://github.com/heroku/heroku-buildpack-python"
},
Expand Down
5 changes: 4 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
{
"url": "https://github.com/heroku/heroku-buildpack-nodejs"
},
{
"url": "https://github.com/moneymeets/python-poetry-buildpack"
},
{
"url": "https://github.com/heroku/heroku-buildpack-python"
},
Expand Down Expand Up @@ -579,4 +582,4 @@
},
"success_url": "/",
"website": "https://github.com/mitodl/mitx-online"
}
}
6 changes: 3 additions & 3 deletions authentication/middleware_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_process_exception_no_strategy(rf, settings):
def test_process_exception(rf, settings):
"""Tests that a process_exception handles auth exceptions correctly"""
settings.DEBUG = False
msg = "error message"
request = rf.get(reverse("social:complete", args=("email",)))
# social_django depends on request.sesssion, so use the middleware to set that
SessionMiddleware().process_request(request)
Expand All @@ -30,10 +29,11 @@ def test_process_exception(rf, settings):
request.backend = backend

middleware = SocialAuthExceptionRedirectMiddleware()
result = middleware.process_exception(request, AuthAlreadyAssociated(backend, msg))
error = AuthAlreadyAssociated(backend)
result = middleware.process_exception(request, error)
assert result.status_code == status.HTTP_302_FOUND
assert result.url == "{}?message={}&backend={}".format(
reverse("login"), urlquote(msg), backend.name
reverse("login"), urlquote(error.__str__()), backend.name
)


Expand Down
Loading

0 comments on commit 2195a66

Please sign in to comment.