Browse Source

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>
Tin Lam 4 months ago
parent
commit
1a325a400b

+ 1
- 1
pegleg/engine/lint.py View File

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

+ 1
- 1
pegleg/engine/repository.py View File

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

+ 2
- 2
pegleg/engine/secrets.py View File

@@ -15,9 +15,9 @@
15 15
 import logging
16 16
 import os
17 17
 
18
-from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
19
-from pegleg.engine.util import files
20 18
 from pegleg.engine.util import definition
19
+from pegleg.engine.util import files
20
+from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
21 21
 
22 22
 __all__ = ('encrypt', 'decrypt')
23 23
 

+ 1
- 1
pegleg/engine/site.py View File

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

+ 4
- 2
pegleg/engine/util/deckhand.py View File

@@ -12,11 +12,13 @@
12 12
 # See the License for the specific language governing permissions and
13 13
 # limitations under the License.
14 14
 
15
-from pegleg.engine.errorcodes import DECKHAND_DUPLICATE_SCHEMA
16
-from pegleg.engine.errorcodes import DECKHAND_RENDER_EXCEPTION
15
+
17 16
 from deckhand.engine import layering
18 17
 from deckhand import errors as dh_errors
19 18
 
19
+from pegleg.engine.errorcodes import DECKHAND_DUPLICATE_SCHEMA
20
+from pegleg.engine.errorcodes import DECKHAND_RENDER_EXCEPTION
21
+
20 22
 
21 23
 def load_schemas_from_docs(documents):
