From 3e84c56d3fa360e2811fca5054b8cc8883da8bd9 Mon Sep 17 00:00:00 2001 From: Eugene Shershen Date: Sat, 23 Oct 2021 01:02:08 +0300 Subject: [PATCH] refactoring, pre-commit added --- .flake8 | 2 +- .github/workflows/ci.yml | 20 ++++++++-------- .gitignore | 2 +- .pre-commit-config.yaml | 49 ++++++++++++++++++++++++++++++++++++++++ .pyup.yml | 2 +- README.md | 4 ++-- pyproject.toml | 2 +- setup.py | 2 +- 8 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 index 757fe01..ac8264d 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,4 @@ [flake8] exclude = .venv max-line-length = 100 -extend-ignore = E203 \ No newline at end of file +extend-ignore = E203 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ef2b0c..bd1026a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: push: branches: - main - + jobs: test: name: test @@ -35,35 +35,35 @@ jobs: uses: actions/setup-python@v1 with: python-version: ${{ matrix.python }} - + - name: Install dependencies run: | python -m pip install --upgrade pip wheel pip install -r requirements.txt - + # test all the builds apart from linux_3.8... - name: Test with pytest if: matrix.build != 'linux_3.8' run: pytest - + # only do the test coverage for linux_3.8 - name: Produce coverage report if: matrix.build == 'linux_3.8' run: pytest --cov=fastapi_async_sqlalchemy --cov-report=xml - + - name: Upload coverage report if: matrix.build == 'linux_3.8' uses: codecov/codecov-action@v1 with: file: ./coverage.xml - + lint: name: lint runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - + - name: Set up Python uses: actions/setup-python@v1 with: @@ -86,12 +86,12 @@ jobs: uses: actions/setup-python@v1 with: python-version: 3.7 - + - name: Install dependencies - # isort needs all of the packages to be installed so it can + # isort needs all of the packages to be installed so it can # tell which are third party and which are first party run: pip install -r requirements.txt - + - name: Check formatting of imports run: isort --check-only --diff --verbose diff --git a/.gitignore b/.gitignore index 3bc7b97..9981947 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ __pycache__/ htmlcov/ test.py *.egg-info -coverage.xml \ No newline at end of file +coverage.xml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c298df7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,49 @@ +exclude: (alembic|build|dist|docker|esign|kubernetes|migrations) + +default_language_version: + python: python3.7 + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/asottile/pyupgrade + rev: v2.28.0 + hooks: + - id: pyupgrade + args: + - --py37-plus + - repo: https://github.com/myint/autoflake + rev: v1.4 + hooks: + - id: autoflake + args: + - --in-place + - --remove-all-unused-imports + - --expand-star-imports + - --remove-duplicate-keys + - --remove-unused-variables + - repo: https://github.com/PyCQA/isort + rev: 5.9.3 + hooks: + - id: isort + - repo: https://github.com/psf/black + rev: 21.9b0 + hooks: + - id: black + - repo: https://github.com/PyCQA/flake8 + rev: 3.9.2 + hooks: + - id: flake8 + args: + - --max-line-length=100 + - --ignore=E203, E501, W503 + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.910 + hooks: + - id: mypy + additional_dependencies: + - pydantic + - types-ujson diff --git a/.pyup.yml b/.pyup.yml index bdd9a62..de9a616 100644 --- a/.pyup.yml +++ b/.pyup.yml @@ -1,4 +1,4 @@ -# autogenerated pyup.io config file +# autogenerated pyup.io config file # see https://pyup.io/docs/configuration/ for all available options schedule: '' diff --git a/README.md b/README.md index 081b813..7064a83 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ### Description -FastAPI-Async-SQLAlchemy provides middleware for FastAPI and SQLAlchemy using async AsyncSession and async engine. +FastAPI-Async-SQLAlchemy provides middleware for FastAPI and SQLAlchemy using async AsyncSession and async engine. Based on FastAPI-SQLAlchemy ### Install @@ -34,7 +34,7 @@ from sqlalchemy import table app = FastAPI() app.add_middleware( - SQLAlchemyMiddleware, + SQLAlchemyMiddleware, db_url="postgresql+asyncpg://user:user@192.168.88.200:5432/primary_db" ) diff --git a/pyproject.toml b/pyproject.toml index 19bdfa4..5a9141f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,4 +16,4 @@ multi_line_output = 3 include_trailing_comma = true force_grid_wrap = 0 use_parentheses = true -line_length = 100 \ No newline at end of file +line_length = 100 diff --git a/setup.py b/setup.py index 7ceeddf..be74c8f 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup with open(Path("fastapi_async_sqlalchemy") / "__init__.py", encoding="utf-8") as fh: - version = re.search(r'__version__ = "(.*?)"', fh.read(), re.M).group(1) + version = re.search(r'__version__ = "(.*?)"', fh.read(), re.M).group(1) # type: ignore with open("README.md", encoding="utf-8") as fh: long_description = fh.read()