From 9442ae85bf5b77735d2685277bcd02cc17ed8e9c Mon Sep 17 00:00:00 2001 From: zy7y <13271962515@163.com> Date: Thu, 2 May 2024 07:59:33 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#44=20=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=89=A7=E8=A1=8C=E6=97=B6=E5=AF=BC=E5=8C=85=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 25 +++++++++++++++++++++++++ README.md | 8 ++++++-- dfs_generate/conversion.py | 4 ++-- dfs_generate/server.py | 4 ++-- dfs_generate/tools.py | 2 +- requirements-test.txt | 3 ++- 6 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..cef7045 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Workflow for Codecov example-python +on: [push, pull_request] +jobs: + run: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Install dependencies + run: pip install -r requirements-test.txt + - name: Run tests and collect coverage + run: pytest --cov --cov-report xml:coverage.xml --cov-report term-missing + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + flags: smart-tests + verbose: true + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index 708b291..5ee74dc 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -# dfs-generate +# dfs-generate [![codecov](https://codecov.io/gh/zy7y/dfs-generate/graph/badge.svg?token=ZTBA7CYTFC)](https://codecov.io/gh/zy7y/dfs-generate) 通过已有数据库表,生成FastAPI接口的工具项目,最终目的为FastAPI使用者,减少代码; 项目启发 Mybatis 逆向工程、[pdmaner](https://gitee.com/robergroup/pdmaner) -# 支持ORM +# 已支持从数据库表生成 - [x] SQLModel - [x] Tortoise ORM +- [x] Vue +- [x] FastAPI 增加、删除、分页查询、详情查询、更新接口 # Generate Code [FastAPI SQLModel MySQL](docs/sqlmodel) @@ -56,6 +58,8 @@ source venv/bin/activate pip install -r requirements.txt ``` ### 运行 +> 解决找不到模块问题 +> mac / linux `export PYTHONPATH=./` windows `set PYTHONPATH=./` ```shell python dfs_generate/server.py ``` diff --git a/dfs_generate/conversion.py b/dfs_generate/conversion.py index f960185..1650fad 100644 --- a/dfs_generate/conversion.py +++ b/dfs_generate/conversion.py @@ -1,6 +1,6 @@ from string import Template -from templates import ( +from dfs_generate.templates import ( SQLMODEL_DAO, TORTOISE_DAO, RESPONSE_SCHEMA, @@ -13,7 +13,7 @@ VUE_INDEX_VUE, VUE_CRUD_TS, ) -from tools import to_pascal, tran, to_snake +from dfs_generate.tools import to_pascal, tran, to_snake def _pydantic_field(column, imports): diff --git a/dfs_generate/server.py b/dfs_generate/server.py index 0b35cf0..7916058 100644 --- a/dfs_generate/server.py +++ b/dfs_generate/server.py @@ -5,8 +5,8 @@ import isort from yapf.yapflib.yapf_api import FormatCode -from conversion import SQLModelConversion, TortoiseConversion -from tools import MySQLConf, MySQLHelper +from dfs_generate.conversion import SQLModelConversion, TortoiseConversion +from dfs_generate.tools import MySQLConf, MySQLHelper app = bottle.Bottle() diff --git a/dfs_generate/tools.py b/dfs_generate/tools.py index 589cee4..6e94f97 100644 --- a/dfs_generate/tools.py +++ b/dfs_generate/tools.py @@ -3,7 +3,7 @@ import pymysql -from types_map import TYPES +from dfs_generate.types_map import TYPES def tran(t, mode) -> dict: diff --git a/requirements-test.txt b/requirements-test.txt index 26b77f6..aa2d618 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,2 +1,3 @@ -r requirements.txt -pytest +pytest==8.2.0 +pytest-cov==5.0.0