Skip to content

Commit 60e21cf

Browse files
committed
black format
1 parent 74f51eb commit 60e21cf

15 files changed

+115
-95
lines changed

benchmarks/benchmark_funcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def benchmark_int8_to_datetime():
88

99

1010
def rand_int():
11-
return random.randint(0, 0xffffffff)
11+
return random.randint(0, 0xFFFFFFFF)
1212

1313

1414
@benchmark_setup(i=rand_int)

benchmarks/benchmark_strhash.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ def benchmark_strhash_default_method(string):
1313

1414
@benchmark_setup(string=new_str)
1515
def benchmark_strhash_fnv1a(string):
16-
ctools.strhash(string, 'fnv1a')
16+
ctools.strhash(string, "fnv1a")
1717

1818

1919
@benchmark_setup(string=new_str)
2020
def benchmark_strhash_fnv1(string):
21-
ctools.strhash(string, 'fnv1')
21+
ctools.strhash(string, "fnv1")
2222

2323

2424
@benchmark_setup(string=new_str)
2525
def benchmark_strhash_djb2(string):
26-
ctools.strhash(string, 'djb2')
26+
ctools.strhash(string, "djb2")
2727

2828

2929
@benchmark_setup(string=new_str)
3030
def benchmark_strhash_murmur(string):
31-
ctools.strhash(string, 'murmur')
31+
ctools.strhash(string, "murmur")

ctools/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@
2222

2323
test = Tester(__name__)
2424
del Tester
25-

ctools/_tester.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,32 @@
2121

2222
def _show_info(test_args):
2323
import ctools
24+
2425
title = "Testing Information"
2526
print("\n-" * len(title))
2627
print(title)
2728
print("-" * len(title))
2829
print("Python: ", sys.executable)
29-
print('Ctools:', ctools.__version__, "(debug build)" if ctools.build_with_debug() else "")
30-
print("Arguments:", " ".join(test_args), '\n')
30+
print(
31+
"Ctools:",
32+
ctools.__version__,
33+
"(debug build)" if ctools.build_with_debug() else "",
34+
)
35+
print("Arguments:", " ".join(test_args), "\n")
3136

3237

3338
class Tester(object):
3439
def __init__(self, module_name):
3540
self.module_name = module_name
3641

37-
def __call__(self, extra_argv=None, coverage=False, include_sys_argv=True, tests=None,
38-
verbose=True):
42+
def __call__(
43+
self,
44+
extra_argv=None,
45+
coverage=False,
46+
include_sys_argv=True,
47+
tests=None,
48+
verbose=True,
49+
):
3950
import pytest
4051

