
Python formatting using `git cl format` has been enabled in the codebase for a while now by including a .style.yapf file in your folder hierarchy. However back in 2020 an exception was added to ignore the json schema compiler folder, as the code in there uses a lot of chained function calls that are split across lines for readability and the formatter was condensing them into a much less readable state. This CL resolves this by using the line continuation character `\` for these chained function lines, allowing us to retain the more readable indentation and also enable the formatter by default. It also runs a full format over all the files in the directory, to get them into a consistent state where we can have the formatter enabled by default going forward with low impact. No behavior change is expected. Bug: 40711753 Change-Id: I6e10dc5af022ce0e3557099a84773aa9cc92d2e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5804254 Commit-Queue: Tim <tjudkins@chromium.org> Reviewed-by: Devlin Cronin <rdevlin.cronin@chromium.org> Cr-Commit-Position: refs/heads/main@{#1345613}
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
# Copyright 2012 The Chromium Authors
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
"""Utilies for the processing of schema python structures.
|
|
"""
|
|
|
|
|
|
def CapitalizeFirstLetter(value):
|
|
return value[0].capitalize() + value[1:]
|
|
|
|
|
|
def GetNamespace(ref):
|
|
return SplitNamespace(ref)[0]
|
|
|
|
|
|
def StripNamespace(ref):
|
|
return SplitNamespace(ref)[1]
|
|
|
|
|
|
def SplitNamespace(ref):
|
|
"""Returns (namespace, entity) from |ref|, e.g. app.window.AppWindow ->
|
|
(app.window, AppWindow). If |ref| isn't qualified then returns (None, ref).
|
|
"""
|
|
if '.' in ref:
|
|
return tuple(ref.rsplit('.', 1))
|
|
return (None, ref)
|
|
|
|
|
|
def JsFunctionNameToClassName(namespace_name, function_name):
|
|
"""Transform a fully qualified function name like foo.bar.baz into FooBarBaz
|
|
|
|
Also strips any leading 'Experimental' prefix."""
|
|
parts = []
|
|
full_name = namespace_name + "." + function_name
|
|
for part in full_name.split("."):
|
|
parts.append(CapitalizeFirstLetter(part))
|
|
if parts[0] == "Experimental":
|
|
del parts[0]
|
|
class_name = "".join(parts)
|
|
return class_name
|