Commit 77ab1491 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Apply black formatter to .py files

Summary: [Folly] Apply `black` formatter to `.py` files.

Reviewed By: zertosh

Differential Revision: D17898404

fbshipit-source-id: b597b55b646e539a288d175e0b2db8111b5b103b
parent d2c64d94
...@@ -4,7 +4,7 @@ from __future__ import division ...@@ -4,7 +4,7 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
from __future__ import unicode_literals from __future__ import unicode_literals
'fbcode_builder steps to build & test folly' "fbcode_builder steps to build & test folly"
import specs.fmt as fmt import specs.fmt as fmt
import specs.gmock as gmock import specs.gmock as gmock
...@@ -14,29 +14,27 @@ from shell_quoting import ShellQuoted ...@@ -14,29 +14,27 @@ from shell_quoting import ShellQuoted
def fbcode_builder_spec(builder): def fbcode_builder_spec(builder):
builder.add_option( builder.add_option(
'folly/_build:cmake_defines', "folly/_build:cmake_defines", {"BUILD_SHARED_LIBS": "OFF", "BUILD_TESTS": "ON"}
{
'BUILD_SHARED_LIBS': 'OFF',
'BUILD_TESTS': 'ON',
}
) )
return { return {
'depends_on': [fmt, gmock], "depends_on": [fmt, gmock],
'steps': [ "steps": [
builder.fb_github_cmake_install('folly/_build'), builder.fb_github_cmake_install("folly/_build"),
builder.step( builder.step(
'Run folly tests', [ "Run folly tests",
[
builder.run( builder.run(
ShellQuoted('ctest --output-on-failure -j {n}') ShellQuoted("ctest --output-on-failure -j {n}").format(
.format(n=builder.option('make_parallelism'), ) n=builder.option("make_parallelism")
)
) )
] ],
), ),
] ],
} }
config = { config = {
'github_project': 'facebook/folly', "github_project": "facebook/folly",
'fbcode_builder_spec': fbcode_builder_spec, "fbcode_builder_spec": fbcode_builder_spec,
} }
This diff is collapsed.
...@@ -16,7 +16,7 @@ class FiberPrinter: ...@@ -16,7 +16,7 @@ class FiberPrinter:
def __init__(self, val): def __init__(self, val):
self.val = val self.val = val
state = self.val['state_'] state = self.val["state_"]
d = gdb.types.make_enum_dict(state.type) d = gdb.types.make_enum_dict(state.type)
d = dict((v, k) for k, v in d.items()) d = dict((v, k) for k, v in d.items())
self.state = d[int(state)] self.state = d[int(state)]
...@@ -39,9 +39,11 @@ class FiberPrinter: ...@@ -39,9 +39,11 @@ class FiberPrinter:
return "Unknown" return "Unknown"
def backtrace_available(self): def backtrace_available(self):
return self.state != "folly::fibers::Fiber::INVALID" and \ return (
self.state != "folly::fibers::Fiber::NOT_STARTED" and \ self.state != "folly::fibers::Fiber::INVALID"
self.state != "folly::fibers::Fiber::RUNNING" and self.state != "folly::fibers::Fiber::NOT_STARTED"
and self.state != "folly::fibers::Fiber::RUNNING"
)
def children(self): def children(self):
result = collections.OrderedDict() result = collections.OrderedDict()
...@@ -58,17 +60,15 @@ class FiberPrinter: ...@@ -58,17 +60,15 @@ class FiberPrinter:
class GetFiberXMethodWorker(gdb.xmethod.XMethodWorker): class GetFiberXMethodWorker(gdb.xmethod.XMethodWorker):
def get_arg_types(self): def get_arg_types(self):
return gdb.lookup_type('int') return gdb.lookup_type("int")
def get_result_type(self): def get_result_type(self):
return gdb.lookup_type('int') return gdb.lookup_type("int")
def __call__(self, *args): def __call__(self, *args):
fm = args[0] fm = args[0]
index = int(args[1]) index = int(args[1])
fiber = next(itertools.islice(fiber_manager_active_fibers(fm), fiber = next(itertools.islice(fiber_manager_active_fibers(fm), index, None))
index,
None))
if fiber is None: if fiber is None:
raise gdb.GdbError("Index out of range") raise gdb.GdbError("Index out of range")
else: else:
...@@ -77,35 +77,37 @@ class GetFiberXMethodWorker(gdb.xmethod.XMethodWorker): ...@@ -77,35 +77,37 @@ class GetFiberXMethodWorker(gdb.xmethod.XMethodWorker):
class GetFiberXMethodMatcher(gdb.xmethod.XMethodMatcher): class GetFiberXMethodMatcher(gdb.xmethod.XMethodMatcher):
def __init__(self): def __init__(self):
super(GetFiberXMethodMatcher, self).__init__( super(GetFiberXMethodMatcher, self).__init__("Fiber address method matcher")
"Fiber address method matcher")
self.worker = GetFiberXMethodWorker() self.worker = GetFiberXMethodWorker()
def match(self, class_type, method_name): def match(self, class_type, method_name):
if class_type.name == "folly::fibers::FiberManager" and \ if (
method_name == "get_fiber": class_type.name == "folly::fibers::FiberManager"
and method_name == "get_fiber"
):
return self.worker return self.worker
return None return None
def fiber_manager_active_fibers(fm): def fiber_manager_active_fibers(fm):
all_fibers = \ all_fibers = fm["allFibers_"]["data_"]["root_plus_size_"]["m_header"]
fm['allFibers_']['data_']['root_plus_size_']['m_header'] fiber_hook = all_fibers["next_"]
fiber_hook = all_fibers['next_']
fiber_count = 0 fiber_count = 0
while fiber_hook != all_fibers.address: while fiber_hook != all_fibers.address:
fiber = fiber_hook.cast(gdb.lookup_type("int64_t")) fiber = fiber_hook.cast(gdb.lookup_type("int64_t"))
fiber = fiber - gdb.parse_and_eval( fiber = fiber - gdb.parse_and_eval(
"(int64_t)&'folly::fibers::Fiber'::globalListHook_") "(int64_t)&'folly::fibers::Fiber'::globalListHook_"
)
fiber = fiber.cast( fiber = fiber.cast(
gdb.lookup_type('folly::fibers::Fiber').pointer()).dereference() gdb.lookup_type("folly::fibers::Fiber").pointer()
).dereference()
if FiberPrinter(fiber).state != "folly::fibers::Fiber::INVALID": if FiberPrinter(fiber).state != "folly::fibers::Fiber::INVALID":
yield fiber yield fiber
fiber_hook = fiber_hook.dereference()['next_'] fiber_hook = fiber_hook.dereference()["next_"]
fiber_count = fiber_count + 1 fiber_count = fiber_count + 1
...@@ -123,7 +125,7 @@ class FiberManagerPrinter: ...@@ -123,7 +125,7 @@ class FiberManagerPrinter:
num_items = 0 num_items = 0
for fiber in fibers_iterator: for fiber in fibers_iterator:
if num_items >= self.fiber_print_limit: if num_items >= self.fiber_print_limit:
yield ('...', '...') yield ("...", "...")
return return
yield (str(fiber.address), fiber) yield (str(fiber.address), fiber)
...@@ -141,15 +143,18 @@ class FiberManagerPrinter: ...@@ -141,15 +143,18 @@ class FiberManagerPrinter:
class FiberPrintLimitCommand(gdb.Command): class FiberPrintLimitCommand(gdb.Command):
def __init__(self): def __init__(self):
super(FiberPrintLimitCommand, self).__init__( super(FiberPrintLimitCommand, self).__init__(
"fiber-print-limit", gdb.COMMAND_USER) "fiber-print-limit", gdb.COMMAND_USER
)
def invoke(self, arg, from_tty): def invoke(self, arg, from_tty):
if not arg: if not arg:
print("New limit has to be passed to 'fiber_print_limit' command") print("New limit has to be passed to 'fiber_print_limit' command")
return return
FiberManagerPrinter.fiber_print_limit = int(arg) FiberManagerPrinter.fiber_print_limit = int(arg)
print("New fiber limit for FiberManager printer set to " + print(
str(FiberManagerPrinter.fiber_print_limit)) "New fiber limit for FiberManager printer set to "
+ str(FiberManagerPrinter.fiber_print_limit)
)
class FrameId(object): class FrameId(object):
...@@ -197,8 +202,8 @@ class FiberUnwinder(gdb.unwinder.Unwinder): ...@@ -197,8 +202,8 @@ class FiberUnwinder(gdb.unwinder.Unwinder):
cls.instance = FiberUnwinder() cls.instance = FiberUnwinder()
gdb.unwinder.register_unwinder(None, cls.instance) gdb.unwinder.register_unwinder(None, cls.instance)
fiber_impl = fiber['fiberImpl_'] fiber_impl = fiber["fiberImpl_"]
cls.instance.fiber_context_ptr = fiber_impl['fiberContext_'] cls.instance.fiber_context_ptr = fiber_impl["fiberContext_"]
def __init__(self): def __init__(self):
super(FiberUnwinder, self).__init__("Fiber unwinder") super(FiberUnwinder, self).__init__("Fiber unwinder")
...@@ -208,10 +213,10 @@ class FiberUnwinder(gdb.unwinder.Unwinder): ...@@ -208,10 +213,10 @@ class FiberUnwinder(gdb.unwinder.Unwinder):
if not self.fiber_context_ptr: if not self.fiber_context_ptr:
return None return None
orig_sp = pending_frame.read_register('rsp') orig_sp = pending_frame.read_register("rsp")
orig_pc = pending_frame.read_register('rip') orig_pc = pending_frame.read_register("rip")
void_star_star = gdb.lookup_type('uint64_t').pointer() void_star_star = gdb.lookup_type("uint64_t").pointer()
ptr = self.fiber_context_ptr.cast(void_star_star) ptr = self.fiber_context_ptr.cast(void_star_star)
# This code may need to be adjusted to newer versions of boost::context. # This code may need to be adjusted to newer versions of boost::context.
...@@ -236,9 +241,9 @@ class FiberUnwinder(gdb.unwinder.Unwinder): ...@@ -236,9 +241,9 @@ class FiberUnwinder(gdb.unwinder.Unwinder):
frame_id = FrameId(rsp, orig_pc) frame_id = FrameId(rsp, orig_pc)
unwind_info = pending_frame.create_unwind_info(frame_id) unwind_info = pending_frame.create_unwind_info(frame_id)
unwind_info.add_saved_register('rbp', rbp) unwind_info.add_saved_register("rbp", rbp)
unwind_info.add_saved_register('rsp', rsp) unwind_info.add_saved_register("rsp", rsp)
unwind_info.add_saved_register('rip', rip) unwind_info.add_saved_register("rip", rip)
self.fiber_context_ptr = None self.fiber_context_ptr = None
...@@ -279,7 +284,8 @@ class FiberActivateCommand(gdb.Command): ...@@ -279,7 +284,8 @@ class FiberActivateCommand(gdb.Command):
class FiberDeactivateCommand(gdb.Command): class FiberDeactivateCommand(gdb.Command):
def __init__(self): def __init__(self):
super(FiberDeactivateCommand, self).__init__( super(FiberDeactivateCommand, self).__init__(
"fiber-deactivate", gdb.COMMAND_USER) "fiber-deactivate", gdb.COMMAND_USER
)
def invoke(self, arg, from_tty): def invoke(self, arg, from_tty):
print(fiber_deactivate()) print(fiber_deactivate())
...@@ -302,8 +308,7 @@ class FiberXMethodMatcher(gdb.xmethod.XMethodMatcher): ...@@ -302,8 +308,7 @@ class FiberXMethodMatcher(gdb.xmethod.XMethodMatcher):
self.worker = FiberXMethodWorker() self.worker = FiberXMethodWorker()
def match(self, class_type, method_name): def match(self, class_type, method_name):
if class_type.name == "folly::fibers::Fiber" and \ if class_type.name == "folly::fibers::Fiber" and method_name == "activate":
method_name == "activate":
return self.worker return self.worker
return None return None
...@@ -322,21 +327,26 @@ def get_fiber_manager_map(evb_type): ...@@ -322,21 +327,26 @@ def get_fiber_manager_map(evb_type):
# Exception thrown if unable to find type # Exception thrown if unable to find type
# Probably because of missing debug symbols # Probably because of missing debug symbols
global_cache_type = gdb.lookup_type( global_cache_type = gdb.lookup_type(
"folly::fibers::(anonymous namespace)::GlobalCache<" + evb_type + ">") "folly::fibers::(anonymous namespace)::GlobalCache<" + evb_type + ">"
)
except gdb.error: except gdb.error:
raise gdb.GdbError("Unable to find types. " raise gdb.GdbError(
"Unable to find types. "
"Please make sure debug info is available for this binary.\n" "Please make sure debug info is available for this binary.\n"
"Have you run 'fbload debuginfo_fbpkg'?") "Have you run 'fbload debuginfo_fbpkg'?"
)
global_cache_instance_ptr_ptr = gdb.parse_and_eval( global_cache_instance_ptr_ptr = gdb.parse_and_eval(
"&'" + global_cache_type.name + "::instance()::ret'") "&'" + global_cache_type.name + "::instance()::ret'"
)
global_cache_instance_ptr = global_cache_instance_ptr_ptr.cast( global_cache_instance_ptr = global_cache_instance_ptr_ptr.cast(
global_cache_type.pointer().pointer()).dereference() global_cache_type.pointer().pointer()
).dereference()
if global_cache_instance_ptr == 0x0: if global_cache_instance_ptr == 0x0:
raise gdb.GdbError("FiberManager map is empty.") raise gdb.GdbError("FiberManager map is empty.")
global_cache_instance = global_cache_instance_ptr.dereference() global_cache_instance = global_cache_instance_ptr.dereference()
return global_cache_instance['map_'] return global_cache_instance["map_"]
def get_fiber_manager_map_evb(): def get_fiber_manager_map_evb():
...@@ -349,9 +359,10 @@ def get_fiber_manager_map_vevb(): ...@@ -349,9 +359,10 @@ def get_fiber_manager_map_vevb():
def build_pretty_printer(): def build_pretty_printer():
pp = gdb.printing.RegexpCollectionPrettyPrinter("folly_fibers") pp = gdb.printing.RegexpCollectionPrettyPrinter("folly_fibers")
pp.add_printer('fibers::Fiber', '^folly::fibers::Fiber$', FiberPrinter) pp.add_printer("fibers::Fiber", "^folly::fibers::Fiber$", FiberPrinter)
pp.add_printer('fibers::FiberManager', '^folly::fibers::FiberManager$', pp.add_printer(
FiberManagerPrinter) "fibers::FiberManager", "^folly::fibers::FiberManager$", FiberManagerPrinter
)
return pp return pp
......
...@@ -14,11 +14,11 @@ class IOBufTests(unittest.TestCase): ...@@ -14,11 +14,11 @@ class IOBufTests(unittest.TestCase):
self.assertEqual(len(ebuf), 0) self.assertEqual(len(ebuf), 0)
self.assertEqual(ebuf.chain_size(), 0) self.assertEqual(ebuf.chain_size(), 0)
self.assertEqual(ebuf.chain_count(), 8) self.assertEqual(ebuf.chain_count(), 8)
self.assertEqual(b''.join(ebuf), b'') self.assertEqual(b"".join(ebuf), b"")
self.assertEqual(b'', bytes(ebuf)) self.assertEqual(b"", bytes(ebuf))
def test_chain(self) -> None: def test_chain(self) -> None:
control = [b'facebook', b'thrift', b'python3', b'cython'] control = [b"facebook", b"thrift", b"python3", b"cython"]
chain = make_chain([IOBuf(x) for x in control]) chain = make_chain([IOBuf(x) for x in control])
self.assertTrue(chain.is_chained) self.assertTrue(chain.is_chained)
self.assertTrue(chain) self.assertTrue(chain)
...@@ -27,10 +27,10 @@ class IOBufTests(unittest.TestCase): ...@@ -27,10 +27,10 @@ class IOBufTests(unittest.TestCase):
self.assertEqual(chain.chain_size(), sum(len(x) for x in control)) self.assertEqual(chain.chain_size(), sum(len(x) for x in control))
self.assertEqual(chain.chain_count(), len(control)) self.assertEqual(chain.chain_count(), len(control))
self.assertEqual(memoryview(chain.next), control[1]) # type: ignore self.assertEqual(memoryview(chain.next), control[1]) # type: ignore
self.assertEqual(b''.join(chain), b''.join(control)) self.assertEqual(b"".join(chain), b"".join(control))
def test_cyclic_chain(self) -> None: def test_cyclic_chain(self) -> None:
control = [b'aaa', b'aaaa'] control = [b"aaa", b"aaaa"]
chain = make_chain([IOBuf(x) for x in control]) chain = make_chain([IOBuf(x) for x in control])
self.assertTrue(chain.is_chained) self.assertTrue(chain.is_chained)
self.assertTrue(chain) self.assertTrue(chain)
...@@ -39,7 +39,7 @@ class IOBufTests(unittest.TestCase): ...@@ -39,7 +39,7 @@ class IOBufTests(unittest.TestCase):
self.assertEqual(chain.chain_size(), sum(len(x) for x in control)) self.assertEqual(chain.chain_size(), sum(len(x) for x in control))
self.assertEqual(chain.chain_count(), len(control)) self.assertEqual(chain.chain_count(), len(control))
self.assertEqual(memoryview(chain.next), control[1]) # type: ignore self.assertEqual(memoryview(chain.next), control[1]) # type: ignore
self.assertEqual(b''.join(chain), b''.join(control)) self.assertEqual(b"".join(chain), b"".join(control))
def test_hash(self) -> None: def test_hash(self) -> None:
x = b"omg" x = b"omg"
...@@ -61,7 +61,7 @@ class IOBufTests(unittest.TestCase): ...@@ -61,7 +61,7 @@ class IOBufTests(unittest.TestCase):
def test_iter(self) -> None: def test_iter(self) -> None:
x = b"testtest" x = b"testtest"
xb = IOBuf(x) xb = IOBuf(x)
self.assertEqual(b''.join(iter(xb)), x) self.assertEqual(b"".join(iter(xb)), x)
def test_bytes(self) -> None: def test_bytes(self) -> None:
x = b"omgwtfbbq" x = b"omgwtfbbq"
......
...@@ -11,14 +11,17 @@ from Cython.Compiler import Options ...@@ -11,14 +11,17 @@ from Cython.Compiler import Options
Options.fast_fail = True Options.fast_fail = True
ext = Extension("folly.executor", ext = Extension(
sources=['folly/executor.pyx'], "folly.executor",
libraries=['folly_pic', 'glog', 'double-conversion', 'iberty']) sources=["folly/executor.pyx"],
libraries=["folly_pic", "glog", "double-conversion", "iberty"],
)
setup(name="folly", setup(
version='0.0.1', name="folly",
packages=['folly'], version="0.0.1",
package_data={"": ['*.pxd', '*.h']}, packages=["folly"],
package_data={"": ["*.pxd", "*.h"]},
zip_safe=False, zip_safe=False,
ext_modules=cythonize([ext], ext_modules=cythonize([ext], compiler_directives={"language_level": 3}),
compiler_directives={'language_level': 3, })) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment