Skip to content

Commit d265777

Browse files
authored
feat: Lint with black (#2)
* feat: Lint with black * better 'on' * fmt --------- Co-authored-by: Kemal Hadimli <[email protected]>
1 parent 21b86bb commit d265777

File tree

35 files changed

+646
-433
lines changed

35 files changed

+646
-433
lines changed

.github/workflows/lint.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Lint with Black
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: 3.8
21+
22+
- name: Install Black
23+
run: pip install black
24+
25+
- name: Run Black
26+
run: black --check .

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
test:
2-
pytest .
2+
pytest .
3+
4+
fmt:
5+
pip install -q black
6+
black .

cloudquery/sdk/docs/generator.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def to_dict(self):
2424
"title": self.title,
2525
"description": self.description,
2626
"columns": [col.to_dict() for col in self.columns],
27-
"relations": [rel.to_dict() for rel in self.relations]
27+
"relations": [rel.to_dict() for rel in self.relations],
2828
}
2929

3030

@@ -40,7 +40,7 @@ def to_dict(self):
4040
"name": self.name,
4141
"type": self.type,
4242
"is_primary_key": self.is_primary_key,
43-
"is_incremental_key": self.is_incremental_key
43+
"is_incremental_key": self.is_incremental_key,
4444
}
4545

4646

@@ -58,9 +58,9 @@ def generate(self, directory: str, format: str):
5858

5959
def _generate_json(self, directory: str):
6060
json_tables = self._jsonify_tables(self._tables)
61-
buffer = bytes(json.dumps(json_tables, indent=2, ensure_ascii=False), 'utf-8')
61+
buffer = bytes(json.dumps(json_tables, indent=2, ensure_ascii=False), "utf-8")
6262
output_path = pathlib.Path(directory) / "__tables.json"
63-
with output_path.open('wb') as f:
63+
with output_path.open("wb") as f:
6464
f.write(buffer)
6565
return None
6666

@@ -88,10 +88,12 @@ def _jsonify_tables(self, tables):
8888

8989
def _generate_markdown(self, directory: str):
9090
env = jinja2.Environment()
91-
env.globals['indent_to_depth'] = self._indent_to_depth
92-
env.globals['all_tables_entry'] = self._all_tables_entry
91+
env.globals["indent_to_depth"] = self._indent_to_depth
92+
env.globals["all_tables_entry"] = self._all_tables_entry
9393
all_tables_template = env.from_string(ALL_TABLES)
94-
rendered_all_tables = all_tables_template.render(plugin_name=self._plugin_name, tables=self._tables)
94+
rendered_all_tables = all_tables_template.render(
95+
plugin_name=self._plugin_name, tables=self._tables
96+
)
9597
formatted_all_tables = self._format_markdown(rendered_all_tables)
9698

9799
with open(os.path.join(directory, "README.md"), "w") as f:
@@ -111,9 +113,9 @@ def _render_table(self, directory: str, env: jinja2.Environment, table: Table):
111113

112114
def _all_tables_entry(self, table: Table):
113115
env = jinja2.Environment()
114-
env.globals['indent_to_depth'] = self._indent_to_depth
115-
env.globals['all_tables_entry'] = self._all_tables_entry
116-
env.globals['indent_table_to_depth'] = self._indent_table_to_depth
116+
env.globals["indent_to_depth"] = self._indent_to_depth
117+
env.globals["all_tables_entry"] = self._all_tables_entry
118+
env.globals["indent_table_to_depth"] = self._indent_table_to_depth
117119
entry_template = env.from_string(ALL_TABLES_ENTRY)
118120
return entry_template.render(table=table)
119121

@@ -129,15 +131,15 @@ def _indent_table_to_depth(table: Table) -> str:
129131
@staticmethod
130132
def _indent_to_depth(text: str, depth: int) -> str:
131133
indentation = depth * 4 # You can adjust the number of spaces as needed
132-
lines = text.split('\n')
133-
indented_lines = [(' ' * indentation) + line for line in lines]
134-
return '\n'.join(indented_lines)
134+
lines = text.split("\n")
135+
indented_lines = [(" " * indentation) + line for line in lines]
136+
return "\n".join(indented_lines)
135137