22 24
     '''

+ 3
- 2
pegleg/engine/util/encryption.py View File

@@ -12,13 +12,14 @@
12 12
 # See the License for the specific language governing permissions and
13 13
 # limitations under the License.
14 14
 
15
-import logging
16 15
 import base64
16
+import logging
17
+
18
+from cryptography.exceptions import InvalidSignature
17 19
 from cryptography.fernet import Fernet
18 20
 from cryptography.hazmat.backends import default_backend
19 21
 from cryptography.hazmat.primitives import hashes
20 22
 from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
21
-from cryptography.exceptions import InvalidSignature
22 23
 
23 24
 KEY_LENGTH = 32
24 25
 ITERATIONS = 10000

+ 5
- 4
pegleg/engine/util/files.py View File

@@ -12,11 +12,12 @@
12 12
 # See the License for the specific language governing permissions and
13 13
 # limitations under the License.
14 14
 
15
-import click
16 15
 import collections
16
+import logging
17 17
 import os
18
+
19
+import click
18 20
 import yaml
19
-import logging
20 21
 
21 22
 from pegleg import config
22 23
 from pegleg.engine import util
@@ -330,7 +331,7 @@ def search(search_paths):
330 331
         search_paths = [search_paths]
331 332
 
332 333
     for search_path in search_paths:
333
-        LOG.debug("Recursively collecting YAMLs from %s" % search_path)
334
+        LOG.debug("Recursively collecting YAMLs from %s", search_path)
334 335
         for root, _, filenames in os.walk(search_path):
335 336
 
336 337
             # Ignore hidden folders like .tox or .git for faster processing.
@@ -372,7 +373,7 @@ def check_file_save_location(save_location):
372 373
 
373 374
 
374 375
 def collect_files_by_repo(site_name):
375
-    """ Collects file by repo name in memory."""
376
+    """Collects file by repo name in memory."""
376 377
 
377 378
     collected_files_by_repo = collections.defaultdict(list)
378 379
     for repo_base, filename in util.definition.site_files_by_repo(

+ 2
- 2
pegleg/engine/util/pegleg_managed_document.py View File

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

+ 6
- 5
pegleg/engine/util/pegleg_secret_management.py View File

@@ -14,16 +14,17 @@
14 14
 
15 15
 import logging
16 16
 import os
17
-import yaml
18
-import sys
19 17
 import re
18
+import sys
19
+
20 20
 import click
21
+import yaml
21 22
 
22
-from pegleg.engine.util.encryption import encrypt
23 23
 from pegleg.engine.util.encryption import decrypt
24
+from pegleg.engine.util.encryption import encrypt
25
+from pegleg.engine.util import files
24 26
 from pegleg.engine.util.pegleg_managed_document import \
25 27
     PeglegManagedSecretsDocument as PeglegManagedSecret
26
-from pegleg.engine.util import files
27 28
 
28 29
 LOG = logging.getLogger(__name__)
29 30
 PASSPHRASE_PATTERN = '^.{24,}$'
@@ -31,7 +32,7 @@ ENV_PASSPHRASE = 'PEGLEG_PASSPHRASE'
31 32
 ENV_SALT = 'PEGLEG_SALT'
32 33
 
33 34
 
34
-class PeglegSecretManagement():
35
+class PeglegSecretManagement(object):
35 36
     """An object to handle operations on of a pegleg managed file."""
36 37
 
37 38
     def __init__(self, file_path=None, docs=None):

+ 7
- 7
pegleg/engine/util/shipyard_helper.py View File

@@ -18,8 +18,8 @@ import uuid
18 18
 
19 19
 import yaml
20 20
 
21
-from pegleg.engine.util import files
22 21
 from pegleg.engine.exceptions import PeglegBaseException
22
+from pegleg.engine.util import files
23 23
 
24 24
 from shipyard_client.api_client.shipyard_api_client import ShipyardClient
25 25
 from shipyard_client.api_client.shipyardclient_context import \
@@ -36,7 +36,7 @@ class AuthValuesError(PeglegBaseException):
36 36
 
37 37
 
38 38
 class DocumentUploadError(PeglegBaseException):
39
-    """ Exception occurs while uploading documents"""
39
+    """Exception occurs while uploading documents"""
40 40
 
41 41
     def __init__(self, message):
42 42
         self.message = message
@@ -65,18 +65,18 @@ class ShipyardHelper(object):
65 65
         self.context_marker = self.ctx.obj['context_marker']
66 66
         if self.context_marker is None:
67 67
             self.context_marker = str(uuid.uuid4())
68
-            LOG.debug("context_marker is %s" % self.context_marker)
68
+            LOG.debug("context_marker is %s", self.context_marker)
69 69
         self.site_name = self.ctx.obj['site_name']
70 70
         self.client_context = ShipyardClientContext(
71 71
             self.auth_vars, self.context_marker)
72 72
         self.api_client = ShipyardClient(self.client_context)
73 73
 
74 74
     def upload_documents(self):
75
-        """ Uploads documents to Shipyard """
75
+        """Uploads documents to Shipyard """
76 76
 
77 77
         collected_documents = files.collect_files_by_repo(self.site_name)
78 78
 
79
-        LOG.info("Uploading %s collection(s) " % len(collected_documents))
79
+        LOG.info("Uploading %d collection(s) ", len(collected_documents))
80 80
         for idx, document in enumerate(collected_documents):
81 81
             # Append flag is not required for the first
82 82
             # collection being uploaded to Shipyard. It
@@ -129,7 +129,7 @@ class ShipyardHelper(object):
129 129
                     raise DocumentUploadError(resp_text)
130 130
             else:
131 131
                 output = self.formatted_response_handler(resp_text)
132
-                LOG.info("Uploaded document in buffer %s " % output)
132
+                LOG.info("Uploaded document in buffer %s ", output)
133 133
 
134 134
         # Commit in the last iteration of the loop when all the documents
135 135
         # have been pushed to Shipyard buffer.
@@ -137,7 +137,7 @@ class ShipyardHelper(object):
137 137
             return self.commit_documents()
138 138
 
139 139
     def commit_documents(self):
140
-        """ Commit Shipyard buffer documents """
140
+        """Commit Shipyard buffer documents """
141 141
 
142 142
         LOG.info("Commiting Shipyard buffer documents")
143 143
 

+ 1
- 1
test-requirements.txt View File

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

+ 1
- 2
tests/unit/engine/test_site_repository.py View File

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

+ 9
- 1
tox.ini View File

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

Loading…
Cancel
Save