Skip to content

Commit 93a2563

Browse files
authored
Merge pull request #27 from hhatto/formatter
add code formatter
2 parents 4d4cef7 + 75c8ca8 commit 93a2563

11 files changed

Lines changed: 103 additions & 106 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
- name: Lint with ruff
3636
run: |
3737
ruff check .
38+
- name: Check code format with black
39+
run: |
40+
black --check --diff .
3841
- name: Test with pytest
3942
run: |
4043
pytest

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ run linter::
180180
$ ruff .
181181

182182

183+
run formatter::
184+
185+
$ black --diff .
186+
187+
183188
Links
184189
=====
185190
* PyPI_

examples/codesearch/1_create.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
print(ret.status)
1717
ret = grn.call("column_create", table="Files", name="name", flags="COLUMN_SCALAR", type="ShortText")
1818
print(ret.status)
19-
ret = grn.call(
20-
"column_create", table="Files", name="content", flags="COLUMN_SCALAR", type="ShortText"
21-
)
19+
ret = grn.call("column_create", table="Files", name="content", flags="COLUMN_SCALAR", type="ShortText")
2220
print(ret.status)
2321

2422
ret = grn.call(

examples/codesearch/3_search.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
query = "content:@%s" % sys.argv[1]
66
grn = Groonga()
7-
ret = grn.call(
8-
"select", table="Files", limit=1000, sortby="-_score", output_columns="_score,_key", query=query
9-
)
7+
ret = grn.call("select", table="Files", limit=1000, sortby="-_score", output_columns="_score,_key", query=query)
108
for item in ret.items:
119
print("[score:%3d]%s" % (item["_score"], item["_key"]))
1210
print("hit:", ret.hit_num)

examples/groonga_microblog_tutorial/1_crate.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,9 @@ def _call(g, cmd, **kwargs):
2525
_call(g, "column_create", table="Users", name="name", flags="COLUMN_SCALAR", type="ShortText")
2626
_call(g, "column_create", table="Users", name="follower", flags="COLUMN_VECTOR", type="Users")
2727
_call(g, "column_create", table="Users", name="favorites", flags="COLUMN_VECTOR", type="Comments")
28-
_call(
29-
g, "column_create", table="Users", name="location", flags="COLUMN_SCALAR", type="WGS84GeoPoint"
30-
)
31-
_call(
32-
g, "column_create", table="Users", name="location_str", flags="COLUMN_SCALAR", type="ShortText"
33-
)
34-
_call(
35-
g, "column_create", table="Users", name="description", flags="COLUMN_SCALAR", type="ShortText"
36-
)
28+
_call(g, "column_create", table="Users", name="location", flags="COLUMN_SCALAR", type="WGS84GeoPoint")
29+
_call(g, "column_create", table="Users", name="location_str", flags="COLUMN_SCALAR", type="ShortText")
30+
_call(g, "column_create", table="Users", name="description", flags="COLUMN_SCALAR", type="ShortText")
3731
_call(
3832
g,
3933
"column_create",
@@ -45,18 +39,10 @@ def _call(g, cmd, **kwargs):
4539
)
4640

4741
_call(g, "column_create", table="Comments", name="comment", flags="COLUMN_SCALAR", type="ShortText")
48-
_call(
49-
g, "column_create", table="Comments", name="last_modified", flags="COLUMN_SCALAR", type="Time"
50-
)
51-
_call(
52-
g, "column_create", table="Comments", name="replied_to", flags="COLUMN_SCALAR", type="Comments"
53-
)
54-
_call(
55-
g, "column_create", table="Comments", name="replied_users", flags="COLUMN_VECTOR", type="Users"
56-
)
57-
_call(
58-
g, "column_create", table="Comments", name="hash_tags", flags="COLUMN_VECTOR", type="HashTags"
59-
)
42+
_call(g, "column_create", table="Comments", name="last_modified", flags="COLUMN_SCALAR", type="Time")
43+
_call(g, "column_create", table="Comments", name="replied_to", flags="COLUMN_SCALAR", type="Comments")
44+
_call(g, "column_create", table="Comments", name="replied_users", flags="COLUMN_VECTOR", type="Users")
45+
_call(g, "column_create", table="Comments", name="hash_tags", flags="COLUMN_VECTOR", type="HashTags")
6046
_call(
6147
g,
6248
"column_create",

examples/groonga_microblog_tutorial/2_load_with_pyarrow.py

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,68 @@ def load_and_select(table, data, batch):
3636
pa.array(["神奈川県", "東京都渋谷区", "東京都中野区"]),
3737
pa.array(["groonga developer", "エロいおっさん", "がおがお"]),
3838
]
39-
users_batch = pa.record_batch(users, names=["_key", "name", "follower", "favorites", "location", "location_str", "description"])
39+
users_batch = pa.record_batch(
40+
users, names=["_key", "name", "follower", "favorites", "location", "location_str", "description"]
41+
)
4042
load_and_select("Users", users, users_batch)
4143

4244

4345
comments = [
44-
pa.array(["daijiro:1", "tasukuchan:1", "daijiro:2", "tasukuchan:2", "tasukuchan:3", "tasukuchan:4", "OffGao:1", "OffGao:2"]),
45-
pa.array([
46-
"マイクロブログ作ってみました(甘栗むいちゃいました的な感じで)。",
47-
"初の書き込み。テストテスト。",
48-
"@tasukuchan ようこそ!!!",
49-
"@daijiro ありがとう!",
50-
"groongaなう #groonga",
51-
"groonga開発合宿のため羽田空港に来ました! #groonga #travel",
52-
"@daijiro @tasukuchan 登録してみましたよー!",
53-
"中野ブロードウェイなうなう",
54-
]),
55-
pa.array([
56-
"2010/03/17 12:05:00", "2010/03/17 12:00:00", "2010/03/17 12:05:00", "2010/03/17 13:00:00",
57-
"2010/03/17 14:00:00", "2010/03/17 14:05:00", "2010/03/17 15:00:00", "2010/03/17 15:05:00",
58-
]),
46+
pa.array(
47+
[
48+
"daijiro:1",
49+
"tasukuchan:1",
50+
"daijiro:2",
51+
"tasukuchan:2",
52+
"tasukuchan:3",
53+
"tasukuchan:4",
54+
"OffGao:1",
55+
"OffGao:2",
56+
]
57+
),
58+
pa.array(
59+
[
60+
"マイクロブログ作ってみました(甘栗むいちゃいました的な感じで)。",
61+
"初の書き込み。テストテスト。",
62+
"@tasukuchan ようこそ!!!",
63+
"@daijiro ありがとう!",
64+
"groongaなう #groonga",
65+
"groonga開発合宿のため羽田空港に来ました! #groonga #travel",
66+
"@daijiro @tasukuchan 登録してみましたよー!",
67+
"中野ブロードウェイなうなう",
68+
]
69+
),
70+
pa.array(
71+
[
72+
"2010/03/17 12:05:00",
73+
"2010/03/17 12:00:00",
74+
"2010/03/17 12:05:00",
75+
"2010/03/17 13:00:00",
76+
"2010/03/17 14:00:00",
77+
"2010/03/17 14:05:00",
78+
"2010/03/17 15:00:00",
79+
"2010/03/17 15:05:00",
80+
]
81+
),
5982
pa.array([None, None, "tasukuchan:1", "daijiro:2", None, None, None, None]),
6083
pa.array([None, None, ["tasukuchan"], ["daijiro"], None, None, ["daijiro", "tasukuchan"], None]),
6184
pa.array([None, None, None, None, ["groonga"], ["groonga", "travel"], None, None]),
62-
pa.array([None, None, None, None, "127972422x503117107", "127975798x502919856", "128551935x502796433", "128551935x502796434"]),
85+
pa.array(
86+
[
87+
None,
88+
None,
89+
None,
90+
None,
91+
"127972422x503117107",
92+
"127975798x502919856",
93+
"128551935x502796433",
94+
"128551935x502796434",
95+
]
96+
),
6397
pa.array(["daijiro", "tasukuchan", "daijiro", "tasukuchan", "tasukuchan", "tasukuchan", "OffGao", "OffGao"]),
6498
]
65-
comments_batch = pa.record_batch(comments, names=[
66-
"_key", "comment", "last_modified", "replied_to", "replied_users", "hash_tags", "location", "posted_by"
67-
])
99+
comments_batch = pa.record_batch(
100+
comments,
101+
names=["_key", "comment", "last_modified", "replied_to", "replied_users", "hash_tags", "location", "posted_by"],
102+
)
68103
load_and_select("Comments", comments, comments_batch)

poyonga/client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ def get_send_data_for_gqtp(cmd, **kwargs):
3232

3333
def convert_gqtp_result_data(_start, _end, status, raw_data):
3434
# struct result data
35-
diff_time = (_end.tv_sec + _end.tv_nsec / 1000000000.0) - (
36-
_start.tv_sec + _start.tv_nsec / 1000000000.0
37-
)
35+
diff_time = (_end.tv_sec + _end.tv_nsec / 1000000000.0) - (_start.tv_sec + _start.tv_nsec / 1000000000.0)
3836
if status != 0:
3937
status -= 65536
4038
body = '"",[["","",0]]'
@@ -47,7 +45,6 @@ def convert_gqtp_result_data(_start, _end, status, raw_data):
4745

4846

4947
class Groonga:
50-
5148
LIBRT = CDLL(find_library("rt"))
5249
LIBC = CDLL(find_library("c"))
5350

@@ -61,9 +58,7 @@ class _TimeSpec:
6158
tv_sec = 0.0
6259
tv_nsec = 0.0
6360

64-
def __init__(
65-
self, host="localhost", port=10041, protocol="http", encoding="utf-8", prefix_path="/d/"
66-
):
61+
def __init__(self, host="localhost", port=10041, protocol="http", encoding="utf-8", prefix_path="/d/"):
6762
self.host = host
6863
self.port = port
6964
self.protocol = protocol

poyonga/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from enum import StrEnum
33
except ImportError:
44
from enum import Enum
5+
56
class StrEnum(str, Enum): # noqa
67
pass
78

poyonga/result.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ def _parse_apache_arrow_body(self, table):
100100
raise NotImplementedError("Apache Arrow data is not supported")
101101

102102
def __str__(self):
103-
return f"<{type(self).__name__} " + \
104-
f"status={self.status} " + \
105-
f"start_time={self.start_time} " + \
106-
f"elapsed={self.elapsed}>"
103+
return (
104+
f"<{type(self).__name__} "
105+
+ f"status={self.status} "
106+
+ f"start_time={self.start_time} "
107+
+ f"elapsed={self.elapsed}>"
108+
)
107109

108110

109111
class GroongaSelectResult(GroongaResult):

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Repository = "https://github.com/hhatto/poyonga"
3131
dev = [
3232
"ruff",
3333
"pytest",
34+
"black",
3435
]
3536

3637
[tool.setuptools]
@@ -56,3 +57,6 @@ extend-exclude = [
5657
"examples",
5758
]
5859
line-length = 120
60+
61+
[tool.black]
62+
line-length = 120

0 commit comments

Comments
 (0)