diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 823656b..fe7936e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: verify-types: name: "Pyright Verify Types" runs-on: "ubuntu-latest" - + steps: - name: "Checkout repository" uses: "actions/checkout@v4" @@ -20,7 +20,7 @@ jobs: with: path: ~/.local key: poetry-0 - + - name: "Install Poetry" if: steps.cached-poetry.outputs.cache-hit != 'true' uses: "snok/install-poetry@v1" @@ -30,10 +30,10 @@ jobs: with: python-version: "3.12.1" cache: "poetry" - + - name: "Install project" run: poetry install --all-extras --no-interaction --no-ansi - + - name: "Run Pyright" run: "poetry run pyright --verifytypes pg_purepy --ignoreexternal" @@ -42,7 +42,7 @@ jobs: fail-fast: false matrix: postgres-version: ["16", "15", "14", "13", "12"] - + name: "Test on PostgreSQL ${{ matrix.postgres-version }}" runs-on: ubuntu-latest @@ -53,7 +53,7 @@ jobs: POSTGRES_USERNAME: "postgres" POSTGRES_PASSWORD: "postgres" POSTGRES_DB: "postgres" - + ports: - 5432 @@ -67,7 +67,7 @@ jobs: with: path: ~/.local key: poetry-0 - + - name: "Install Poetry" if: steps.cached-poetry.outputs.cache-hit != 'true' uses: "snok/install-poetry@v1" @@ -77,10 +77,10 @@ jobs: with: python-version: "3.12.1" cache: "poetry" - + - name: "Install project" run: poetry install --all-extras --no-interaction --no-ansi - + - name: "Run Pytest" run: "poetry run pytest -rPx --cov" env: @@ -88,7 +88,7 @@ jobs: POSTGRES_PASSWORD: "postgres" POSTGRES_DATABASE: "postgres" POSTGRES_PORT: "${{ job.services.postgresql.ports[5432] }}" - + - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 env: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..701fc21 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-toml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + args: ["--fix=lf"] + - id: trailing-whitespace + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.9 + hooks: + - id: ruff + args: ["--preview", "--fix"] + - id: ruff-format + args: ["--preview"] diff --git a/.readthedocs.yaml b/.readthedocs.yaml index dc4489b..cf3ee0f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -14,4 +14,4 @@ build: - pip install poetry - poetry config virtualenvs.create false post_install: - - poetry install --with docs \ No newline at end of file + - poetry install --with docs diff --git a/LICENCE b/LICENCE index 153d416..0a04128 100644 --- a/LICENCE +++ b/LICENCE @@ -162,4 +162,4 @@ General Public License ever published by the Free Software Foundation. whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the -Library. \ No newline at end of file +Library. diff --git a/LICENCE.GPL b/LICENCE.GPL index e72bfdd..f288702 100644 --- a/LICENCE.GPL +++ b/LICENCE.GPL @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. \ No newline at end of file +. diff --git a/README.rst b/README.rst index bdc4c11..6fc90e4 100644 --- a/README.rst +++ b/README.rst @@ -11,4 +11,4 @@ A lot of this library was inspired by the `pg8000`_ library. Credits to that. Read the docs at https://pg.py.veriny.tf/. .. _anyio: https://github.com/agronholm/anyio -.. _pg8000: https://github.com/tlocke/pg8000 \ No newline at end of file +.. _pg8000: https://github.com/tlocke/pg8000 diff --git a/docs/_static/css/custom.css b/docs/_static/css/custom.css index ea3abfa..4210eb9 100644 --- a/docs/_static/css/custom.css +++ b/docs/_static/css/custom.css @@ -46,4 +46,4 @@ p, li, strong, em, a { .wy-side-nav-search > a img.logo { display: inline !important; padding: 0 !important; -} \ No newline at end of file +} diff --git a/docs/api-lowlevel.rst b/docs/api-lowlevel.rst index e1be2d5..163b739 100644 --- a/docs/api-lowlevel.rst +++ b/docs/api-lowlevel.rst @@ -237,4 +237,4 @@ The client object exposes the current state of the protocol state machine using :undoc-members: -.. _sans-IO: https://sans-io.readthedocs.io/ \ No newline at end of file +.. _sans-IO: https://sans-io.readthedocs.io/ diff --git a/docs/changelog.rst b/docs/changelog.rst index 277fed8..5c97888 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,9 +5,9 @@ Changelog ------------------ - Make :meth:`.AsyncPostgresConnection.fetch_one` raise an error in the event of an empty row, - instead of returning an optional. + instead of returning an optional. - This results in a more ergonomic API (as you don't need to check for None constantly) with the + This results in a more ergonomic API (as you don't need to check for None constantly) with the side effect of requiring potentially more error handling. This is the same approach used in the `sqlx `_ library, for one example. diff --git a/docs/conversion.rst b/docs/conversion.rst index c282ef2..5879f32 100644 --- a/docs/conversion.rst +++ b/docs/conversion.rst @@ -91,4 +91,4 @@ Then, you can register converters with a method depending on your API. .. automethod:: pg_purepy.protocol.SansIOClient.add_converter -The high-level API has its own API for converters. See :ref:`hilevel-converters`. \ No newline at end of file +The high-level API has its own API for converters. See :ref:`hilevel-converters`. diff --git a/docs/current-support.rst b/docs/current-support.rst index c1c53f0..478b569 100644 --- a/docs/current-support.rst +++ b/docs/current-support.rst @@ -32,4 +32,4 @@ Won't Be Supported ------------------ - High-level APIs for multiple SQL queries in one query string. There's no nice API for this, - unfortunately. \ No newline at end of file + unfortunately. diff --git a/docs/make.bat b/docs/make.bat index 2119f51..922152e 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -1,35 +1,35 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=. -set BUILDDIR=_build - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - -:end -popd +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/messages.rst b/docs/messages.rst index 492079e..65346b8 100644 --- a/docs/messages.rst +++ b/docs/messages.rst @@ -80,4 +80,3 @@ These classes relate to parts of the query cycle. :members: .. autoclass:: pg_purepy.messages.BindComplete - diff --git a/pyproject.toml b/pyproject.toml index 798759c..fd42435 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,18 +66,18 @@ line-length = 100 show-source = true select = [ - "RUF", - "F", - "E", + "RUF", + "F", + "E", "W", - "I", - "UP", - "B", - "YTT", + "I", + "UP", + "B", + "YTT", "ASYNC", - "TRIO", - "PYI", - "SIM", + "TRIO", + "PYI", + "SIM", "RET", "PERF", ] diff --git a/tests/test_async_connection.py b/tests/test_async_connection.py index 7fcf576..884a3ec 100644 --- a/tests/test_async_connection.py +++ b/tests/test_async_connection.py @@ -43,10 +43,10 @@ async def test_connection_with_invalid_password(): with pytest.raises(InvalidPasswordError): async with open_database_connection( - address_or_path=POSTGRES_ADDRESS, - username=POSTGRES_USERNAME, + address_or_path=POSTGRES_ADDRESS, + username=POSTGRES_USERNAME, port=POSTGRES_PORT, - password="" + password="", ): pass @@ -242,7 +242,10 @@ async def test_execute_prepared_statement_insert(): async with open_connection() as conn: await conn.execute( - "create temp table test_epsi (id int primary key generated always as identity, foo text not null);" + """ + create temp table test_epsi ( + id int primary key generated always as identity, foo text not null + );""" ) st_no_params = await conn.create_prepared_statement( @@ -275,7 +278,12 @@ async def test_insert(): async with open_connection() as conn: await conn.execute( - "create temp table test_insert (id int primary key generated always as identity, foo text not null);" + """ + create temp table test_insert ( + id int primary key generated always as identity, + foo text not null + ); + """ ) row_count = await conn.execute("insert into test_insert(foo) values (:one);", one="test") assert row_count == 1 @@ -291,7 +299,10 @@ async def test_unparameterised_insert(): async with open_connection() as conn: await conn.execute( - "create temp table test_insert2 (id int primary key generated always as identity, foo text not null);" + """create temp table test_insert2 ( + id int primary key generated always as identity, + foo text not null + );""" ) row_count = await conn.execute("insert into test_insert2(foo) values ('test');") assert row_count == 1