4152
module = sys.modules[self.module_name]
@@ -55,11 +66,11 @@ def __call__(self, extra_argv=None, coverage=False, include_sys_argv=True, tests
5566
test_args.extend(sys.argv[1:])
5667

5768
test_args += ["--pyargs"] + list(tests)
58-
test_args += ["--deselect", os.path.join(here, 'tests', '_bases.py')]
69+
test_args += ["--deselect", os.path.join(here, "tests", "_bases.py")]
5970

6071
if verbose:
6172
for i in test_args:
62-
if i.startswith('-v'):
73+
if i.startswith("-v"):
6374
break
6475
else:
6576
test_args.append("-vvv")
@@ -74,11 +85,13 @@ def __call__(self, extra_argv=None, coverage=False, include_sys_argv=True, tests
7485
return code
7586

7687

77-
_memory_report = namedtuple('MemoryReport', "exc_code,cycles,max_rss,last_rss,max_incr,cum_incr,escaped")
88+
_memory_report = namedtuple(
89+
"MemoryReport", "exc_code,cycles,max_rss,last_rss,max_incr,cum_incr,escaped"
90+
)
7891

7992

8093
def memory_leak_test(
81-
test, max_rss=None, max_incr=None, cycles=None, multi=10, log_prefix="", log=True,
94+
test, max_rss=None, max_incr=None, cycles=None, multi=10, log_prefix="", log=True
8295
):
8396
import time
8497
import psutil
@@ -90,7 +103,7 @@ def memory_leak_test(
90103

91104
pid = os.getpid()
92105
process = psutil.Process(pid)
93-
print_('PID =', pid)
106+
print_("PID =", pid)
94107

95108
cycle_count = 1
96109
last_rss = None
@@ -124,15 +137,17 @@ def memory_leak_test(
124137
incr_limit = multi * cum_incr
125138

126139
print_(log_prefix, end=" ")
127-
print_(f"loop={cycle_count}, escaped={spend}, rss={rss_bytes:,}, increase={incr:,}")
140+
print_(
141+
f"loop={cycle_count}, escaped={spend}, rss={rss_bytes:,}, increase={incr:,}"
142+
)
128143

129144
if rss_limit and rss_bytes > rss_limit:
130145
print_(f"rss {rss_bytes:,} touch roof {rss_limit:,}")
131146
exc_code = 1
132147
break
133148

134149
if incr_limit and cum_incr > incr_limit:
135-
print_(f'rss increase {cum_incr:,} touch roof {incr_limit:,}')
150+
print_(f"rss increase {cum_incr:,} touch roof {incr_limit:,}")
136151
exc_code = 1
137152
break
138153

@@ -145,8 +160,14 @@ def memory_leak_test(
145160
break
146161

147162
except KeyboardInterrupt:
148-
print_(_memory_report(exc_code, cycle_count, max_rss, last_rss, max_incr, cum_incr, escaped))
163+
print_(
164+
_memory_report(
165+
exc_code, cycle_count, max_rss, last_rss, max_incr, cum_incr, escaped
166+
)
167+
)
149168
raise
150-
report = _memory_report(exc_code, cycle_count, max_rss, last_rss, max_incr, cum_incr, escaped)
169+
report = _memory_report(
170+
exc_code, cycle_count, max_rss, last_rss, max_incr, cum_incr, escaped
171+
)
151172
print_(report)
152173
return report

ctools/tests/_bases.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def not_raise(exc=Exception):
2121

2222

2323
class TestCase(unittest.TestCase):
24-
2524
def assertRefEqual(self, a, b, msg=None):
2625
self.assertEqual(sys.getrefcount(a), sys.getrefcount(b), msg=msg)
2726

@@ -52,7 +51,6 @@ def map_set_random(mp):
5251

5352

5453
class DefaultMap(dict):
55-
5654
def setnx(self, k, ca):
5755
if k not in self:
5856
v = ca()
@@ -287,7 +285,7 @@ def test_normal_update(self):
287285
self.assertRefEqual(dkey, ckey)
288286
self.assertRefEqual(dval, cval)
289287
self.assertEqual(len(cache), len(mp))
290-
self.assertIn('a', cache)
288+
self.assertIn("a", cache)
291289

292290
def test_normal_setdefault(self):
293291
cache = self.create_map()
@@ -340,7 +338,7 @@ def test_normal_clear(self):
340338
dkey, dval = map_set_random(mp)
341339
cache.clear()
342340
mp.clear()
343-
self.assertEqual(len(cache), 0, msg='cache map is not empty after clear')
341+
self.assertEqual(len(cache), 0, msg="cache map is not empty after clear")
344342
self.assertRefEqual(ckey, dkey)
345343
self.assertRefEqual(cval, dval)
346344

@@ -365,5 +363,5 @@ def test_error_set(self):
365363
self.assertRefEqual(cval, dval)
366364

367365

368-
if __name__ == '__main__':
366+
if __name__ == "__main__":
369367
unittest.main()

ctools/tests/test_cachemap.py

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

88

99
class TestCacheMapEntry(BaseTestEntry):
10-
1110
def create_entry(self):
1211
return ctools.CacheMapEntry(uuid.uuid1())
1312

@@ -20,19 +19,18 @@ def set_random(mp):
2019

2120

2221
class TestCacheMap(BaseTestMapLike):
23-
2422
def create_map(self):
2523
return ctools.CacheMap(257)
2624

2725
def test_get_set(self):
2826
d = ctools.CacheMap(2)
29-
d['a'] = 1
30-
d['c'] = 2
31-
d['e'] = 3
27+
d["a"] = 1
28+
d["c"] = 2
29+
d["e"] = 3
3230
self.assertEqual(len(d), 2)
3331

3432
for i in range(10):
35-
self.assertEqual(d['c'], 2)
33+
self.assertEqual(d["c"], 2)
3634

3735
def test_len(self):
3836
for m in range(254, 1024):
@@ -47,5 +45,5 @@ def test_len(self):
4745

4846
del BaseTestEntry, BaseTestMapLike
4947

50-
if __name__ == '__main__':
48+
if __name__ == "__main__":
5149
unittest.main()

ctools/tests/test_function.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class TestFunction(unittest.TestCase):
10-
1110
def test_int8_to_datetime(self):
1211
start = datetime(2000, 1, 1)
1312
for i in range(1024):
@@ -21,17 +20,11 @@ def test_int8_to_datetime(self):
2120
def test_jump_consistent_hash(self):
2221
count = 1024
2322
bucket = 100
24-
m = {
25-
i: ctools.jump_consistent_hash(i, bucket)
26-
for i in range(count)
27-
}
23+
m = {i: ctools.jump_consistent_hash(i, bucket) for i in range(count)}
2824
for i in range(count):
2925
b = ctools.jump_consistent_hash(i, bucket)
3026
self.assertEqual(m[i], b)
31-
n = {
32-
i: ctools.jump_consistent_hash(i, bucket + 1)
33-
for i in range(count)
34-
}
27+
n = {i: ctools.jump_consistent_hash(i, bucket + 1) for i in range(count)}
3528
equal_count = 0
3629
for i in range(count):
3730
if m[i] == n[i]:
@@ -54,10 +47,10 @@ def test_strhash(self):
5447
self.assertEqual(b, ctools.strhash(us, meth))
5548

5649
self.assertEqual(ctools.strhash(s), ctools.strhash(s, "fnv1a"))
57-
self.assertEqual(ctools.strhash(us), ctools.strhash(us, 'fnv1a'))
50+
self.assertEqual(ctools.strhash(us), ctools.strhash(us, "fnv1a"))
5851

5952
self.assertNotEqual(ctools.strhash(s), ctools.strhash(s, "fnv1"))
6053
self.assertNotEqual(ctools.strhash(s), ctools.strhash(s, "fnv1"))
6154

6255
with self.assertRaises(TypeError):
63-
ctools.strhash(s, method='fnv1a')
56+
ctools.strhash(s, method="fnv1a")

ctools/tests/test_ttlcache.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class TestTTLCacheEntry(BaseTestEntry):
11-
1211
def create_entry(self):
1312
return ctools.TTLCacheEntry(uuid.uuid1(), 1024)
1413

@@ -21,7 +20,6 @@ def set_random(mp):
2120

2221

2322
class TestTTLCache(BaseTestMapLike):
24-
2523
def create_map(self):
2624
return ctools.TTLCache(1024)
2725

@@ -48,5 +46,5 @@ def test_expire(self):
4846

4947
del BaseTestEntry, BaseTestMapLike
5048

51-
if __name__ == '__main__':
49+
if __name__ == "__main__":
5250
unittest.main()

setup.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@ def source(*args):
2626
return [os.path.join("src", *args)]
2727

2828

29-
if os.getenv('CTOOLS_DEBUG', '').upper() == "ON":
30-
print('---------------CTOOLS DEBUG ON------------------')
31-
extra_extension_args = dict(
32-
undef_macros=["NDEBUG"]
33-
)
29+
if os.getenv("CTOOLS_DEBUG", "").upper() == "ON":
30+
print("---------------CTOOLS DEBUG ON------------------")
31+
extra_extension_args = dict(undef_macros=["NDEBUG"])
3432
else:
35-
print('---------------CTOOLS DEBUG OFF------------------')
36-
extra_extension_args = dict(
37-
define_macros=[('NDEBUG', '1')]
38-
)
33+
print("---------------CTOOLS DEBUG OFF------------------")
34+
extra_extension_args = dict(define_macros=[("NDEBUG", "1")])
3935

4036

4137
def find_version():
@@ -44,7 +40,7 @@ def find_version():
4440
value = f.read()
4541
exec(value, d, d)
4642

47-
return d['__version__']
43+
return d["__version__"]
4844

4945

5046
extensions = [
@@ -53,7 +49,7 @@ def find_version():
5349
Extension("_ctools_ttlcache", source("ctools_ttlcache.c"), **extra_extension_args),
5450
]
5551

56-
with io.open('README.rst', 'rt', encoding='utf8') as f:
52+
with io.open("README.rst", "rt", encoding="utf8") as f:
5753
readme = f.read()
5854

5955
setup(
@@ -68,14 +64,14 @@ def find_version():
6864
"Documentation": "https://github.com/ko-han/python-ctools/wiki",
6965
"Source Code": "https://github.com/ko-han/python-ctools",
7066
},
71-
license='Apache License 2.0',
67+
license="Apache License 2.0",
7268
long_description=readme,
73-
long_description_content_type='text/x-rst',
69+
long_description_content_type="text/x-rst",
7470
python_requires=">=3",
7571
include_package_data=True,
7672
zip_safe=False,
7773
ext_modules=extensions,
78-
packages=find_packages(include=['ctools', 'ctools.*']),
74+
packages=find_packages(include=["ctools", "ctools.*"]),
7975
classifiers=[
8076
"Programming Language :: C",
8177
"Programming Language :: Python :: 3 :: Only",

src/ctools_ttlcache.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,10 @@ static PyMethodDef TTLCache_methods[] = {
596596
{ "clear", (PyCFunction)TTLCache_clear, METH_NOARGS, NULL },
597597
{ "setnx", (PyCFunction)TTLCache_setnx, METH_VARARGS | METH_KEYWORDS, NULL },
598598
{ "_storage", (PyCFunction)TTLCache__storage, METH_NOARGS, NULL },
599-
{ "get_default_ttl", (PyCFunction)TTLCache_get_default_ttl, METH_NOARGS, NULL },
599+
{ "get_default_ttl",
600+
(PyCFunction)TTLCache_get_default_ttl,
601+
METH_NOARGS,
602+
NULL },
600603
{ NULL, NULL, 0, NULL } /* Sentinel */
601604
};
602605

tools/genapidoc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
66

7-
with open(os.path.join(project_root, 'ctools', "__init__.pyi")) as f:
7+
with open(os.path.join(project_root, "ctools", "__init__.pyi")) as f:
88
s = f.read()
99

1010
doc = re.split("##----*start----*##", s, 1, re.MULTILINE)[1].lstrip()
1111

12-
api_list = [i for i in re.split('#- api', doc) if i]
12+
api_list = [i for i in re.split("#- api", doc) if i]
1313

1414
des_regex = re.compile("#- description:(?P<des>.*)")
1515

@@ -19,15 +19,15 @@
1919
match = des_regex.search(api)
2020
if not match:
2121
lines.append("```python\n{}\n```".format(api.strip()))
22-
lines.append('\n')
22+
lines.append("\n")
2323
else:
24-
description = match.group('des').strip()
24+
description = match.group("des").strip()
2525
if description:
2626
lines.append("* {}\n".format(description))
2727
api = des_regex.sub("", api).strip()
2828
lines.append("```python\n{}\n```".format(api))
2929
lines.append("\n\n\n")
3030

3131

32-
with open(os.path.join(project_root, 'doc', 'api.md'), 'wt') as f:
32+
with open(os.path.join(project_root, "doc", "api.md"), "wt") as f:
3333
f.writelines(lines)

0 commit comments

Comments
 (0)