136138
@staticmethod
137139
def _format_markdown(text: str) -> str:
138-
re_match_newlines = re.compile(r'\n{3,}')
139-
re_match_headers = re.compile(r'(#{1,6}.+)\n+')
140+
re_match_newlines = re.compile(r"\n{3,}")
141+
re_match_headers = re.compile(r"(#{1,6}.+)\n+")
140142

141-
text = re_match_newlines.sub(r'\n\n', text)
142-
text = re_match_headers.sub(r'\1\n\n', text)
143+
text = re_match_newlines.sub(r"\n\n", text)
144+
text = re_match_headers.sub(r"\1\n\n", text)
143145
return text
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
21
from .memdb import MemDB
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from cloudquery.sdk import plugin
32
from cloudquery.sdk import message
43
from cloudquery.sdk import schema
@@ -8,17 +7,20 @@
87
NAME = "memdb"
98
VERSION = "development"
109

10+
1111
class MemDB(plugin.Plugin):
1212
def __init__(self) -> None:
13-
super().__init__(NAME, VERSION)
14-
self._tables: List[schema.Table] = []
15-
self._memory_db : Dict[str, pa.record] = {
16-
"test_table": pa.record_batch([pa.array([1, 2, 3])], names=["test_column"])
17-
}
18-
19-
def get_tables(self, options : plugin.TableOptions = None) -> List[plugin.Table]:
20-
return self._tables
21-
22-
def sync(self, options: plugin.SyncOptions) -> Generator[message.SyncMessage, None, None]:
23-
for table, record in self._memory_db.items():
24-
yield message.SyncInsertMessage(record)
13+
super().__init__(NAME, VERSION)
14+
self._tables: List[schema.Table] = []
15+
self._memory_db: Dict[str, pa.record] = {
16+
"test_table": pa.record_batch([pa.array([1, 2, 3])], names=["test_column"])
17+
}
18+
19+
def get_tables(self, options: plugin.TableOptions = None) -> List[plugin.Table]:
20+
return self._tables
21+
22+
def sync(
23+
self, options: plugin.SyncOptions
24+
) -> Generator[message.SyncMessage, None, None]:
25+
for table, record in self._memory_db.items():
26+
yield message.SyncInsertMessage(record)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
from .plugin import PluginServicer
1+
from .plugin import PluginServicer

cloudquery/sdk/internal/servers/plugin_v3/plugin.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def Init(self, request: plugin_pb2.Init.Request, context):
2323
return plugin_pb2.Init.Response()
2424

2525
def GetTables(self, request: plugin_pb2.GetTables.Request, context):
26-
tables = self._plugin.get_tables(TableOptions(tables=request.tables, skip_tables=request.skip_tables))
26+
tables = self._plugin.get_tables(
27+
TableOptions(tables=request.tables, skip_tables=request.skip_tables)
28+
)
2729
schema = tables_to_arrow_schemas(tables)
2830
tablesBytes = []
2931
for s in schema:
@@ -51,13 +53,15 @@ def Sync(self, request, context):
5153
writer.write_batch(msg.record)
5254
writer.close()
5355
buf = sink.getvalue().to_pybytes()
54-
yield plugin_pb2.Sync.Response(insert=plugin_pb2.Sync.MessageInsert(
55-
record=buf
56-
))
56+
yield plugin_pb2.Sync.Response(
57+
insert=plugin_pb2.Sync.MessageInsert(record=buf)
58+
)
5759
elif isinstance(msg, SyncMigrateTableMessage):
58-
yield plugin_pb2.Sync.Response(migrate_table=plugin_pb2.Sync.MessageMigrateTable(
59-
table=msg.table.to_arrow_schema().serialize().to_pybytes()
60-
))
60+
yield plugin_pb2.Sync.Response(
61+
migrate_table=plugin_pb2.Sync.MessageMigrateTable(
62+
table=msg.table.to_arrow_schema().serialize().to_pybytes()
63+
)
64+
)
6165
else:
6266
# unknown sync message type
6367
raise NotImplementedError()

cloudquery/sdk/plugin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .plugin import Plugin, Table, TableOptions, SyncOptions
1+
from .plugin import Plugin, Table, TableOptions, SyncOptions

