Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update latest bump #52

Merged
merged 2 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ test.verbose: ## test.verbose
docker-compose run --rm tifa-toolbox-test bash -c "python -m pytest tests -v --pdb --pdbcls=IPython.terminal.debugger:Pdb"

format: ## publish package to pypi
black tifa
black tests
poetry run ruff format .

shell_plus:
docker-compose run --rm tifa-toolbox bash -c "tifa-cli shell_plus"
Expand Down Expand Up @@ -67,22 +66,7 @@ monitor: ## flower
# docker images

build-tifa: ## > tifa
docker build -t 'twocucao/tifa:latest' -f 'compose/app/Dockerfile' .
docker build -t 'tifa:local' -f 'compose/app/Dockerfile' .

build-tifa-no-cache: ## > tifa
docker build -t 'twocucao/tifa:latest' -f 'compose/app/Dockerfile' --no-cache .

build-elasticsearch: ## > elasticsearch
docker build -t 'elasticsearch:local' -f 'compose/elasticsearch/Dockerfile' .

build-elasticsearch-no-cache: ## > elasticsearch
docker build -t 'elasticsearch:local' -f 'compose/elasticsearch/Dockerfile' . --no-cache

publish-tifa-image: ## > build and publish tifa image
echo ${DOCKER_PASS} | docker login -u twocucao --password-stdin
docker pull twocucao/tifa:latest || true
docker build -t 'tifa:latest' -f 'compose/app/Dockerfile' . --cache-from=twocucao/tifa:latest
docker tag 'tifa:latest' twocucao/tifa:latest
docker push twocucao/tifa:latest || true


docker build -t 'tifa:local' -f 'compose/app/Dockerfile' --no-cache .
28 changes: 20 additions & 8 deletions compose/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
FROM python:3.10.9-buster
FROM python:3.11.8-bullseye
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update &&\
apt-get upgrade -y &&\
apt-get install -y \
vim \
git \
gcc \
liblzma-dev \
build-essential \
libffi-dev \
cmake \
curl \
freetds-bin \
gcc \
git \
krb5-user \
ldap-utils \
libffi6 \
libbz2-dev \
libffi-dev \
libncurses5-dev \
libncursesw5-dev \
libreadline-dev \
libsasl2-2 \
libsasl2-modules \
libsqlite3-dev \
libssl-dev \
libssl1.1 \
llvm \
locales \
lsb-release \
sasl2-bin \
sqlite3 \
unixodbc

unixodbc \
vim \
wget \
xz-utils \
zlib1g-dev \
tk-dev

ENV PYPI=https://mirrors.cloud.tencent.com/pypi/simple
ENV PIP_DEFAULT_TIMEOUT=1000
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.7"

x-tifa-common:
&tifa-common
image: twocucao/tifa:latest
image: tifa:local
volumes:
- .:/opt/tifa
environment:
Expand Down
4,027 changes: 1,668 additions & 2,359 deletions poetry.lock

Large diffs are not rendered by default.

36 changes: 13 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,54 @@ include = ["tifa/templates/", "tifa/static/"]
[[tool.poetry.source]]
name = "tencent"
url = 'https://mirrors.cloud.tencent.com/pypi/simple'
priority = 'default'
priority = 'primary'

[tool.poetry.dependencies]
python = "^3.10"
python = "^3.11"
ipython = "*"
markdown = "*"
xlsxwriter = "*"
xlwt = "*"
fastapi = "^0.70.1"
uvicorn = "*"
fastapi = "^0.110.0"
uvicorn = "^0.28.0"
typer = "*"
python-jose = {extras = ["cryptography"], version = "^3.1.0"}
passlib = {extras = ["bcrypt"], version = "^1.7.2"}
aiofiles = "*"
orjson = "*"
python-dotenv = "^0.12.0"
asyncpg = "*"
python-dotenv = "^1.0.1"
aioredis = "*"
aiokafka = "*"
prometheus_client = "*"
devtools = "*"
python-socketio = {extras = ["asyncio_client"], version = "^5.2.1"}
jinja2 = "*"
requests = "^2.25.1"
aiohttp = "^3.7.4"
celery = "^5.3.1"
fastapi-utils = "^0.2.1"
gunicorn = "*"
pandas = "*"
pillow = "*"
psycopg2-binary = "^2.9.6"
pypinyin = "^0.42.0"
qrcode = "^7.1"
raven = "^6.10.0"
redis = "^3.5.3"
tenacity = "^7.0.0"
xlrd = "^2.0.1"
opentelemetry-api = "^1.4.0"
opentelemetry-exporter-jaeger = "^1.4.0"
opentelemetry-sdk = "^1.4.0"
opentelemetry-instrumentation-fastapi = "^0.23b2"
opentelemetry-instrumentation-aiohttp-client = "^0.23b2"
elasticsearch = "^8.9.0"
django = "^4.2.3"
dj-database-url = "^2.0.0"
pymysql = "^1.1.0"
aiobotocore = "^2.12.1"
pydantic-settings = "^2.2.1"
sqlalchemy = {extras = ["asyncio"], version = "^2.0.28"}
aiomysql = "^0.2.0"

[tool.poetry.dev-dependencies]
black = "*"
autoflake = "*"
coverage = "*"
"flake8" = "*"
mypy = "*"
pytest = "*"
pytest-cov = "*"
pre-commit = "*"
pytest-asyncio = "^0.15.1"

[tool.poetry.group.dev.dependencies]
ruff = "^0.3.3"

[tool.black]
exclude = '''
/(
Expand All @@ -86,4 +77,3 @@ tifa-cli = 'tifa.cli:cli'
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def op(self, url: str, json=None, **kwargs) -> Response:
app = create_app()


@pytest.fixture(scope='session')
@pytest.fixture(scope="session")
def event_loop():
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
Expand Down Expand Up @@ -88,10 +88,8 @@ async def user(session: AsyncSession):
@pytest.fixture(scope="session")
def staff_client(staff: Staff):
client = ApiClient(app, staff)
token = gen_jwt("{\"admin\":1}", 60 * 24)
client.headers.update({
"Authorization": f"Bearer {token}"
})
token = gen_jwt('{"admin":1}', 60 * 24)
client.headers.update({"Authorization": f"Bearer {token}"})
return client


Expand Down Expand Up @@ -119,7 +117,9 @@ async def color_attribute(session: AsyncSession):
available_in_grid=True,
)
adal.add(AttributeValue, attribute=attribute, name="Red", slug="red", value="red")
adal.add(AttributeValue, attribute=attribute, name="Blue", slug="blue", value="blue")
adal.add(
AttributeValue, attribute=attribute, name="Blue", slug="blue", value="blue"
)
await adal.commit()
return attribute

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/admin/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def test_channel_curd(staff_client):
"isActive": True,
"slug": "test_channel_slug",
"currencyCode": "usa",
}
},
)
assert channel["id"]
assert channel["isActive"]
Expand All @@ -19,6 +19,6 @@ def test_channel_curd(staff_client):
"isActive": False,
"slug": "test_channel_slug",
"currencyCode": "usa",
}
},
)
assert not channel["isActive"]
18 changes: 10 additions & 8 deletions tests/functional/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@

@pytest.mark.asyncio
async def test_filtering_by_attribute(
session: AsyncSession,
product_type,
# color_attribute,
# size_attribute,
# # category,
# date_attribute,
# date_time_attribute,
# # boolean_attribute,
session: AsyncSession,
product_type,
# color_attribute,
# size_attribute,
# # category,
# date_attribute,
# date_time_attribute,
# # boolean_attribute,
):
adal = AsyncDal(session)
assert len(await adal.all(ProductType)) == 1
...


# product_type_a = ProductType.objects.create(
# name="New class", slug="new-class1", has_variants=True
# )
Expand Down
2 changes: 0 additions & 2 deletions tifa/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json

from fastapi.responses import ORJSONResponse


Expand Down
10 changes: 2 additions & 8 deletions tifa/app.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import time

from fastapi import FastAPI, Request
from prometheus_client import make_asgi_app # type: ignore
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.staticfiles import StaticFiles

from tifa.contrib.globals import GlobalsMiddleware
from tifa.settings import settings
from tifa.utils.pkg import import_submodules


def setup_routers(app: FastAPI):
from tifa.apps import user, health, whiteboard, admin
from tifa.apps import user, health, admin

app.mount("/health", health.bp)
# app.mount("/admin", admin.bp)
app.mount("/admin", admin.bp)
app.mount("/user", user.bp)
app.mount("/whiteboard", whiteboard.bp)
app.mount("/metrics", make_asgi_app())


def setup_cli(app: FastAPI):
Expand Down Expand Up @@ -62,8 +58,6 @@ def create_app():
title=settings.TITLE,
description=settings.DESCRIPTION,
)
# thread local just flask like g
app.add_middleware(GlobalsMiddleware)
# 注册 db models
setup_db_models(app)
# 初始化路由
Expand Down
51 changes: 50 additions & 1 deletion tifa/apps/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,50 @@
# from .router import bp
from fastapi.responses import ORJSONResponse
from starlette.exceptions import HTTPException

from tifa.contrib.fastapi_plus import create_bp
from tifa.globals import celery

bp = create_bp()


@bp.exception_handler(HTTPException)
async def http_exception_handler(request, exc):
return ORJSONResponse(
{
"detail": exc.detail,
},
status_code=exc.status_code,
)


@bp.get("/test_celery_sync")
def test_celery():
celery.send_task("test_celery", args=("words????",))
return "ok"


@bp.get("/test_celery_asyncio_io_bound")
async def test_celery_async():
celery.send_task("test_celery_asyncio_io_bound", args=())
return "ok"


@bp.get("/test_celery_asyncio_cpu_bound")
async def test_celery_async():
celery.send_task("test_celery_asyncio_cpu_bound", args=())
return "ok"


@bp.get("/test_sentry")
def test_sentry():
1 / 0


@bp.get("/test_1_plus_1/{result}")
def test_1_plus_1(result: int):
return {"result": result == 2}


@bp.get("/test/1_plus_1_{result}")
def test_1_plus_1_v2(result: int):
return {"result": result == 2}
41 changes: 0 additions & 41 deletions tifa/apps/whiteboard/__init__.py

This file was deleted.

Loading
Loading