Skip to content

Commit c8bcc0b

Browse files
RCheesetiangolo
andauthored
➕ Use Poetry for package management (fastapi#144)
* use poetry insted of Pipfile * fix python black version * set prepare.sh as executable * revert postgres 11 * use multi-build stage in docker * fix poetry path * 🔥 Remove uneeded changes * 🔧 Move and update Poetry file * 🙈 Update gitignore * 🐳 Update Dockerfiles to use Poetry * 🐳 Update Dockerfiles with Poetry * 🔧 Add SERVER_NAME required by Celery worker * 🐳 Update Poetry install to avoid env conflicts * ➕ Add Pytest to Poetry dependencies Co-authored-by: Sebastián Ramírez <[email protected]>
1 parent 0a194b3 commit c8bcc0b

File tree

8 files changed

+76
-44
lines changed

8 files changed

+76
-44
lines changed

Diff for: scripts/discard-dev-files.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
rm -rf \{\{cookiecutter.project_slug\}\}/.git
2-
rm -rf \{\{cookiecutter.project_slug\}\}/backend/app/Pipfile.lock
2+
rm -rf \{\{cookiecutter.project_slug\}\}/backend/app/poetry.lock
33
rm -rf \{\{cookiecutter.project_slug\}\}/frontend/node_modules
44
rm -rf \{\{cookiecutter.project_slug\}\}/frontend/dist
55
git checkout \{\{cookiecutter.project_slug\}\}/README.md

Diff for: {{cookiecutter.project_slug}}/backend/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
__pycache__
2+
app.egg-info

Diff for: {{cookiecutter.project_slug}}/backend/app/Pipfile

-39
This file was deleted.
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[tool.poetry]
2+
name = "app"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Admin <[email protected]>"]
6+
7+
[tool.poetry.dependencies]
8+
python = "^3.7"
9+
uvicorn = "^0.11.3"
10+
fastapi = "^0.54.1"
11+
pyjwt = "^1.7.1"
12+
python-multipart = "^0.0.5"
13+
email-validator = "^1.0.5"
14+
requests = "^2.23.0"
15+
celery = "^4.4.2"
16+
passlib = {extras = ["bcrypt"], version = "^1.7.2"}
17+
tenacity = "^6.1.0"
18+
pydantic = "^1.4"
19+
emails = "^0.5.15"
20+
raven = "^6.10.0"
21+
gunicorn = "^20.0.4"
22+
jinja2 = "^2.11.2"
23+
psycopg2-binary = "^2.8.5"
24+
alembic = "^1.4.2"
25+
sqlalchemy = "^1.3.16"
26+
pytest = "^5.4.1"
27+
28+
[tool.poetry.dev-dependencies]
29+
mypy = "^0.770"
30+
black = "^19.10b0"
31+
isort = "^4.3.21"
32+
autoflake = "^1.3.1"
33+
flake8 = "^3.7.9"
34+
pytest = "^5.4.1"
35+
jupyter = "^1.0.0"
36+
vulture = "^1.4"
37+
38+
[build-system]
39+
requires = ["poetry>=0.12"]
40+
build-backend = "poetry.masonry.api"

Diff for: {{cookiecutter.project_slug}}/backend/backend.dockerfile

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
22

3-
RUN pip install celery~=4.3 passlib[bcrypt] tenacity requests emails "fastapi>=0.47.0" "uvicorn>=0.11.1" gunicorn pyjwt python-multipart email-validator jinja2 psycopg2-binary alembic SQLAlchemy
3+
WORKDIR /app/
4+
5+
# Install Poetry
6+
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \
7+
cd /usr/local/bin && \
8+
ln -s /opt/poetry/bin/poetry && \
9+
poetry config virtualenvs.create false
10+
11+
# Copy poetry.lock* in case it doesn't exist in the repo
12+
COPY ./app/pyproject.toml ./app/poetry.lock* /app/
13+
RUN poetry install --no-dev --no-root
414

515
# For development, Jupyter remote kernel, Hydrogen
616
# Using inside the container:
@@ -10,7 +20,6 @@ RUN bash -c "if [ $env == 'dev' ] ; then pip install jupyterlab ; fi"
1020
EXPOSE 8888
1121

1222
COPY ./app /app
13-
WORKDIR /app/
1423

1524
ENV PYTHONPATH=/app
1625

Diff for: {{cookiecutter.project_slug}}/backend/celeryworker.dockerfile

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
FROM python:3.7
22

3-
RUN pip install raven celery~=4.3 passlib[bcrypt] tenacity requests "fastapi>=0.47.0" emails pyjwt email-validator jinja2 psycopg2-binary alembic SQLAlchemy
3+
WORKDIR /app/
4+
5+
# Install Poetry
6+
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \
7+
cd /usr/local/bin && \
8+
ln -s /opt/poetry/bin/poetry && \
9+
poetry config virtualenvs.create false
10+
11+
# Copy poetry.lock* in case it doesn't exist in the repo
12+
COPY ./app/pyproject.toml ./app/poetry.lock* /app/
13+
RUN poetry install --no-dev --no-root
414

515
# For development, Jupyter remote kernel, Hydrogen
616
# Using inside the container:

Diff for: {{cookiecutter.project_slug}}/backend/tests.dockerfile

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
FROM python:3.7
22

3-
RUN pip install requests pytest tenacity passlib[bcrypt] "fastapi>=0.47.0" email-validator psycopg2-binary SQLAlchemy
3+
WORKDIR /app/
4+
5+
# Install Poetry
6+
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \
7+
cd /usr/local/bin && \
8+
ln -s /opt/poetry/bin/poetry && \
9+
poetry config virtualenvs.create false
10+
11+
# Copy poetry.lock* in case it doesn't exist in the repo
12+
COPY ./app/pyproject.toml ./app/poetry.lock* /app/
13+
RUN poetry install --no-dev --no-root
414

515
# For development, Jupyter remote kernel, Hydrogen
616
# Using inside the container:

Diff for: {{cookiecutter.project_slug}}/docker-compose.shared.env.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ services:
1717
- env-postgres.env
1818
- env-backend.env
1919
environment:
20+
- SERVER_NAME=${DOMAIN}
2021
- SERVER_HOST=https://${DOMAIN}

0 commit comments

Comments
 (0)