Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 19ebc33

Browse files
committed
style/refactor: some refactoring and improvements in typing annotations
1 parent 17ab272 commit 19ebc33

File tree

34 files changed

+4563
-7895
lines changed

34 files changed

+4563
-7895
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ipython_config.py
9999
# This is especially recommended for binary packages to ensure reproducibility, and is more
100100
# commonly ignored for libraries.
101101
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102-
#poetry.lock
102+
poetry.lock
103103

104104
# pdm
105105
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
@@ -168,4 +168,4 @@ sqlsymphony-orm/format-code.py
168168
sqlsymphony-orm/main.py
169169
sqlsymphony-orm/spacetabs.sh
170170
.idea/
171-
sqlsymphony-orm/.idea
171+
sqlsymphony-orm/.idea

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = "SQLSymphonyORM"
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = "0.4.16"
51+
PROJECT_NUMBER = "0.4.17"
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewer a

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ currently being supported with security updates.
77

88
| Version | Supported |
99
| ------- | ------------------ |
10+
| 0.4.17 | :white_check_mark: |
1011
| 0.4.16 | :white_check_mark: |
1112
| 0.4.15 | :x: |
1213
| 0.4.14 | :x: |

sqlsymphony_orm/examples/main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88

99
class BankAccount(Model):
10-
__tablename__ = "BankAccounts"
11-
__database__ = "bank.db"
10+
__tablename__ = "BankAccounts"
11+
__database__ = "bank.db"
1212

13-
id = IntegerField(primary_key=True)
14-
name = TextField(null=False)
15-
cash = RealField(null=False, default=0.0)
13+
id = IntegerField(primary_key=True)
14+
name = TextField(null=False)
15+
cash = RealField(null=False, default=0.0)
1616

17-
def __repr__(self):
18-
return f"<BankAccount {self.pk}>"
17+
def __repr__(self):
18+
return f"<BankAccount {self.pk}>"
1919

2020

2121
account = BankAccount(name="John", cash=100.0)
@@ -40,10 +40,10 @@ def __repr__(self):
4040
mm_manager = SQLiteMultiModelManager("database.db")
4141
mm_manager.add_model(account)
4242
mm_manager.model_manager(account._model_name).create_table(
43-
account.table_name, account.get_formatted_sql_fields()
43+
account.table_name, account.get_formatted_sql_fields()
4444
)
4545
mm_manager.model_manager(account._model_name).insert(
46-
account.table_name, account.get_formatted_sql_fields(), account.pk, account
46+
account.table_name, account.get_formatted_sql_fields(), account.pk, account
4747
)
4848
mm_manager.model_manager(account._model_name).commit()
4949

sqlsymphony_orm/examples/main2.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@
1010

1111

1212
class User(SessionModel):
13-
__tablename__ = "Users"
13+
__tablename__ = "Users"
1414

15-
id = IntegerField(primary_key=True)
16-
name = TextField(null=False)
17-
cash = RealField(null=False, default=0.0)
15+
id = IntegerField(primary_key=True)
16+
name = TextField(null=False)
17+
cash = RealField(null=False, default=0.0)
1818

19-
def __repr__(self):
20-
return f"<User {self.pk}>"
19+
def __repr__(self):
20+
return f"<User {self.pk}>"
2121

2222

2323
class User2(SessionModel):
24-
__tablename__ = "Users"
24+
__tablename__ = "Users"
2525

26-
id = IntegerField(primary_key=True)
27-
name = TextField(null=False)
28-
cash = RealField(null=False, default=0.0)
29-
password = TextField(default="password1234")
26+
id = IntegerField(primary_key=True)
27+
name = TextField(null=False)
28+
cash = RealField(null=False, default=0.0)
29+
password = TextField(default="password1234")
3030

31-
def __repr__(self):
32-
return f"<User {self.pk}>"
31+
def __repr__(self):
32+
return f"<User {self.pk}>"
3333

3434

