Skip to content

Commit

Permalink
Merge a7ca6b0 into 111d424
Browse files Browse the repository at this point in the history
  • Loading branch information
agrieve committed Dec 30, 2019
2 parents 111d424 + a7ca6b0 commit 478e89b
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 83 deletions.
3 changes: 1 addition & 2 deletions .style.yapf
@@ -1,3 +1,2 @@
[style]
# YAPF uses the chromium style
based_on_style = chromium
based_on_style = yapf
5 changes: 2 additions & 3 deletions CONTRIBUTING.rst
Expand Up @@ -27,9 +27,8 @@ use Github pull requests for this purpose.
YAPF coding style
-----------------

YAPF follows the `Chromium Python Style Guide
<https://www.chromium.org/chromium-os/python-style-guidelines>`_. It's the same
as the Google Python Style guide with two exceptions:
YAPF follows the `Google Python Style Guide
<https://google.github.io/styleguide/pyguide.html>`_ with two exceptions:

- 2 spaces for indentation rather than 4.
- CamelCase for function and method names rather than snake_case.
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -188,9 +188,9 @@ example:

.. code-block:: shell
--style='{based_on_style: chromium, indent_width: 4}'
--style='{based_on_style: chromium, indent_width: 2}'
This will take the ``chromium`` base style and modify it to have four space
This will take the ``chromium`` base style and modify it to have two space
indentations.

YAPF will search for the formatting style in the following manner:
Expand Down
11 changes: 10 additions & 1 deletion yapf/yapflib/style.py
Expand Up @@ -432,7 +432,7 @@ def CreateGoogleStyle():
return style


def CreateChromiumStyle():
def CreateYapfStyle():
style = CreateGoogleStyle()
style['ALLOW_MULTILINE_DICTIONARY_KEYS'] = True
style['ALLOW_SPLIT_BEFORE_DEFAULT_OR_NAMED_ASSIGNS'] = False
Expand All @@ -444,6 +444,13 @@ def CreateChromiumStyle():
return style


def CreateChromiumStyle():
style = CreatePEP8Style()
style['BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF'] = True
style['COLUMN_LIMIT'] = 80
return style


def CreateFacebookStyle():
style = CreatePEP8Style()
style['ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT'] = False
Expand All @@ -466,13 +473,15 @@ def CreateFacebookStyle():
chromium=CreateChromiumStyle,
google=CreateGoogleStyle,
facebook=CreateFacebookStyle,
yapf=CreateYapfStyle,
)

_DEFAULT_STYLE_TO_FACTORY = [
(CreateChromiumStyle(), CreateChromiumStyle),
(CreateFacebookStyle(), CreateFacebookStyle),
(CreateGoogleStyle(), CreateGoogleStyle),
(CreatePEP8Style(), CreatePEP8Style),
(CreateYapfStyle(), CreateYapfStyle),
]


Expand Down
2 changes: 1 addition & 1 deletion yapftests/blank_line_calculator_test.py
Expand Up @@ -27,7 +27,7 @@ class BasicBlankLineCalculatorTest(yapf_test_helper.YAPFTest):

@classmethod
def setUpClass(cls):
style.SetGlobalStyle(style.CreateChromiumStyle())
style.SetGlobalStyle(style.CreateYapfStyle())

def testDecorators(self):
unformatted_code = textwrap.dedent("""\
Expand Down
2 changes: 1 addition & 1 deletion yapftests/format_decision_state_test.py
Expand Up @@ -28,7 +28,7 @@ class FormatDecisionStateTest(yapf_test_helper.YAPFTest):

@classmethod
def setUpClass(cls):
style.SetGlobalStyle(style.CreateChromiumStyle())
style.SetGlobalStyle(style.CreateYapfStyle())

def testSimpleFunctionDefWithNoSplitting(self):
code = textwrap.dedent(r"""
Expand Down
2 changes: 1 addition & 1 deletion yapftests/main_test.py
Expand Up @@ -116,7 +116,7 @@ def testEchoInputWithStyle(self):
chromium_code = 'def f(a=1):\n return 2 * a\n'
with patched_input(code):
with captured_output() as (out, _):
ret = yapf.main(['-', '--style=chromium'])
ret = yapf.main(['-', '--style=yapf'])
self.assertEqual(ret, 0)
self.assertEqual(out.getvalue(), chromium_code)

Expand Down

0 comments on commit 478e89b

Please sign in to comment.