Skip to content

Commit

Permalink
Merge c66b990 into 111d424
Browse files Browse the repository at this point in the history
  • Loading branch information
agrieve committed Jan 2, 2020
2 parents 111d424 + c66b990 commit 536eb22
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 120 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
4 changes: 4 additions & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,10 @@
# All notable changes to this project will be documented in this file.
# This project adheres to [Semantic Versioning](http://semver.org/).

## [vNext]-
### Changed
- Renamed "chromium" style to "yapf". Chromium will now use PEP-8 directly.

## [0.29.0] 2019-11-28
### Added
- Add the `--quiet` flag to suppress output. The return code is 1 if there are
Expand Down
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
8 changes: 4 additions & 4 deletions README.rst
Expand Up @@ -178,8 +178,8 @@ with a ``[yapf]`` heading. For example:
The ``based_on_style`` setting determines which of the predefined styles this
custom style is based on (think of it like subclassing). Four
styles are predefined: ``pep8`` (default), ``chromium``, ``google`` and
``facebook`` (see ``_STYLE_NAME_TO_FACTORY`` in style.py_).
styles are predefined: ``pep8`` (default), ``google`` and ``facebook`` (see
``_STYLE_NAME_TO_FACTORY`` in style.py_).

.. _style.py: https://github.com/google/yapf/blob/master/yapf/yapflib/style.py#L445

Expand All @@ -188,9 +188,9 @@ example:

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

YAPF will search for the formatting style in the following manner:
Expand Down
7 changes: 3 additions & 4 deletions yapf/yapflib/style.py
Expand Up @@ -432,11 +432,10 @@ 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
style['INDENT_DICTIONARY_VALUE'] = True
style['INDENT_WIDTH'] = 2
style['SPLIT_BEFORE_BITWISE_OPERATOR'] = True
style['SPLIT_BEFORE_DOT'] = True
Expand All @@ -463,16 +462,16 @@ def CreateFacebookStyle():

_STYLE_NAME_TO_FACTORY = dict(
pep8=CreatePEP8Style,
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
6 changes: 3 additions & 3 deletions yapftests/main_test.py
Expand Up @@ -113,12 +113,12 @@ def testEchoInput(self):

def testEchoInputWithStyle(self):
code = 'def f(a = 1):\n return 2*a\n'
chromium_code = 'def f(a=1):\n return 2 * a\n'
yapf_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)
self.assertEqual(out.getvalue(), yapf_code)

def testEchoBadInput(self):
bad_syntax = ' a = 1\n'
Expand Down

0 comments on commit 536eb22

Please sign in to comment.