3535
class Comment(SessionModel):
36-
id = IntegerField(primary_key=True)
37-
name = TextField(null=False)
38-
user_id = IntegerField(null=False)
36+
id = IntegerField(primary_key=True)
37+
name = TextField(null=False)
38+
user_id = IntegerField(null=False)
3939

4040

4141
user = User(name="John")
@@ -57,7 +57,7 @@ class Comment(SessionModel):
5757
session.commit()
5858

5959
print(
60-
session.filter(QueryBuilder().SELECT("*").FROM(User.table_name).WHERE(name="Anna"))
60+
session.filter(QueryBuilder().SELECT("*").FROM(User.table_name).WHERE(name="Anna"))
6161
)
6262
print(session.get_all())
6363
print(session.get_all_by_model(User))

sqlsymphony_orm/examples/main3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from sqlsymphony_orm.security.hashing import PlainHasher, HashAlgorithm
22

33
hasher = PlainHasher(
4-
HashAlgorithm.SHA512
4+
HashAlgorithm.SHA512
55
) # also: SHA256, SHA512, MD5, BLAKE2B, BLAKE2S
66

77
hash1 = hasher.hash("password")
88
hash2 = hasher.hash("pasword")
99

10-
print(hasher.verify("password", hash1)) # True
11-
print(hasher.verify("password", hash2)) # False
10+
print(hasher.verify("password", hash1)) # True
11+
print(hasher.verify("password", hash2)) # False

sqlsymphony_orm/examples/main4.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from sqlsymphony_orm.security.hashing import SaltedHasher, HashAlgorithm
22

33
hasher = SaltedHasher(
4-
HashAlgorithm.SHA512, salt="SALT"
4+
HashAlgorithm.SHA512, salt="SALT"
55
) # also: SHA256, SHA512, MD5, BLAKE2B, BLAKE2S
66
hasher2 = SaltedHasher(
7-
HashAlgorithm.SHA512, salt="SALT2"
7+
HashAlgorithm.SHA512, salt="SALT2"
88
) # also: SHA256, SHA512, MD5, BLAKE2B, BLAKE2S
99

1010
hash1 = hasher.hash("password")
1111
hash2 = hasher2.hash("password")
1212

13-
print(hasher.verify("password", hash1)) # True
14-
print(hasher.verify("password", hash2)) # False
13+
print(hasher.verify("password", hash1)) # True
14+
print(hasher.verify("password", hash2)) # False

sqlsymphony_orm/examples/main5.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99

1010

1111
class User(SessionModel):
12-
__tablename__ = "Users"
12+
__tablename__ = "Users"
1313

14-
id = IntegerField(primary_key=True)
15-
name = TextField(null=False)
16-
cash = RealField(null=False, default=0.0)
14+
id = IntegerField(primary_key=True)
15+
name = TextField(null=False)
16+
cash = RealField(null=False, default=0.0)
1717

18-
def __repr__(self):
19-
return f"<User {self.pk}>"
18+
def __repr__(self):
19+
return f"<User {self.pk}>"
2020

2121

2222
print(
23-
session.filter(QueryBuilder().SELECT("*").FROM(User.table_name).WHERE(name="Anna"))
23+
session.filter(QueryBuilder().SELECT("*").FROM(User.table_name).WHERE(name="Anna"))
2424
)
2525
print(session.get_all_by_model(User))
2626

sqlsymphony_orm/format-code.py

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
RED = "\033[31m"
99
GREEN = "\033[32m"
1010
YELLOW = "\033[33m"
11-
NC = "\033[0m" # No Color
11+
NC = "\033[0m" # No Color
1212
BOLD = "\033[1m" # No Color
1313

1414
# File Extension filter. You can add new extension
@@ -22,100 +22,100 @@
2222

2323

2424
def print_usage():
25-
"""Print the usage instructions."""
26-
print(f"{YELLOW}Usage: convert_tabs(file_path, tab_size, conversion_type){NC}")
27-
print("<conversion_type>: 'spaces' or 'tabs'")
25+
"""Print the usage instructions."""
26+
print(f"{YELLOW}Usage: convert_tabs(file_path, tab_size, conversion_type){NC}")
27+
print("<conversion_type>: 'spaces' or 'tabs'")
2828

