Skip to content

Commit fdc45c5

Browse files
committed
Apply black, isort, autoflake
Test with autoflake
1 parent 006a5ba commit fdc45c5

17 files changed

Lines changed: 108 additions & 102 deletions

.flake8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
22
# E203: it's a parse limit of flake8
3-
# W503: https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#w503
4-
ignore = E203, W503, E501,E701
3+
# W503,E501,E701: https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#w503
4+
ignore = E203, W503, E501, E701
55
# align to black choice
66
max-line-length = 88

src/setup.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
import io
22
import os
33

4-
from setuptools import setup, find_packages
4+
from setuptools import find_packages, setup
55

66

77
def read_file(filename):
88
base_path = os.path.abspath(os.path.dirname(__file__))
99
full_path = os.path.join(base_path, filename)
1010
try:
11-
with io.open(full_path, encoding='utf-8') as file:
11+
with io.open(full_path, encoding="utf-8") as file:
1212
return file.read()
1313
except FileNotFoundError:
14-
full_path = os.path.join(base_path, f'../{filename}')
15-
with io.open(full_path, encoding='utf-8') as file:
14+
full_path = os.path.join(base_path, f"../{filename}")
15+
with io.open(full_path, encoding="utf-8") as file:
1616
return file.read()
1717

1818

1919
setup(
20-
name='SqliteCloud',
21-
version='0.0.75',
22-
author='sqlitecloud.io',
23-
description='A Python package for working with SQLite databases in the cloud.',
24-
long_description=read_file('README-PYPI.md'),
25-
long_description_content_type='text/markdown',
20+
name="SqliteCloud",
21+
version="0.0.75",
22+
author="sqlitecloud.io",
23+
description="A Python package for working with SQLite databases in the cloud.",
24+
long_description=read_file("README-PYPI.md"),
25+
long_description_content_type="text/markdown",
2626
url="https://github.com/sqlitecloud/python",
2727
packages=find_packages(),
2828
install_requires=[
29-
'lz4 == 3.1.10',
29+
"lz4 == 3.1.10",
3030
],
3131
classifiers=[
32-
'Development Status :: 3 - Alpha',
33-
'Intended Audience :: Developers',
34-
'License :: OSI Approved :: MIT License',
35-
'Programming Language :: Python :: 3.6',
36-
'Programming Language :: Python :: 3.7',
37-
'Programming Language :: Python :: 3.8',
38-
'Programming Language :: Python :: 3.9',
39-
'Programming Language :: Python :: 3.10',
40-
'Programming Language :: Python :: 3.11',
41-
'Programming Language :: Python :: 3.12',
32+
"Development Status :: 3 - Alpha",
33+
"Intended Audience :: Developers",
34+
"License :: OSI Approved :: MIT License",
35+
"Programming Language :: Python :: 3.6",
36+
"Programming Language :: Python :: 3.7",
37+
"Programming Language :: Python :: 3.8",
38+
"Programming Language :: Python :: 3.9",
39+
"Programming Language :: Python :: 3.10",
40+
"Programming Language :: Python :: 3.11",
41+
"Programming Language :: Python :: 3.12",
4242
],
43-
license='MIT',
43+
license="MIT",
4444
)

