Commit c0cea3b0 authored by Ricky Stewart's avatar Ricky Stewart
Browse files

Bug 1654103: Standardize on Black for Python code in `mozilla-central`....

Bug 1654103: Standardize on Black for Python code in `mozilla-central`. r=remote-protocol-reviewers,marionette-reviewers,webdriver-reviewers,perftest-reviewers,devtools-backward-compat-reviewers,jgilbert,preferences-reviewers,sylvestre,maja_zf,webcompat-reviewers,denschub,ntim,whimboo,sparky

Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly.

To produce this patch I did all of the following:

1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions.

2. Run ./mach lint --linter black --fix

3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks.

4. Make some ad-hoc manual updates to `testing/marionette/client/setup.py`, `testing/marionette/harness/setup.py`, and `testing/firefox-ui/harness/setup.py`, which have hard-coded regexes that break after the reformat.

5. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023).

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D94045
parent 8f82fc13
...@@ -12,56 +12,55 @@ import sys ...@@ -12,56 +12,55 @@ import sys
old_bytecode = sys.dont_write_bytecode old_bytecode = sys.dont_write_bytecode
sys.dont_write_bytecode = True sys.dont_write_bytecode = True
path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'mach')) path = os.path.abspath(os.path.join(os.path.dirname(__file__), "mach"))
# If mach is not here, we're on the objdir go to the srcdir. # If mach is not here, we're on the objdir go to the srcdir.
if not os.path.exists(path): if not os.path.exists(path):
with open(os.path.join(os.path.dirname(__file__), 'mozinfo.json')) as info: with open(os.path.join(os.path.dirname(__file__), "mozinfo.json")) as info:
config = json.loads(info.read()) config = json.loads(info.read())
path = os.path.join(config['topsrcdir'], 'mach') path = os.path.join(config["topsrcdir"], "mach")
sys.dont_write_bytecode = old_bytecode sys.dont_write_bytecode = old_bytecode
def _is_likely_cpp_header(filename): def _is_likely_cpp_header(filename):
if not filename.endswith('.h'): if not filename.endswith(".h"):
return False return False
if filename.endswith('Inlines.h') or filename.endswith('-inl.h'): if filename.endswith("Inlines.h") or filename.endswith("-inl.h"):
return True return True
cpp_file = filename[:-1] + 'cpp' cpp_file = filename[:-1] + "cpp"
return os.path.exists(cpp_file) return os.path.exists(cpp_file)
def Settings(**kwargs): def Settings(**kwargs):
if kwargs[ 'language' ] == 'cfamily': if kwargs["language"] == "cfamily":
return FlagsForFile(kwargs['filename']) return FlagsForFile(kwargs["filename"])
# This is useful for generic language server protocols, like rust-analyzer, # This is useful for generic language server protocols, like rust-analyzer,
# to discover the right project root instead of guessing based on where the # to discover the right project root instead of guessing based on where the
# closest Cargo.toml is. # closest Cargo.toml is.
return { return {
'project_directory': '.', "project_directory": ".",
} }
def FlagsForFile(filename): def FlagsForFile(filename):
output = subprocess.check_output([path, 'compileflags', filename]) output = subprocess.check_output([path, "compileflags", filename])
output = output.decode('utf-8') output = output.decode("utf-8")
flag_list = shlex.split(output) flag_list = shlex.split(output)
# This flag is added by Fennec for android build and causes ycmd to fail to parse the file. # This flag is added by Fennec for android build and causes ycmd to fail to parse the file.
# Removing this flag is a workaround until ycmd starts to handle this flag properly. # Removing this flag is a workaround until ycmd starts to handle this flag properly.
# https://github.com/Valloric/YouCompleteMe/issues/1490 # https://github.com/Valloric/YouCompleteMe/issues/1490
final_flags = [x for x in flag_list if not x.startswith('-march=armv')] final_flags = [x for x in flag_list if not x.startswith("-march=armv")]
if _is_likely_cpp_header(filename): if _is_likely_cpp_header(filename):
final_flags += ["-x", "c++"] final_flags += ["-x", "c++"]
return { return {"flags": final_flags, "do_cache": True}
'flags': final_flags,
'do_cache': True
}
if __name__ == '__main__': if __name__ == "__main__":
print(FlagsForFile(sys.argv[1])) print(FlagsForFile(sys.argv[1]))
...@@ -4,38 +4,39 @@ ...@@ -4,38 +4,39 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS.mozilla.a11y += ['AccessibleWrap.h', EXPORTS.mozilla.a11y += [
'HyperTextAccessibleWrap.h', "AccessibleWrap.h",
'SessionAccessibility.h', "HyperTextAccessibleWrap.h",
'TraversalRule.h', "SessionAccessibility.h",
"TraversalRule.h",
] ]
SOURCES += [ SOURCES += [
'AccessibleWrap.cpp', "AccessibleWrap.cpp",
'DocAccessibleWrap.cpp', "DocAccessibleWrap.cpp",
'Platform.cpp', "Platform.cpp",
'ProxyAccessibleWrap.cpp', "ProxyAccessibleWrap.cpp",
'RootAccessibleWrap.cpp', "RootAccessibleWrap.cpp",
'SessionAccessibility.cpp', "SessionAccessibility.cpp",
'TraversalRule.cpp', "TraversalRule.cpp",
] ]
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/base', "/accessible/base",
'/accessible/generic', "/accessible/generic",
'/accessible/html', "/accessible/html",
'/accessible/ipc', "/accessible/ipc",
'/accessible/ipc/other', "/accessible/ipc/other",
'/accessible/xpcom', "/accessible/xpcom",
'/accessible/xul', "/accessible/xul",
'/dom/base', "/dom/base",
'/widget', "/widget",
'/widget/android', "/widget/android",
] ]
FINAL_LIBRARY = 'xul' FINAL_LIBRARY = "xul"
include('/ipc/chromium/chromium-config.mozbuild') include("/ipc/chromium/chromium-config.mozbuild")
if CONFIG['CC_TYPE'] in ('clang', 'gcc'): if CONFIG["CC_TYPE"] in ("clang", "gcc"):
CXXFLAGS += ['-Wno-error=shadow'] CXXFLAGS += ["-Wno-error=shadow"]
...@@ -5,40 +5,40 @@ ...@@ -5,40 +5,40 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS.mozilla.dom += [ EXPORTS.mozilla.dom += [
'AccessibleNode.h', "AccessibleNode.h",
] ]
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [
'AccessibleNode.cpp', "AccessibleNode.cpp",
] ]
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/base', "/accessible/base",
'/accessible/generic', "/accessible/generic",
] ]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk': if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/atk', "/accessible/atk",
] ]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/windows/ia2', "/accessible/windows/ia2",
'/accessible/windows/msaa', "/accessible/windows/msaa",
] ]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/mac', "/accessible/mac",
] ]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android': elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/android', "/accessible/android",
] ]
else: else:
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/other', "/accessible/other",
] ]
include('/ipc/chromium/chromium-config.mozbuild') include("/ipc/chromium/chromium-config.mozbuild")
FINAL_LIBRARY = 'xul' FINAL_LIBRARY = "xul"
...@@ -5,61 +5,61 @@ ...@@ -5,61 +5,61 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS.mozilla.a11y += [ EXPORTS.mozilla.a11y += [
'AccessibleWrap.h', "AccessibleWrap.h",
'HyperTextAccessibleWrap.h', "HyperTextAccessibleWrap.h",
] ]
SOURCES += [ SOURCES += [
'AccessibleWrap.cpp', "AccessibleWrap.cpp",
'ApplicationAccessibleWrap.cpp', "ApplicationAccessibleWrap.cpp",
'AtkSocketAccessible.cpp', "AtkSocketAccessible.cpp",
'DocAccessibleWrap.cpp', "DocAccessibleWrap.cpp",
'DOMtoATK.cpp', "DOMtoATK.cpp",
'nsMaiHyperlink.cpp', "nsMaiHyperlink.cpp",
'nsMaiInterfaceAction.cpp', "nsMaiInterfaceAction.cpp",
'nsMaiInterfaceComponent.cpp', "nsMaiInterfaceComponent.cpp",
'nsMaiInterfaceDocument.cpp', "nsMaiInterfaceDocument.cpp",
'nsMaiInterfaceEditableText.cpp', "nsMaiInterfaceEditableText.cpp",
'nsMaiInterfaceHyperlinkImpl.cpp', "nsMaiInterfaceHyperlinkImpl.cpp",
'nsMaiInterfaceHypertext.cpp', "nsMaiInterfaceHypertext.cpp",
'nsMaiInterfaceImage.cpp', "nsMaiInterfaceImage.cpp",
'nsMaiInterfaceSelection.cpp', "nsMaiInterfaceSelection.cpp",
'nsMaiInterfaceTable.cpp', "nsMaiInterfaceTable.cpp",
'nsMaiInterfaceTableCell.cpp', "nsMaiInterfaceTableCell.cpp",
'nsMaiInterfaceText.cpp', "nsMaiInterfaceText.cpp",
'nsMaiInterfaceValue.cpp', "nsMaiInterfaceValue.cpp",
'Platform.cpp', "Platform.cpp",
'RootAccessibleWrap.cpp', "RootAccessibleWrap.cpp",
'UtilInterface.cpp', "UtilInterface.cpp",
] ]
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/base', "/accessible/base",
'/accessible/generic', "/accessible/generic",
'/accessible/html', "/accessible/html",
'/accessible/ipc', "/accessible/ipc",
'/accessible/ipc/other', "/accessible/ipc/other",
'/accessible/xpcom', "/accessible/xpcom",
'/accessible/xul', "/accessible/xul",
'/other-licenses/atk-1.0', "/other-licenses/atk-1.0",
] ]
FINAL_LIBRARY = 'xul' FINAL_LIBRARY = "xul"
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk': if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
CFLAGS += CONFIG['TK_CFLAGS'] CFLAGS += CONFIG["TK_CFLAGS"]
CXXFLAGS += CONFIG['TK_CFLAGS'] CXXFLAGS += CONFIG["TK_CFLAGS"]
if CONFIG['MOZ_ENABLE_DBUS']: if CONFIG["MOZ_ENABLE_DBUS"]:
CXXFLAGS += CONFIG['MOZ_DBUS_CFLAGS'] CXXFLAGS += CONFIG["MOZ_DBUS_CFLAGS"]
include('/ipc/chromium/chromium-config.mozbuild') include("/ipc/chromium/chromium-config.mozbuild")
if CONFIG['CC_TYPE'] in ('clang', 'gcc'): if CONFIG["CC_TYPE"] in ("clang", "gcc"):
# Used in G_DEFINE_TYPE_EXTENDED macro, probably fixed in newer glib / # Used in G_DEFINE_TYPE_EXTENDED macro, probably fixed in newer glib /
# gobject headers. See bug 1243331 comment 3. # gobject headers. See bug 1243331 comment 3.
CXXFLAGS += [ CXXFLAGS += [
'-Wno-error=unused-function', "-Wno-error=unused-function",
'-Wno-error=shadow', "-Wno-error=shadow",
'-Wno-unused-local-typedefs', "-Wno-unused-local-typedefs",
] ]
...@@ -4,117 +4,114 @@ ...@@ -4,117 +4,114 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS += [ EXPORTS += ["AccEvent.h", "nsAccessibilityService.h"]
'AccEvent.h',
'nsAccessibilityService.h'
]
EXPORTS.mozilla.a11y += [ EXPORTS.mozilla.a11y += [
'AccTypes.h', "AccTypes.h",
'DocManager.h', "DocManager.h",
'FocusManager.h', "FocusManager.h",
'IDSet.h', "IDSet.h",
'Platform.h', "Platform.h",
'RelationType.h', "RelationType.h",
'Role.h', "Role.h",
'SelectionManager.h', "SelectionManager.h",
'States.h', "States.h",
] ]
if CONFIG['MOZ_DEBUG']: if CONFIG["MOZ_DEBUG"]:
EXPORTS.mozilla.a11y += [ EXPORTS.mozilla.a11y += [
'Logging.h', "Logging.h",
] ]
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [
'AccessibleOrProxy.cpp', "AccessibleOrProxy.cpp",
'AccEvent.cpp', "AccEvent.cpp",
'AccGroupInfo.cpp', "AccGroupInfo.cpp",
'AccIterator.cpp', "AccIterator.cpp",
'ARIAMap.cpp', "ARIAMap.cpp",
'ARIAStateMap.cpp', "ARIAStateMap.cpp",
'Asserts.cpp', "Asserts.cpp",
'DocManager.cpp', "DocManager.cpp",
'EmbeddedObjCollector.cpp', "EmbeddedObjCollector.cpp",
'EventQueue.cpp', "EventQueue.cpp",
'EventTree.cpp', "EventTree.cpp",
'Filters.cpp', "Filters.cpp",
'FocusManager.cpp', "FocusManager.cpp",
'NotificationController.cpp', "NotificationController.cpp",
'nsAccessibilityService.cpp', "nsAccessibilityService.cpp",
'nsAccessiblePivot.cpp', "nsAccessiblePivot.cpp",
'nsAccUtils.cpp', "nsAccUtils.cpp",
'nsCoreUtils.cpp', "nsCoreUtils.cpp",
'nsEventShell.cpp', "nsEventShell.cpp",
'nsTextEquivUtils.cpp', "nsTextEquivUtils.cpp",
'Pivot.cpp', "Pivot.cpp",
'SelectionManager.cpp', "SelectionManager.cpp",
'StyleInfo.cpp', "StyleInfo.cpp",
'TextAttrs.cpp', "TextAttrs.cpp",
'TextRange.cpp', "TextRange.cpp",
'TextUpdater.cpp', "TextUpdater.cpp",
'TreeWalker.cpp', "TreeWalker.cpp",
] ]
if CONFIG['A11Y_LOG']: if CONFIG["A11Y_LOG"]:
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [
'Logging.cpp', "Logging.cpp",
] ]
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/generic', "/accessible/generic",
'/accessible/html', "/accessible/html",
'/accessible/ipc', "/accessible/ipc",
'/dom/base', "/dom/base",
'/dom/xul', "/dom/xul",
] ]
if CONFIG['OS_ARCH'] == 'WINNT': if CONFIG["OS_ARCH"] == "WINNT":
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/ipc/win', "/accessible/ipc/win",
] ]
else: else:
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/ipc/other', "/accessible/ipc/other",
] ]
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/xpcom', "/accessible/xpcom",
'/accessible/xul', "/accessible/xul",
'/dom/base', "/dom/base",
'/ipc/chromium/src', "/ipc/chromium/src",
'/layout/generic', "/layout/generic",
'/layout/style', "/layout/style",
'/layout/xul', "/layout/xul",
'/layout/xul/tree/', "/layout/xul/tree/",
] ]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk': if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/atk', "/accessible/atk",
] ]
CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS'] CXXFLAGS += CONFIG["MOZ_CAIRO_CFLAGS"]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/windows/ia2', "/accessible/windows/ia2",
'/accessible/windows/msaa', "/accessible/windows/msaa",
] ]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/mac', "/accessible/mac",
] ]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android': elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/android', "/accessible/android",
] ]
else: else:
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/accessible/other', "/accessible/other",
] ]
FINAL_LIBRARY = 'xul' FINAL_LIBRARY = "xul"
include('/ipc/chromium/chromium-config.mozbuild') include("/ipc/chromium/chromium-config.mozbuild")
if CONFIG['CC_TYPE'] in ('clang', 'gcc'): if CONFIG["CC_TYPE"] in ("clang", "gcc"):
CXXFLAGS += ['-Wno-error=shadow'] CXXFLAGS += ["-Wno-error=shadow"]
...@@ -5,73 +5,73 @@ ...@@ -5,73 +5,73 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS.mozilla.a11y += [ EXPORTS.mozilla.a11y += [
'Accessible.h', "Accessible.h",
'DocAccessible.h', "DocAccessible.h",
'HyperTextAccessible.h', "HyperTextAccessible.h",
'OuterDocAccessible.h', "OuterDocAccessible.h",
] ]
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [
'Accessible.cpp', "Accessible.cpp",
'ApplicationAccessible.cpp', "ApplicationAccessible.cpp",
'ARIAGridAccessible.cpp', "ARIAGridAccessible.cpp",
'BaseAccessibles.cpp', "BaseAccessibles.cpp",
'DocAccessible.cpp', "DocAccessible.cpp",
'FormControlAccessible.cpp', "FormControlAccessible.cpp",
'HyperTextAccessible.cpp', "HyperTextAccessible.cpp",
'ImageAccessible.cpp', "ImageAccessible.cpp",
'OuterDocAccessible.cpp', "OuterDocAccessible.cpp",
'RootAccessible.cpp', "RootAccessible.cpp",
'TableAccessible.cpp',