Skip to content

Commit

Permalink
add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuyukai committed Dec 22, 2023
1 parent 4627ca5 commit b64497d
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 72 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
verify-types:
name: "Pyright Verify Types"
runs-on: "ubuntu-latest"

steps:
- name: "Checkout repository"
uses: "actions/checkout@v4"
Expand All @@ -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"
Expand All @@ -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"

Expand All @@ -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

Expand All @@ -53,7 +53,7 @@ jobs:
POSTGRES_USERNAME: "postgres"
POSTGRES_PASSWORD: "postgres"
POSTGRES_DB: "postgres"

ports:
- 5432

Expand All @@ -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"
Expand All @@ -77,18 +77,18 @@ 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:
POSTGRES_USERNAME: "postgres"
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:
Expand Down
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ build:
- pip install poetry
- poetry config virtualenvs.create false
post_install:
- poetry install --with docs
- poetry install --with docs
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Library.
2 changes: 1 addition & 1 deletion LICENCE.GPL
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
.. _pg8000: https://github.com/tlocke/pg8000
2 changes: 1 addition & 1 deletion docs/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ p, li, strong, em, a {
.wy-side-nav-search > a img.logo {
display: inline !important;
padding: 0 !important;
}
}
2 changes: 1 addition & 1 deletion docs/api-lowlevel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/
.. _sans-IO: https://sans-io.readthedocs.io/
4 changes: 2 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://docs.rs/sqlx-core/0.7.3/src/sqlx_core/executor.rs.html#115-121>`_ library,
for one example.
Expand Down
2 changes: 1 addition & 1 deletion docs/conversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
The high-level API has its own API for converters. See :ref:`hilevel-converters`.
2 changes: 1 addition & 1 deletion docs/current-support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
unfortunately.
70 changes: 35 additions & 35 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion docs/messages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,3 @@ These classes relate to parts of the query cycle.
:members:

.. autoclass:: pg_purepy.messages.BindComplete

20 changes: 10 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
23 changes: 17 additions & 6 deletions tests/test_async_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b64497d

Please sign in to comment.