Add hacking extension

This patch set adds hacking rule to pegleg and fixes outstanding non-
docstring related violations.

Change-Id: I5bb5e78c211f24cf95669124bfcf9603bea8bf15
Signed-off-by: Tin Lam <tin@irrational.io>
This commit is contained in:
Tin Lam 2018-11-26 02:24:09 -06:00
parent 213ca596e3
commit 1a325a400b
13 changed files with 45 additions and 33 deletions

View File

@ -216,7 +216,7 @@ def _verify_file_contents(*, sitename=None):
def _verify_single_file(filename, schemas):
errors = []
LOG.debug("Validating file %s." % filename)
LOG.debug("Validating file %s.", filename)
with open(filename) as f:
if not f.read(4) == '---\n':
errors.append((FILE_MISSING_YAML_DOCUMENT_HEADER,

View File

@ -196,7 +196,7 @@ def _get_and_validate_site_repositories(site_name, site_data):
LOG.info("The repository for site_name: %s does not contain a "
"site-definition.yaml with a 'repositories' key. Ensure "
"your repository is self-contained and doesn't require "
"extra repositories for correct rendering." % site_name)
"extra repositories for correct rendering.", site_name)
return site_data.get('repositories', {})

View File

@ -15,9 +15,9 @@
import logging
import os
from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
from pegleg.engine.util import files
from pegleg.engine.util import definition
from pegleg.engine.util import files
from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
__all__ = ('encrypt', 'decrypt')

View File

@ -67,7 +67,7 @@ def _collect_to_file(site_name, save_location):
save_file = os.path.join(save_location, repo_name + '.yaml')
if repo_name not in save_files:
save_files[repo_name] = open(save_file, "w")
LOG.debug("Collecting file %s to file %s" % (filename, save_file))
LOG.debug("Collecting file %s to file %s", filename, save_file)
save_files[repo_name].writelines(_read_and_format_yaml(filename))
except Exception as ex:
raise click.ClickException("Error saving output: %s" % str(ex))

View File

@ -12,11 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from pegleg.engine.errorcodes import DECKHAND_DUPLICATE_SCHEMA
from pegleg.engine.errorcodes import DECKHAND_RENDER_EXCEPTION
from deckhand.engine import layering
from deckhand import errors as dh_errors
from pegleg.engine.errorcodes import DECKHAND_DUPLICATE_SCHEMA
from pegleg.engine.errorcodes import DECKHAND_RENDER_EXCEPTION
def load_schemas_from_docs(documents):
'''

View File

@ -12,13 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import base64
import logging
from cryptography.exceptions import InvalidSignature
from cryptography.fernet import Fernet
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.exceptions import InvalidSignature
KEY_LENGTH = 32
ITERATIONS = 10000

View File

@ -12,11 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import click
import collections
import os
import yaml
import logging
import os
import click
import yaml
from pegleg import config
from pegleg.engine import util
@ -330,7 +331,7 @@ def search(search_paths):
search_paths = [search_paths]
for search_path in search_paths:
LOG.debug("Recursively collecting YAMLs from %s" % search_path)
LOG.debug("Recursively collecting YAMLs from %s", search_path)
for root, _, filenames in os.walk(search_path):
# Ignore hidden folders like .tox or .git for faster processing.
@ -372,7 +373,7 @@ def check_file_save_location(save_location):
def collect_files_by_repo(site_name):
""" Collects file by repo name in memory."""
"""Collects file by repo name in memory."""
collected_files_by_repo = collections.defaultdict(list)
for repo_base, filename in util.definition.site_files_by_repo(

View File

@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from datetime import datetime
import logging
PEGLEG_MANAGED_SCHEMA = 'pegleg/PeglegManagedDocument/v1'
ENCRYPTED = 'encrypted'
@ -22,7 +22,7 @@ METADATA = 'metadata'
LOG = logging.getLogger(__name__)
class PeglegManagedSecretsDocument():
class PeglegManagedSecretsDocument(object):
"""Object representing one Pegleg managed secret document."""
def __init__(self, secrets_document):

View File

@ -14,16 +14,17 @@
import logging
import os
import yaml
import sys
import re
import click
import sys
import click
import yaml
from pegleg.engine.util.encryption import encrypt
from pegleg.engine.util.encryption import decrypt
from pegleg.engine.util.encryption import encrypt
from pegleg.engine.util import files
from pegleg.engine.util.pegleg_managed_document import \
PeglegManagedSecretsDocument as PeglegManagedSecret
from pegleg.engine.util import files
LOG = logging.getLogger(__name__)
PASSPHRASE_PATTERN = '^.{24,}$'
@ -31,7 +32,7 @@ ENV_PASSPHRASE = 'PEGLEG_PASSPHRASE'
ENV_SALT = 'PEGLEG_SALT'
class PeglegSecretManagement():
class PeglegSecretManagement(object):
"""An object to handle operations on of a pegleg managed file."""
def __init__(self, file_path=None, docs=None):

View File

@ -18,8 +18,8 @@ import uuid
import yaml
from pegleg.engine.util import files
from pegleg.engine.exceptions import PeglegBaseException
from pegleg.engine.util import files
from shipyard_client.api_client.shipyard_api_client import ShipyardClient
from shipyard_client.api_client.shipyardclient_context import \
@ -36,7 +36,7 @@ class AuthValuesError(PeglegBaseException):
class DocumentUploadError(PeglegBaseException):
""" Exception occurs while uploading documents"""
"""Exception occurs while uploading documents"""
def __init__(self, message):
self.message = message
@ -65,18 +65,18 @@ class ShipyardHelper(object):
self.context_marker = self.ctx.obj['context_marker']
if self.context_marker is None:
self.context_marker = str(uuid.uuid4())
LOG.debug("context_marker is %s" % self.context_marker)
LOG.debug("context_marker is %s", self.context_marker)
self.site_name = self.ctx.obj['site_name']
self.client_context = ShipyardClientContext(
self.auth_vars, self.context_marker)
self.api_client = ShipyardClient(self.client_context)
def upload_documents(self):
""" Uploads documents to Shipyard """
"""Uploads documents to Shipyard """
collected_documents = files.collect_files_by_repo(self.site_name)
LOG.info("Uploading %s collection(s) " % len(collected_documents))
LOG.info("Uploading %d collection(s) ", len(collected_documents))
for idx, document in enumerate(collected_documents):
# Append flag is not required for the first
# collection being uploaded to Shipyard. It
@ -129,7 +129,7 @@ class ShipyardHelper(object):
raise DocumentUploadError(resp_text)
else:
output = self.formatted_response_handler(resp_text)
LOG.info("Uploaded document in buffer %s " % output)
LOG.info("Uploaded document in buffer %s ", output)
# Commit in the last iteration of the loop when all the documents
# have been pushed to Shipyard buffer.
@ -137,7 +137,7 @@ class ShipyardHelper(object):
return self.commit_documents()
def commit_documents(self):
""" Commit Shipyard buffer documents """
"""Commit Shipyard buffer documents """
LOG.info("Commiting Shipyard buffer documents")

View File

@ -7,7 +7,7 @@ mock==2.0.0
yapf==0.20.0
# Linting
flake8==3.3.0
hacking>=1.1.0,<1.2.0 # Apache-2.0
# Security
bandit>=1.5.0

View File

@ -455,8 +455,7 @@ def test_process_repositories_without_repositories_key_in_site_definition(
_test_process_repositories_inner(
site_name=mock.sentinel.site, expected_extra_repos={})
msg = ("The repository for site_name: %s does not contain a "
"site-definition.yaml with a 'repositories' key" % str(
mock.sentinel.site))
"site-definition.yaml with a 'repositories' key")
assert any(msg in x[1][0] for x in m_log.info.mock_calls)

10
tox.ini
View File

@ -74,6 +74,14 @@ commands = {posargs}
[flake8]
filename = *.py
show-source = true
ignore =
# [H106] Don't put vim configuration in source files.
# [H210] Require 'autospec', 'spec', or 'spec_set' in mock.patch/mock.patch.object calls
# [H904] Delay string interpolations at logging calls.
enable-extensions = H106,H201,H904
# TODO(lamt) Clean up these docstring violations if possible
# [H403] multi line docstrings should end on a new line
# [H404] multi line docstring should start without a leading new line
# [H405] multi line docstring summary not separated with an empty line
ignore = H403,H404,H405
exclude=.venv,.git,.tox,build,dist,*lib/python*,*egg,tools,*.ini,*.po,*.pot
max-complexity = 24