Skip to content

Commit

Permalink
Add poetry (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-bahjati authored Mar 2, 2023
1 parent 6ec6bc8 commit 2e79473
Show file tree
Hide file tree
Showing 17 changed files with 1,728 additions and 53 deletions.
4 changes: 0 additions & 4 deletions setup.cfg → .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[tool:pytest]
addopts = --verbose --strict-markers -p no:doctest
norecursedirs=.git,.venv

[flake8]
count = True
max-line-length=127
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/poetry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Python tests
on:
pull_request:
push:
branches: [main]
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Run image
uses: abatilo/actions-poetry@v2
with:
poetry-version: '1.3.2'
- name: Install dependencies
run: poetry install
- name: Run tests
run: poetry run pytest
97 changes: 92 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,95 @@
FROM python:3.9.12-bullseye
# Reference: https://bmaingret.github.io/blog/2021-11-15-Docker-and-Poetry#multi-stage-build

COPY . /publisher
WORKDIR /publisher
ARG APP_NAME=example-publisher
ARG APP_PACKAGE=example_publisher
ARG APP_PATH=/opt/$APP_NAME
ARG PYTHON_VERSION=3.10.4
ARG POETRY_VERSION=1.2.2

RUN pip install --upgrade setuptools pip && pip install -e .
#
# Stage: base
#

CMD ["python", "-m", "publisher", "--config", "config/config.toml"]
FROM python:$PYTHON_VERSION as base

ARG APP_NAME
ARG APP_PATH
ARG POETRY_VERSION

ENV \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1
ENV \
POETRY_VERSION=$POETRY_VERSION \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1

# Install Poetry - respects $POETRY_VERSION & $POETRY_HOME
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python
ENV PATH="$POETRY_HOME/bin:$PATH"

WORKDIR $APP_PATH
COPY . .

#
# Stage: development
#

FROM base as development

ARG APP_NAME
ARG APP_PATH

WORKDIR $APP_PATH
RUN poetry install

ENV APP_NAME=$APP_NAME

ENTRYPOINT ["poetry", "run"]
CMD ["$APP_NAME"]

#
# Stage: build
#

FROM base as build

ARG APP_NAME
ARG APP_PATH

WORKDIR $APP_PATH
RUN poetry build --format wheel
RUN poetry export --format requirements.txt --output constraints.txt --without-hashes

#
# Stage: production
#

FROM python:$PYTHON_VERSION as production

ARG APP_NAME
ARG APP_PATH

ENV \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1

ENV \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100

# Get build artifact wheel and install it respecting dependency versions
WORKDIR $APP_PATH
COPY --from=build $APP_PATH/dist/*.whl ./
COPY --from=build $APP_PATH/constraints.txt ./
RUN pip install ./*.whl --requirement constraints.txt

COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
CMD ["$APP_NAME"]
5 changes: 5 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

set -e

eval "exec $@"
File renamed without changes.
4 changes: 2 additions & 2 deletions publisher/__main__.py → example_publisher/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import os
import sys
from publisher.config import Config
from publisher.publisher import Publisher
from example_publisher.config import Config
from example_publisher.publisher import Publisher
import typed_settings as ts
import click
import logging
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pycoingecko import CoinGeckoAPI
from structlog import get_logger

from publisher.provider import Price, Provider, Symbol
from example_publisher.provider import Price, Provider, Symbol
from ..config import CoinGeckoConfig

log = get_logger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from structlog import get_logger

from publisher.provider import Price, Provider, Symbol
from example_publisher.provider import Price, Provider, Symbol

from ..config import PythReplicatorConfig

Expand Down
10 changes: 5 additions & 5 deletions publisher/publisher.py → example_publisher/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from typing import Dict, List, Optional
from attr import define
from structlog import get_logger
from publisher.provider import Provider
from example_publisher.provider import Provider

from publisher.providers.coin_gecko import CoinGecko
from publisher.config import Config
from publisher.providers.pyth_replicator import PythReplicator
from publisher.pythd import Pythd, SubscriptionId
from example_publisher.providers.coin_gecko import CoinGecko
from example_publisher.config import Config
from example_publisher.providers.pyth_replicator import PythReplicator
from example_publisher.pythd import Pythd, SubscriptionId


log = get_logger()
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from ..providers.pyth_replicator import manual_aggregate
from example_publisher.providers.pyth_replicator import manual_aggregate


def test_manual_aggregate_works():
Expand Down
Loading

0 comments on commit 2e79473

Please sign in to comment.