Standardize Spyglass code with YAPF

From recently merged document updates in [0] there is a desire to
standardize the Airship project python codebase.  This is the effort
to do so for the Spyglass project.

[0] https://review.opendev.org/#/c/671291/

Co-Authored-By: Ian Pittwood <pittwoodian@gmail.com>
Change-Id: I2b0f2491d83675d7742b168ecb9e1dfb9a11e719
This commit is contained in:
Alexander Hughes 2019-07-24 08:23:42 -05:00 committed by Ian Pittwood
parent 534fe50b9e
commit 9689dae61f
7 changed files with 38 additions and 21 deletions

10
.style.yapf Normal file
View File

@ -0,0 +1,10 @@
[style]
based_on_style = pep8
spaces_before_comment = 2
column_limit = 79
blank_line_before_nested_class_or_def = false
blank_line_before_module_docstring = true
split_before_logical_operator = true
split_before_first_argument = true
allow_split_before_dict_value = false
split_before_arithmetic_operator = true

View File

@ -63,7 +63,8 @@ lint: py_lint
# Perform auto formatting
.PHONY: format
format: py_format
format:
tox -e fmt
_BASE_IMAGE_ARG := $(if $(BASE_IMAGE),--build-arg FROM="${BASE_IMAGE}" ,)
@ -107,7 +108,3 @@ clean:
.PHONY: py_lint
py_lint:
tox -e pep8
.PHONY: py_format
py_format:
tox -e fmt

View File

@ -9,3 +9,5 @@ netaddr==0.7.19
pyrsistent==0.15.2
pyyaml==5.1.1
six==1.12.0
yapf==0.27.0
flake8-import-order==0.18.1

View File

@ -28,7 +28,6 @@ LOG = logging.getLogger(__name__)
class ProcessDataSource(object):
def __init__(self, site_type):
# Initialize intermediary and save site type
self._initialize_intermediary()

View File

@ -14,7 +14,6 @@
class BaseProcessor(object):
def __init__(self):
pass

View File

@ -26,7 +26,6 @@ LOG = logging.getLogger(__name__)
class SiteProcessor(BaseProcessor):
def __init__(self, site_data, manifest_dir, force_write):
super().__init__()
if isinstance(site_data, SiteDocumentData):

37
tox.ini
View File

@ -23,7 +23,7 @@ commands =
[testenv:fmt]
basepython = python3
deps =
pipenv
pipenv
commands =
pipenv install --dev
yapf -ir {toxinidir}/spyglass {toxinidir}/tests
@ -36,7 +36,7 @@ deps =
commands =
pipenv install --dev
bash -c {toxinidir}/tools/gate/whitespace-linter.sh
yapf -dr {toxinidir}/spyglass {toxinidir}/setup.py {toxinidir}/tests
yapf -dr {toxinidir}/spyglass {toxinidir}/tests
flake8 {toxinidir}/spyglass {toxinidir}/tests
bandit -r spyglass -n 5
whitelist_externals =
@ -55,40 +55,51 @@ commands =
[testenv:bandit]
basepython = python3
deps =
pipenv
pipenv
commands =
pipenv install --dev
bandit -r spyglass -n 5
[testenv:update-requirements]
deps =
pipenv
pipenv
commands =
pipenv lock --clear
bash -c "pipenv lock -r > {toxinidir}/requirements.txt"
whitelist_externals =
bash
[flake8]
ignore = W503
[testenv:docs]
basepython = python3
deps =
-r{toxinidir}/doc/requirements.txt
-r{toxinidir}/doc/requirements.txt
commands =
rm -rf doc/build
sphinx-build -b html doc/source doc/build/html -n -W -v
rm -rf doc/build
sphinx-build -b html doc/source doc/build/html -n -W -v
whitelist_externals = rm
[testenv:cover]
basepython = python3
deps =
pipenv
pipenv
commands =
pipenv install --dev
bash -c 'PATH=$PATH:~/.local/bin; pytest --cov=spyglass \
--cov-report html:cover --cov-report xml:cover/coverage.xml \
--cov-report term --cov-fail-under 88 tests/'
--cov-report html:cover --cov-report xml:cover/coverage.xml \
--cov-report term --cov-fail-under 88 tests/'
whitelist_externals =
bash
[flake8]
filename = *.py
show-source = true
# [H106] Don't put vim configuration in source files.
# [H201] No 'except:' at least use 'except Exception:'
# [H904] Delay string interpolations at logging calls.
enable-extensions = H106,H201,H904
# [W503] line break before binary operator
ignore = W503
exclude=.venv,.git,.tox,build,dist,*lib/python*,*egg,tools,*.ini,*.po,*.pot
max-complexity = 24
application-import-names = spyglass
import-order-style = pep8