2929

3030
def print_error(message):
31-
"""Print error messages."""
32-
print(f"{RED}Error: {message}{NC}")
31+
"""Print error messages."""
32+
print(f"{RED}Error: {message}{NC}")
3333

3434

3535
def validate_positive_integer(value):
36-
"""Validate if the value is a positive integer."""
37-
try:
38-
int_value = int(value)
39-
if int_value < 1:
40-
raise ValueError
41-
return int_value
42-
except ValueError:
43-
print_error("Tab size must be a positive integer.")
44-
return None
36+
"""Validate if the value is a positive integer."""
37+
try:
38+
int_value = int(value)
39+
if int_value < 1:
40+
raise ValueError
41+
return int_value
42+
except ValueError:
43+
print_error("Tab size must be a positive integer.")
44+
return None
4545

4646

4747
def file_exists(file_path):
48-
"""Check if the file exists."""
49-
if not os.path.isfile(file_path):
50-
print_error(f"File not found: {file_path}")
51-
return False
52-
return True
48+
"""Check if the file exists."""
49+
if not os.path.isfile(file_path):
50+
print_error(f"File not found: {file_path}")
51+
return False
52+
return True
5353

5454

5555
def convert_tabs(file_path, tab_size, conversion_type):
56-
"""Convert tabs to spaces or spaces to tabs based on conversion type."""
57-
try:
58-
if conversion_type == "spaces":
59-
print(f"{BOLD}Converting tabs to spaces...{NC}")
60-
subprocess.run(
61-
["expand", "-t", str(tab_size), file_path],
62-
stdout=open(f"{file_path}.tmp", "w"),
63-
)
64-
elif conversion_type == "tabs":
65-
print(f"{BOLD}Converting spaces to tabs...{NC}")
66-
subprocess.run(
67-
["unexpand", "-t", str(tab_size), file_path],
68-
stdout=open(f"{file_path}.tmp", "w"),
69-
)
70-
else:
71-
print_error(
72-
f"Invalid conversion type: {conversion_type}. Use 'spaces' or 'tabs'."
73-
)
74-
return
75-
76-
os.replace(f"{file_path}.tmp", file_path)
77-
print(f"{GREEN}Conversion completed successfully: {file_path}{NC}")
78-
except Exception as e:
79-
print_error(f"Conversion failed: {str(e)}")
56+
"""Convert tabs to spaces or spaces to tabs based on conversion type."""
57+
try:
58+
if conversion_type == "spaces":
59+
print(f"{BOLD}Converting tabs to spaces...{NC}")
60+
subprocess.run(
61+
["expand", "-t", str(tab_size), file_path],
62+
stdout=open(f"{file_path}.tmp", "w"),
63+
)
64+
elif conversion_type == "tabs":
65+
print(f"{BOLD}Converting spaces to tabs...{NC}")
66+
subprocess.run(
67+
["unexpand", "-t", str(tab_size), file_path],
68+
stdout=open(f"{file_path}.tmp", "w"),
69+
)
70+
else:
71+
print_error(
72+
f"Invalid conversion type: {conversion_type}. Use 'spaces' or 'tabs'."
73+
)
74+
return
75+
76+
os.replace(f"{file_path}.tmp", file_path)
77+
print(f"{GREEN}Conversion completed successfully: {file_path}{NC}")
78+
except Exception as e:
79+
print_error(f"Conversion failed: {str(e)}")
8080

8181

8282
def convert_file(file_path, tab_size, conversion_type):
83-
"""Main function to manage conversion."""
84-
tab_size = validate_positive_integer(tab_size)
85-
if tab_size is None:
86-
return
83+
"""Main function to manage conversion."""
84+
tab_size = validate_positive_integer(tab_size)
85+
if tab_size is None:
86+
return
8787

