Merge pull request #60 from grillazz/56-replace-pipenv-with-poetry

add poetry to project
This commit is contained in:
Jakub Miazek 2022-11-04 10:26:30 +01:00 committed by GitHub
commit 16fb7b5406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 2145 additions and 1381 deletions

View File

@ -1,14 +1,15 @@
name: Unit Tests
on: [pull_request]
name: Continuous Disaster...
on:
pull_request:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10"]
python-version: ["3.10"]
fail-fast: false
services:
@ -26,15 +27,24 @@ jobs:
steps:
- name: Create database schema
run: PGPASSWORD=secret psql -h 127.0.0.1 -d testdb -U user -c "CREATE SCHEMA shakespeare; CREATE SCHEMA happy_hog;"
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install required libs
run: pip install -r requirements.txt
- name: Run tests
run: pytest
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-3.10-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Test
run: poetry run pytest
env:
PYTHONDONTWRITEBYTECODE: 1
PYTHONUNBUFFERED: 1

View File

@ -1,20 +1,41 @@
# Pull base image
FROM python:3.10-slim-buster as builder
FROM python:3.10-slim AS base
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends curl git build-essential \
&& apt-get autoremove -y
ENV POETRY_HOME="/opt/poetry"
RUN curl -sSL https://install.python-poetry.org | python3 -
# Set environment variables
COPY requirements.txt requirements.txt
FROM base AS install
WORKDIR /home/code
# Install pipenv
RUN set -ex && pip install --upgrade pip
# allow controlling the poetry installation of dependencies via external args
ARG INSTALL_ARGS="--no-root --no-dev"
ENV POETRY_HOME="/opt/poetry"
ENV PATH="$POETRY_HOME/bin:$PATH"
COPY pyproject.toml poetry.lock ./
# Install dependencies
RUN set -ex && pip install -r requirements.txt
# install without virtualenv, since we are inside a container
RUN poetry config virtualenvs.create false \
&& poetry install $INSTALL_ARGS
FROM builder as final
WORKDIR /code
COPY app/ /code/
COPY ./tests/ /code/
COPY .env /code/
# cleanup
RUN curl -sSL https://install.python-poetry.org | python3 - --uninstall
RUN apt-get purge -y curl git build-essential \
&& apt-get clean -y \
&& rm -rf /root/.cache \
&& rm -rf /var/apt/lists/* \
&& rm -rf /var/cache/apt/*
FROM install as app-image
COPY tests tests
COPY app app
COPY alembic alembic
COPY .env alembic.ini ./
# create a non-root user and switch to it, for security.
RUN addgroup --system --gid 1001 "app-user"
RUN adduser --system --uid 1001 "app-user"
USER "app-user"
RUN set -ex && bash -c "eval $(grep 'PYTHONDONTWRITEBYTECODE' .env)"
RUN set -ex && bash -c "eval $(grep 'PYTHONUNBUFFERED' .env)"

38
Pipfile
View File

@ -1,38 +0,0 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
fastapi = "*"
pydantic = "*"
httptools = "*"
httpx = "==0.23.0"
requests = "==2.28.1"
uvicorn = "*"
uvloop = "*"
asyncpg = "*"
sqlalchemy = {extras = ["asyncio"], version = "*"}
alembic = "*"
eventlet = "*"
rich = "*"
[dev-packages]
devtools = {extras = ["pygments"], version = "*"}
isort = "*"
mypy = "*"
flake8 = "*"
black = "*"
safety = "*"
autoflake = "*"
pyupgrade = "*"
ipython = "*"
pylint = "*"
pytest-cov = "*"
pytest-asyncio = "*"
[requires]
python_version = "3.10"
[pipenv]
allow_prereleases = true

1222
Pipfile.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -50,4 +50,5 @@ Hope you enjoy it.
### Change Log
- 4 JUN 2022 alembic migrations added to project
- 6 JUN 2022 added initial dataset for shakespeare models
- 6 JUN 2022 added initial dataset for shakespeare models
- 3 OCT 2022 poetry added to project

View File

@ -17,11 +17,6 @@ class Nonsense(Base):
name = Column(String, nullable=False, primary_key=True, unique=True)
description = Column(String, nullable=False)
def __init__(self, name: str, description: str):
self.name = name
self.description = description
@classmethod
async def find(cls, db_session: AsyncSession, name: str):
"""

View File

@ -17,10 +17,6 @@ class Stuff(Base):
name = Column(String, nullable=False, primary_key=True, unique=True)
description = Column(String, nullable=False)
def __init__(self, name: str, description: str):
self.name = name
self.description = description
@classmethod
async def find(cls, db_session: AsyncSession, name: str):
"""

2049
poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

36
pyproject.toml Normal file
View File

@ -0,0 +1,36 @@
[tool.poetry]
name = "fastapi-sqlalchemy-asyncpg"
version = "0.0.1"
description = ""
authors = ["Jakub Miazek <the@grillazz.com>"]
packages = []
license = "MIT"
[tool.poetry.dependencies]
python = "^3.10"
alembic = "*"
asyncpg = "*"
httpx = "*"
pydantic = "*"
sqlalchemy = "*"
fastapi = "*"
uvicorn = { extras = ["standard"], version = "*" }
uvloop = "*"
httptools = "*"
rich = "*"
devtools = {extras = ["pygments"], version = "*"}
isort = "*"
mypy = "*"
flake8 = "*"
black = "*"
safety = "*"
autoflake = "*"
pyupgrade = "*"
ipython = "*"
pylint = "*"
pytest-cov = "*"
pytest-asyncio = "*"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

View File

@ -1,84 +0,0 @@
alembic==1.8.1
anyio==3.6.1
appnope==0.1.3
asgiref==3.5.2
astroid==2.6.6
asttokens==2.0.5
asyncpg==0.26.0
attrs==21.4.0
autoflake==1.4
backcall==0.2.0
black==22.3.0
certifi==2022.6.15.1
charset-normalizer==2.1.1
click==8.1.3
commonmark==0.9.1
coverage==6.4
decorator==5.1.1
devtools==0.8.0
dnspython==2.2.1
dparse==0.5.2
eventlet==0.33.1
executing==0.8.3
fastapi==0.83.0
flake8==4.0.1
greenlet==2.0.0a2
h11==0.12.0
httpcore==0.15.0
httptools==0.4.0
httpx==0.23.0
idna==3.3
iniconfig==1.1.1
ipython==8.3.0
isort==5.10.1
jedi==0.18.1
lazy-object-proxy==1.7.1
Mako==1.2.2
MarkupSafe==2.1.1
matplotlib-inline==0.1.3
mccabe==0.6.1
mypy==0.960
mypy-extensions==0.4.3
packaging==21.3
parso==0.8.3
pathspec==0.9.0
pexpect==4.8.0
pickleshare==0.7.5
platformdirs==2.5.2
pluggy==1.0.0
prompt-toolkit==3.0.29
ptyprocess==0.7.0
pure-eval==0.2.2
py==1.11.0
pycodestyle==2.8.0
pydantic==1.10.2
pyflakes==2.4.0
Pygments==2.13.0
pylint==3.0.0a4
pyparsing==3.0.9
pytest==7.1.2
pytest-asyncio==0.18.3
pytest-cov==3.0.0
pyupgrade==2.32.1
PyYAML==6.0
requests==2.28.1
rfc3986==1.5.0
rich==12.5.1
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.6
safety==2.0b1
six==1.16.0
sniffio==1.3.0
SQLAlchemy==1.4.41
stack-data==0.2.0
starlette==0.19.1
tokenize-rt==4.2.1
toml==0.10.2
tomli==2.0.1
traitlets==5.2.1.post0
typing_extensions==4.3.0
urllib3==1.26.12
uvicorn==0.18.3
uvloop==0.16.0
wcwidth==0.2.5
wrapt==1.12.1