src/sqlitecloud/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def __init__(
2929
"""Initializes a new instance of the class with connection information.
3030
3131
Args:
32-
cloud_account (SqliteCloudAccount): The account information for the SQlite Cloud database.
32+
cloud_account (SqliteCloudAccount): The account information for the
33+
SQlite Cloud database.
3334
connection_str (str): The connection string for the SQlite Cloud database.
3435
Eg: sqlitecloud://user:pass@host.com:port/dbname?timeout=10&apikey=abcd123
3536
@@ -49,7 +50,8 @@ def open_connection(self) -> SQCloudConnect:
4950
"""Opens a connection to the SQCloud server.
5051
5152
Returns:
52-
SQCloudConnect: An instance of the SQCloudConnect class representing the connection to the SQCloud server.
53+
SQCloudConnect: An instance of the SQCloudConnect class representing
54+
the connection to the SQCloud server.
5355
5456
Raises:
5557
SQCloudException: If an error occurs while opening the connection.
@@ -75,9 +77,7 @@ def is_connected(self, conn: SQCloudConnect) -> bool:
7577
"""
7678
return self._driver.is_connected(conn)
7779

78-
def exec_query(
79-
self, query: str, conn: SQCloudConnect
80-
) -> SqliteCloudResultSet:
80+
def exec_query(self, query: str, conn: SQCloudConnect) -> SqliteCloudResultSet:
8181
"""Executes a SQL query on the SQLite Cloud database.
8282
8383
Args:

src/sqlitecloud/download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from io import BufferedWriter
21
import logging
2+
from io import BufferedWriter
33

44
from sqlitecloud.driver import Driver
55
from sqlitecloud.types import SQCloudConnect

src/sqlitecloud/driver.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
from io import BufferedReader, BufferedWriter
21
import logging
32
import select
3+
import socket
44
import ssl
55
import threading
6+
from io import BufferedReader, BufferedWriter
67
from typing import Callable, Optional, Union
8+
79
import lz4.block
10+
811
from sqlitecloud.resultset import SQCloudResult, SqliteCloudResultSet
912
from sqlitecloud.types import (
1013
SQCLOUD_CMD,
@@ -19,7 +22,6 @@
1922
SQCloudRowsetSignature,
2023
SQCloudValue,
2124
)
22-
import socket
2325

2426

2527
class Driver:
@@ -131,7 +133,7 @@ def _internal_connect(
131133
try:
132134
sock.connect((hostname, port))
133135
except Exception as e:
134-
errmsg = f"An error occurred while initializing the socket."
136+
errmsg = "An error occurred while initializing the socket."
135137
raise SQCloudException(errmsg) from e
136138

137139
return sock

src/sqlitecloud/pubsub.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import socket
2-
from sqlite3 import connect
31
from typing import Callable, Optional
2+
43
from sqlitecloud.driver import Driver
54
from sqlitecloud.resultset import SqliteCloudResultSet
65
from sqlitecloud.types import SQCLOUD_PUBSUB_SUBJECT, SQCloudConnect

src/sqlitecloud/types.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1+
import types
12
from asyncio import AbstractEventLoop
23
from enum import Enum
3-
from threading import Thread
4-
import types
54
from typing import Callable, Optional
6-
from enum import Enum
75

86

97
class SQCLOUD_DEFAULT(Enum):

src/sqlitecloud/upload.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
from io import BufferedReader
1+
import logging
22
import os
3+
from io import BufferedReader
34
from typing import Optional
5+
46
from sqlitecloud.driver import Driver
57
from sqlitecloud.types import SQCloudConnect
6-
import logging
8+
79

810
def xCallback(fd: BufferedReader, blen: int, ntot: int, nprogress: int) -> bytes:
911
"""
@@ -45,11 +47,11 @@ def upload_db(
4547
SQCloudException: If an error occurs while uploading the database.
4648
4749
"""
48-
50+
4951
# Create a driver object
5052
driver = Driver()
5153

52-
with open(filename, 'rb') as fd:
54+
with open(filename, "rb") as fd:
5355
dbsize = os.path.getsize(filename)
5456

5557
driver.upload_database(

src/tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import os
2+
23
import pytest
34
from dotenv import load_dotenv
45

56
from sqlitecloud.client import SqliteCloudClient
67
from sqlitecloud.types import SQCloudConnect, SqliteCloudAccount
78

9+
810
@pytest.fixture(autouse=True)
911
def load_env_vars():
1012
load_dotenv(".env")
1113

14+
1215
@pytest.fixture()
1316
def sqlitecloud_connection():
1417
account = SqliteCloudAccount()
@@ -26,4 +29,4 @@ def sqlitecloud_connection():
2629

2730
yield (connection, client)
2831

29-
client.disconnect(connection)
32+
client.disconnect(connection)

src/tests/integration/test_client.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import json
2-
from multiprocessing import connection
32
import os
4-
import sqlite3
5-
import tempfile
63
import time
74

85
import pytest
6+
97
from sqlitecloud.client import SqliteCloudClient
108
from sqlitecloud.types import (
119
SQCLOUD_ERRCODE,
@@ -90,10 +88,10 @@ def test_is_connected(self):
9088
client = SqliteCloudClient(cloud_account=account)
9189

9290
conn = client.open_connection()
93-
assert client.is_connected(conn) == True
91+
assert client.is_connected(conn)
9492

9593
client.disconnect(conn)
96-
assert client.is_connected(conn) == False
94+
assert not client.is_connected(conn)
9795

9896
def test_disconnect(self):
9997
account = SqliteCloudAccount()
@@ -104,10 +102,10 @@ def test_disconnect(self):
104102
client = SqliteCloudClient(cloud_account=account)
105103

106104
conn = client.open_connection()
107-
assert client.is_connected(conn) == True
105+
assert client.is_connected(conn)
108106

109107
client.disconnect(conn)
110-
assert client.is_connected(conn) == False
108+
assert not client.is_connected(conn)
111109
assert conn.socket is None
112110
assert conn.pubsub_socket is None
113111

@@ -119,7 +117,7 @@ def test_select(self, sqlitecloud_connection):
119117

120118
result = client.exec_query("SELECT 'Hello'", connection)
121119

122-
assert False == result.is_result
120+
assert not result.is_result
123121
assert 1 == result.nrows
124122
assert 1 == result.ncols
125123
assert "Hello" == result.get_value(0, 0)
@@ -239,7 +237,7 @@ def test_json(self, sqlitecloud_connection):
239237
connection, client = sqlitecloud_connection
240238
result = client.exec_query("TEST JSON", connection)
241239

242-
assert SQCLOUD_RESULT_TYPE.RESULT_JSON == result.tag
240+
assert SQCLOUD_RESULT_TYPE.RESULT_JSON == result.tag
243241
assert {
244242
"msg-from": {"class": "soldier", "name": "Wixilav"},
245243
"msg-to": {"class": "supreme-commander", "name": "[Redacted]"},
@@ -293,7 +291,7 @@ def test_array(self, sqlitecloud_connection):
293291
result = client.exec_query("TEST ARRAY", connection)
294292

295293
result_array = result.get_result()
296-
294+
297295
assert SQCLOUD_RESULT_TYPE.RESULT_ARRAY == result.tag
298296
assert isinstance(result_array, list)
299297
assert len(result_array) == 5
@@ -332,7 +330,6 @@ def test_max_rows_option(self):
332330
# just expect everything is ok
333331
assert rowset.nrows > 100
334332

335-
336333
def test_max_rowset_option_to_fail_when_rowset_is_bigger(self):
337334
account = SqliteCloudAccount()
338335
account.hostname = os.getenv("SQLITE_HOST")
@@ -352,7 +349,6 @@ def test_max_rowset_option_to_fail_when_rowset_is_bigger(self):
352349
assert SQCLOUD_ERRCODE.INTERNAL.value == e.value.errcode
353350
assert "RowSet too big to be sent (limit set to 1024 bytes)." == e.value.errmsg
354351

355-
356352
def test_max_rowset_option_to_succeed_when_rowset_is_lighter(self):
357353
account = SqliteCloudAccount()
358354
account.hostname = os.getenv("SQLITE_HOST")
@@ -439,7 +435,7 @@ def test_query_timeout(self):
439435
LIMIT 10000000
440436
)
441437
SELECT i FROM r WHERE i = 1;""",
442-
connection
438+
connection,
443439
)
444440

445441
client.disconnect(connection)
@@ -645,7 +641,8 @@ def test_compression_multiple_columns(self):
645641

646642
# min compression size for rowset set by default to 20400 bytes
647643
rowset = client.exec_query(
648-
"SELECT * from albums inner join albums a2 on albums.AlbumId = a2.AlbumId", connection
644+
"SELECT * from albums inner join albums a2 on albums.AlbumId = a2.AlbumId",
645+
connection,
649646
)
650647

651648
client.disconnect(connection)

0 commit comments

Comments
 (0)