88-
if not file_exists(file_path):
89-
return
88+
if not file_exists(file_path):
89+
return
9090

91-
convert_tabs(file_path, tab_size, conversion_type)
91+
convert_tabs(file_path, tab_size, conversion_type)
9292

9393

9494
def main():
95-
# Set the current working directory for scanning c/c++ sources (including
96-
# header files) and apply the clang formatting
97-
# Please note "-style" is for standard style options
98-
# and "-i" is in-place editing
99-
100-
if len(sys.argv) > 1:
101-
print(f"{BOLD}Format {sys.argv[1]}{NC}")
102-
os.system(f"{RUFF} check {sys.argv[1]} --fix")
103-
os.system(f"{RUFF} format {sys.argv[1]}")
104-
print(f"{GREEN}Formatting completed successfully: {sys.argv[1]}{NC}")
105-
convert_file(f"{sys.argv[1]}", "4", "tabs")
106-
return
107-
108-
for root, dirs, files in os.walk(os.getcwd()):
109-
if len(set(root.split("/")).intersection(IGNORED_DIRS)) > 0:
110-
continue
111-
for file in files:
112-
if file.endswith(py_extensions):
113-
print(f"{BOLD}Format {file}: {root}/{file}{NC}")
114-
os.system(f"{RUFF} check {root}/{file} --fix")
115-
os.system(f"{RUFF} format {root}/{file}")
116-
print(f"{GREEN}Formatting completed successfully: {root}/{file}{NC}")
117-
convert_file(f"{root}/{file}", "4", "tabs")
95+
# Set the current working directory for scanning c/c++ sources (including
96+
# header files) and apply the clang formatting
97+
# Please note "-style" is for standard style options
98+
# and "-i" is in-place editing
99+
100+
if len(sys.argv) > 1:
101+
print(f"{BOLD}Format {sys.argv[1]}{NC}")
102+
os.system(f"{RUFF} check {sys.argv[1]} --fix")
103+
os.system(f"{RUFF} format {sys.argv[1]}")
104+
print(f"{GREEN}Formatting completed successfully: {sys.argv[1]}{NC}")
105+
convert_file(f"{sys.argv[1]}", "4", "tabs")
106+
return
107+
108+
for root, dirs, files in os.walk(os.getcwd()):
109+
if len(set(root.split("/")).intersection(IGNORED_DIRS)) > 0:
110+
continue
111+
for file in files:
112+
if file.endswith(py_extensions):
113+
print(f"{BOLD}Format {file}: {root}/{file}{NC}")
114+
os.system(f"{RUFF} check {root}/{file} --fix")
115+
os.system(f"{RUFF} format {root}/{file}")
116+
print(f"{GREEN}Formatting completed successfully: {root}/{file}{NC}")
117+
convert_file(f"{root}/{file}", "4", "tabs")
118118

119119

120120
if __name__ == "__main__":
121-
main()
121+
main()

sqlsymphony_orm/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "sqlsymphony_orm"
3-
version = "0.4.16"
3+
version = "0.4.17"
44
description = "The elegant and powerful SQLite3 ORM for Python"
55
authors = ["alexeev-prog <[email protected]>"]
66
readme = "README.md"
@@ -21,7 +21,7 @@ requires = ["poetry-core"]
2121
build-backend = "poetry.core.masonry.api"
2222

2323
[project]
24-
keywords = ["sqlsymphony", "async", "async database", "async ORM", "aiosqlite", "OOP", "database", "sql", "sqlite", "ORM", "db", 'sqlite3', 'sqlalchemy', 'fast', 'simple']
24+
keywords = ["sqlsymphony", "database", "ORM", "sqlite", "OOP", "database", "sql", "sqlite", "db", 'sqlite3', 'sqlalchemy', 'fast', 'simple']
2525
license = {text = "GNU GPL v3"}
2626
requires-python = ">=3.9"
2727
dynamic = ["version"]

0 commit comments

Comments
 (0)