diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 3353df6..8fae2d9 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -19,12 +19,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 black + pip install -r requirements/dev.txt - - name: Lint with flake8 - run: | - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Lint with pylint + run: pylint app --extension-pkg-allow-list=lxml - name: Format with black run: black . diff --git a/Dockerfile b/Dockerfile index 3e79d79..d18b625 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,9 +2,9 @@ FROM python WORKDIR /srv -COPY ./requirements.txt /srv/requirements.txt +COPY ./requirements /srv/requirements -RUN pip install -r requirements.txt +RUN pip install -r requirements/prod.txt EXPOSE 80 diff --git a/README.md b/README.md index 11158a3..148692b 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,35 @@ Backend for online ebook viewer publite ## Deploy +Run app locally (development only!) + +```bash +# install requirements +pip install -r requirements/dev.txt + +# run app with uvicorn +uvicorn app.main:app --reload --port +``` + +Run app locally (test prod) + +```bash +# install requirements +pip install -r requirements/prod.txt + +# run app with uvicorn +uvicorn app.main:app --port + +# or + +# run with python script +python run.py +``` + Simple docker deployment ```bash -# build docker image +# build docker image docker build . -t publite_backend # run it with docker @@ -25,4 +50,4 @@ Dokku deployment with image from Docker Hub ```bash dokku apps:create publitebackend dokku git:from-image publitebackend publite/backend:latest -``` \ No newline at end of file +``` diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/epub.py b/app/epub.py index 5fed27f..9edb4e8 100644 --- a/app/epub.py +++ b/app/epub.py @@ -2,19 +2,19 @@ Module for EPUB file conversion to html """ -from base64 import b64encode -from functools import cache import html import os +from base64 import b64encode +from functools import cache from tempfile import SpooledTemporaryFile import aiofiles as aiof -from fastapi import HTTPException -from lxml import etree import ebooklib from ebooklib import epub +from fastapi import HTTPException +from lxml import etree -from .utils import DocumentTokens, strip_whitespace, HTMLBook +from .utils import DocumentTokens, HTMLBook, strip_whitespace parser = etree.XMLParser(recover=True) diff --git a/app/fb2.py b/app/fb2.py index f829217..b078c1b 100644 --- a/app/fb2.py +++ b/app/fb2.py @@ -2,16 +2,15 @@ Module for FB2 file conversion to html """ -from tempfile import SpooledTemporaryFile -import xml.etree.ElementTree as ET -from xml.etree.ElementTree import Element -from typing import Optional import html +import xml.etree.ElementTree as ET +from tempfile import SpooledTemporaryFile +from typing import Optional +from xml.etree.ElementTree import Element from fastapi import HTTPException -from .utils import DocumentTokens, strip_whitespace, HTMLBook - +from .utils import DocumentTokens, HTMLBook, strip_whitespace namespaces = { "": "http://www.gribuser.ru/xml/fictionbook/2.0", diff --git a/app/main.py b/app/main.py index 57b6ee2..c538693 100644 --- a/app/main.py +++ b/app/main.py @@ -2,7 +2,7 @@ from datetime import datetime -from fastapi import FastAPI, File, UploadFile, HTTPException +from fastapi import FastAPI, File, HTTPException, UploadFile from pydantic import BaseModel # pylint: disable=no-name-in-module from .epub import epub2html diff --git a/app/utils.py b/app/utils.py index 3ea9e46..f14c18a 100644 --- a/app/utils.py +++ b/app/utils.py @@ -3,9 +3,9 @@ Utils for publite_backend module """ -from typing import Union, Optional import re from hashlib import sha256 +from typing import Optional, Union from pydantic import BaseModel # pylint: disable=no-name-in-module diff --git a/requirements.txt b/requirements.txt index 97ea19d..3e2d68e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,23 +1 @@ -aiofiles==0.7.0 -appdirs==1.4.4 -asgiref==3.4.0 -black==21.6b0 -click==8.0.1 -EbookLib==0.17.1 -fastapi==0.65.2 -flake8==3.9.2 -h11==0.12.0 -lxml==4.6.3 -mccabe==0.6.1 -mypy-extensions==0.4.3 -pathspec==0.8.1 -pycodestyle==2.7.0 -pydantic==1.8.2 -pyflakes==2.3.1 -python-multipart==0.0.5 -regex==2021.7.1 -six==1.16.0 -starlette==0.14.2 -toml==0.10.2 -typing-extensions==3.10.0.0 -uvicorn==0.14.0 +-r requirements/prod.txt \ No newline at end of file diff --git a/requirements/dev.txt b/requirements/dev.txt new file mode 100644 index 0000000..b21d143 --- /dev/null +++ b/requirements/dev.txt @@ -0,0 +1,4 @@ +-r prod.txt +pylint +rope +black \ No newline at end of file diff --git a/requirements/prod.txt b/requirements/prod.txt new file mode 100644 index 0000000..ea9c6f9 --- /dev/null +++ b/requirements/prod.txt @@ -0,0 +1,7 @@ +fastapi +uvicorn +aiofiles +ebooklib +python-multipart +lxml +pydantic \ No newline at end of file diff --git a/run.py b/run.py new file mode 100644 index 0000000..4cff6c6 --- /dev/null +++ b/run.py @@ -0,0 +1,4 @@ +import uvicorn + +if __name__ == "__main__": + uvicorn.run("app.main:app")