Skip to content

[lldb] Format more Python files with black #65979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lldb/bindings/python/createPythonInit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pkgFiles = sys.argv[2:]

getFileName = lambda f: os.path.splitext(os.path.basename(f))[0]
importNames = ', '.join('"{}"'.format(getFileName(f)) for f in pkgFiles)
importNames = ", ".join('"{}"'.format(getFileName(f)) for f in pkgFiles)

script = """__all__ = [{import_names}]
for x in __all__:
Expand All @@ -18,7 +18,9 @@ def __lldb_init_module(debugger, internal_dict):
lldb_init = getattr(submodule, '__lldb_init_module', None)
if lldb_init:
lldb_init(debugger, internal_dict)
""".format(import_names=importNames, pkg_name=pkgRelDir.replace("/", "."))
""".format(
import_names=importNames, pkg_name=pkgRelDir.replace("/", ".")
)

pkgIniFile = os.path.normpath(os.path.join(pkgRelDir, "__init__.py"))
with open(pkgIniFile, "w") as f:
Expand Down
21 changes: 13 additions & 8 deletions lldb/bindings/python/get-python-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ def relpath_nodots(path, base):
rel = os.path.normpath(os.path.relpath(path, base))
assert not os.path.isabs(rel)
parts = rel.split(os.path.sep)
if parts and parts[0] == '..':
if parts and parts[0] == "..":
raise ValueError(f"{path} is not under {base}")
return rel


def main():
parser = argparse.ArgumentParser(description="extract cmake variables from python")
parser.add_argument("variable_name")
Expand All @@ -35,10 +36,10 @@ def main():
except ValueError:
# Try to fall back to something reasonable if sysconfig's platlib
# is outside of sys.prefix
if os.name == 'posix':
print('lib/python%d.%d/site-packages' % sys.version_info[:2])
elif os.name == 'nt':
print('Lib\\site-packages')
if os.name == "posix":
print("lib/python%d.%d/site-packages" % sys.version_info[:2])
elif os.name == "nt":
print("Lib\\site-packages")
else:
raise
elif args.variable_name == "LLDB_PYTHON_EXE_RELATIVE_PATH":
Expand All @@ -57,16 +58,20 @@ def main():
exe = os.path.realpath(exe)
continue
else:
print("Could not find a relative path to sys.executable under sys.prefix", file=sys.stderr)
print(
"Could not find a relative path to sys.executable under sys.prefix",
file=sys.stderr,
)
for e in tried:
print("tried:", e, file=sys.stderr)
print("realpath(sys.prefix):", prefix, file=sys.stderr)
print("sys.prefix:", sys.prefix, file=sys.stderr)
sys.exit(1)
elif args.variable_name == "LLDB_PYTHON_EXT_SUFFIX":
print(sysconfig.get_config_var('EXT_SUFFIX'))
print(sysconfig.get_config_var("EXT_SUFFIX"))
else:
parser.error(f"unknown variable {args.variable_name}")

if __name__ == '__main__':

if __name__ == "__main__":
main()
8 changes: 2 additions & 6 deletions lldb/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ["sphinx.ext.todo", "sphinx.ext.mathjax", "sphinx.ext.intersphinx"]

autodoc_default_options = {
"special-members": True
}
autodoc_default_options = {"special-members": True}

# Unless we only generate the basic manpage we need the plugin for generating
# the Python API documentation.
Expand All @@ -60,9 +58,7 @@
try:
import furo
except ModuleNotFoundError:
print(
f"install sphinx furo theme with {sys.executable} -m pip install furo"
)
print(f"install sphinx furo theme with {sys.executable} -m pip install furo")
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = "furo"
Expand Down
5 changes: 3 additions & 2 deletions lldb/packages/Python/lldbsuite/test/lldbtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2604,15 +2604,16 @@ def assertSuccess(self, obj, msg=None):
if not obj.Success():
error = obj.GetCString()
self.fail(self._formatMessage(msg, "'{}' is not success".format(error)))

"""Assert that an lldb.SBError is in the "failure" state."""

def assertFailure(self, obj, error_str = None, msg=None):
def assertFailure(self, obj, error_str=None, msg=None):
if obj.Success():
self.fail(self._formatMessage(msg, "Error not in a fail state"))

if error_str == None:
return

error = obj.GetCString()
self.assertEqual(error, error_str, msg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,14 @@ def request_disconnect(self, terminateDebuggee=None):
}
return self.send_recv(command_dict)

def request_disassemble(self, memoryReference, offset=-50, instructionCount=200, resolveSymbols=True):
def request_disassemble(
self, memoryReference, offset=-50, instructionCount=200, resolveSymbols=True
):
args_dict = {
"memoryReference": memoryReference,
"offset": offset,
"instructionCount": instructionCount,
"resolveSymbols": resolveSymbols
"resolveSymbols": resolveSymbols,
}
command_dict = {
"command": "disassemble",
Expand Down
26 changes: 16 additions & 10 deletions lldb/source/Interpreter/embedded_interpreter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

if sys.version_info[0] < 3:
import __builtin__ as builtins
else:
Expand All @@ -18,10 +19,10 @@
have_readline = False
else:
have_readline = True
if 'libedit' in readline.__doc__:
readline.parse_and_bind('bind ^I rl_complete')
if "libedit" in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind('tab: complete')
readline.parse_and_bind("tab: complete")

# When running one line, we might place the string to run in this string
# in case it would be hard to correctly escape a string's contents
Expand All @@ -34,7 +35,8 @@ def get_terminal_size(fd):
import fcntl
import termios
import struct
hw = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))

hw = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234"))
except:
hw = (0, 0)
return hw
Expand All @@ -46,7 +48,7 @@ class LLDBExit(SystemExit):

def strip_and_check_exit(line):
line = line.rstrip()
if line in ('exit', 'quit'):
if line in ("exit", "quit"):
raise LLDBExit
return line

Expand Down Expand Up @@ -75,6 +77,7 @@ def run_python_interpreter(local_dict):
if get_terminal_size(fd)[1] == 0:
try:
import termios

old = termios.tcgetattr(fd)
if old[3] & termios.ECHO:
# Need to turn off echoing and restore
Expand All @@ -86,7 +89,8 @@ def run_python_interpreter(local_dict):
code.interact(
banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()'.",
readfunc=readfunc_stdio,
local=local_dict)
local=local_dict,
)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)
except:
Expand All @@ -96,18 +100,20 @@ def run_python_interpreter(local_dict):
code.interact(
banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.",
readfunc=readfunc_stdio,
local=local_dict)
local=local_dict,
)
else:
# We have a real interactive terminal
code.interact(
banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.",
readfunc=readfunc,
local=local_dict)
local=local_dict,
)
except LLDBExit:
pass
except SystemExit as e:
if e.code:
print('Script exited with code %s' % e.code)
print("Script exited with code %s" % e.code)


def run_one_line(local_dict, input_string):
Expand All @@ -127,4 +133,4 @@ def run_one_line(local_dict, input_string):
pass
except SystemExit as e:
if e.code:
print('Script exited with code %s' % e.code)
print("Script exited with code %s" % e.code)
Loading