cloudquery/sdk/scalar/binary.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
from cloudquery.sdk.scalar import Scalar, ScalarInvalidTypeError
22
from .scalar import NULL_VALUE
33

4+
45
class Binary(Scalar):
56
def __init__(self, valid: bool = False, value: bytes = None):
6-
self._valid = valid
7-
self._value = value
7+
self._valid = valid
8+
self._value = value
89

910
def __eq__(self, scalar: Scalar) -> bool:
10-
if scalar is None:
11-
return False
12-
if type(scalar) == Binary:
13-
return self._value == scalar._value and self._valid == scalar._valid
14-
return False
15-
11+
if scalar is None:
12+
return False
13+
if type(scalar) == Binary:
14+
return self._value == scalar._value and self._valid == scalar._valid
15+
return False
16+
1617
def __str__(self) -> str:
17-
return str(self._value) if self._valid else NULL_VALUE
18+
return str(self._value) if self._valid else NULL_VALUE
1819

1920
@property
2021
def value(self):
21-
return self._value
22-
22+
return self._value
23+
2324
def set(self, scalar):
24-
if scalar is None:
25-
return
25+
if scalar is None:
26+
return
2627

27-
if type(scalar) == bytes:
28-
self._valid = True
29-
self._value = scalar
30-
elif type(scalar) == str:
31-
self._valid = True
32-
self._value = scalar.encode()
33-
else:
34-
raise ScalarInvalidTypeError("Invalid type for Binary scalar")
28+
if type(scalar) == bytes:
29+
self._valid = True
30+
self._value = scalar
31+
elif type(scalar) == str:
32+
self._valid = True
33+
self._value = scalar.encode()
34+
else:
35+
raise ScalarInvalidTypeError("Invalid type for Binary scalar")

cloudquery/sdk/scalar/bool.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
21
from cloudquery.sdk.scalar import Scalar, ScalarInvalidTypeError, NULL_VALUE
32
from typing import Any
43

4+
55
def parse_string_to_bool(input_string):
6-
true_strings = ['true', 't', 'yes', 'y', '1']
7-
false_strings = ['false', 'f', 'no', 'n', '0']
6+
true_strings = ["true", "t", "yes", "y", "1"]
7+
false_strings = ["false", "f", "no", "n", "0"]
88

99
lower_input = input_string.lower()
1010

@@ -15,34 +15,35 @@ def parse_string_to_bool(input_string):
1515
else:
1616
raise ScalarInvalidTypeError("Invalid boolean string: {}".format(input_string))
1717

18+
1819
class Bool(Scalar):
1920
def __init__(self, valid: bool = False, value: bool = False) -> None:
20-
self._valid = valid
21-
self._value = value
22-
21+
self._valid = valid
22+
self._value = value
23+
2324
def __eq__(self, scalar: Scalar) -> bool:
24-
if scalar is None:
25-
return False
26-
if type(scalar) == Bool:
27-
return self._value == scalar._value and self._valid == scalar._valid
28-
return False
25+
if scalar is None:
26+
return False
27+
if type(scalar) == Bool:
28+
return self._value == scalar._value and self._valid == scalar._valid
29+
return False
2930

3031
def __str__(self) -> str:
31-
return str(self._value) if self._valid else NULL_VALUE
32+
return str(self._value) if self._valid else NULL_VALUE
3233

3334
@property
3435
def value(self):
35-
return self._value
36-
36+
return self._value
37+
3738
def set(self, value: Any):
38-
if value is None:
39-
return
39+
if value is None:
40+
return
4041

41-
if type(value) == bool:
42-
self._value = value
43-
elif type(value) == str:
44-
self._value = parse_string_to_bool(value)
45-
else:
46-
raise ScalarInvalidTypeError("Invalid type for Bool scalar")
47-
48-
self._valid = True
42+
if type(value) == bool:
43+
self._value = value
44+
elif type(value) == str:
45+
self._value = parse_string_to_bool(value)
46+
else:
47+
raise ScalarInvalidTypeError("Invalid type for Bool scalar")
48+
49+
self._valid = True

0 commit comments

Comments
 (0)