From 9689dae61f832bcd6efc30559f5c08a16d5f23d9 Mon Sep 17 00:00:00 2001 From: Alexander Hughes Date: Wed, 24 Jul 2019 08:23:42 -0500 Subject: [PATCH] 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 Change-Id: I2b0f2491d83675d7742b168ecb9e1dfb9a11e719 --- .style.yapf | 10 ++++++ Makefile | 7 ++-- requirements.txt | 2 ++ spyglass/parser/engine.py | 1 - spyglass/site_processors/base.py | 1 - spyglass/site_processors/site_processor.py | 1 - tox.ini | 37 ++++++++++++++-------- 7 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 .style.yapf diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 0000000..53ffd06 --- /dev/null +++ b/.style.yapf @@ -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 diff --git a/Makefile b/Makefile index 1ce50d4..06f964e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/requirements.txt b/requirements.txt index d7eaa1d..02d44d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/spyglass/parser/engine.py b/spyglass/parser/engine.py index 2c5c831..c48a0f9 100755 --- a/spyglass/parser/engine.py +++ b/spyglass/parser/engine.py @@ -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() diff --git a/spyglass/site_processors/base.py b/spyglass/site_processors/base.py index 994cb45..f8f33af 100644 --- a/spyglass/site_processors/base.py +++ b/spyglass/site_processors/base.py @@ -14,7 +14,6 @@ class BaseProcessor(object): - def __init__(self): pass diff --git a/spyglass/site_processors/site_processor.py b/spyglass/site_processors/site_processor.py index f3d21a6..566ccc6 100644 --- a/spyglass/site_processors/site_processor.py +++ b/spyglass/site_processors/site_processor.py @@ -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): diff --git a/tox.ini b/tox.ini index a57a194..9f3ae23 100644 --- a/tox.ini +++ b/tox.ini @@ -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