Skip to content

Commit d1e9735

Browse files
committed
enable pylint pre-commit hook
1 parent 8216037 commit d1e9735

13 files changed

+44
-108
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ repos:
1616
rev: v1.4.0
1717
hooks:
1818
- id: doctoc
19+
- repo: [email protected]:PyCQa/pylint
20+
rev: pylint-2.5.3
21+
hooks:
22+
- id: pylint

.pylintrc

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[MASTER]
22

3+
# Specify a score threshold to be exceeded before program exits with error.
4+
fail-under=9
5+
36
# List of plugins (as comma separated values of python module names) to load,
47
# usually to register additional checkers.
58
load-plugins=
@@ -36,85 +39,8 @@ confidence=
3639
# --disable=W".
3740
disable=missing-function-docstring,
3841
missing-module-docstring,
39-
parameter-unpacking,
40-
unpacking-in-except,
41-
old-raise-syntax,
42-
backtick,
43-
long-suffix,
44-
old-ne-operator,
45-
old-octal-literal,
46-
import-star-module-level,
47-
non-ascii-bytes-literal,
48-
raw-checker-failed,
49-
bad-inline-option,
50-
locally-disabled,
51-
file-ignored,
5242
line-too-long,
53-
suppressed-message,
54-
useless-suppression,
55-
deprecated-pragma,
56-
use-symbolic-message-instead,
57-
apply-builtin,
58-
basestring-builtin,
59-
buffer-builtin,
60-
cmp-builtin,
61-
coerce-builtin,
62-
execfile-builtin,
63-
file-builtin,
64-
long-builtin,
65-
raw_input-builtin,
66-
reduce-builtin,
67-
standarderror-builtin,
68-
unicode-builtin,
69-
xrange-builtin,
70-
coerce-method,
71-
delslice-method,
72-
getslice-method,
73-
setslice-method,
74-
no-absolute-import,
75-
old-division,
76-
dict-iter-method,
77-
dict-view-method,
78-
next-method-called,
79-
metaclass-assignment,
80-
indexing-exception,
81-
raising-string,
82-
reload-builtin,
83-
oct-method,
84-
hex-method,
85-
nonzero-method,
86-
cmp-method,
87-
input-builtin,
88-
round-builtin,
89-
intern-builtin,
90-
unichr-builtin,
91-
map-builtin-not-iterating,
92-
zip-builtin-not-iterating,
93-
range-builtin-not-iterating,
94-
filter-builtin-not-iterating,
95-
using-cmp-argument,
96-
eq-without-hash,
97-
div-method,
98-
idiv-method,
99-
rdiv-method,
100-
exception-message-attribute,
101-
invalid-str-codec,
102-
sys-max-int,
103-
bad-python3-import,
104-
deprecated-string-function,
105-
deprecated-str-translate-call,
106-
deprecated-itertools-function,
107-
deprecated-types-field,
108-
next-method-defined,
109-
dict-items-not-iterating,
110-
dict-keys-not-iterating,
111-
dict-values-not-iterating,
112-
deprecated-operator-function,
113-
deprecated-urllib-function,
114-
xreadlines-attribute,
115-
deprecated-sys-function,
116-
exception-escape,
117-
comprehension-escape
43+
duplicate-code
11844

11945
# Enable the message, report, category or checker with the given id(s). You can
12046
# either give multiple identifier separated by comma (,) or put this option

k8t/filters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def b64decode(value: Any) -> str:
6868
def hashf(value, method="sha256"):
6969
try:
7070
hash_method = getattr(hashlib, method)()
71-
except AttributeError:
72-
raise RuntimeError("No such hash method: {}".format(method))
71+
except AttributeError as no_hash_method:
72+
raise RuntimeError("No such hash method: {}".format(method)) from no_hash_method
7373

7474
if isinstance(value, str):
7575
hash_method.update(value.encode())
@@ -90,8 +90,8 @@ def get_secret(key: str, length: int = None) -> str:
9090
provider_name = str(provider_name).lower()
9191
try:
9292
provider = getattr(secret_providers, provider_name)
93-
except AttributeError:
94-
raise NotImplementedError("secret provider {} does not exist.".format(provider_name))
93+
except AttributeError as no_secret_provider:
94+
raise NotImplementedError("secret provider {} does not exist.".format(provider_name)) from no_secret_provider
9595

9696
return provider(key, length)
9797

k8t/secret_providers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import logging
1111
import string
1212

13-
import boto3
14-
import botocore
13+
import boto3 # pylint: disable=E0401
14+
import botocore # pylint: disable=E0401
1515
from k8t import config
1616

1717
try:
@@ -50,7 +50,7 @@ def ssm(key: str, length: int = None) -> str:
5050
client.exceptions.ParameterNotFound,
5151
botocore.exceptions.ClientError,
5252
) as exc:
53-
raise RuntimeError(f"Failed to retrieve secret {key}: {exc}")
53+
raise RuntimeError(f"Failed to retrieve secret {key}: {exc}") from exc
5454

5555

5656
def random(key: str, length: int = None) -> str:

k8t/templates.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
99

1010
import logging
11-
import os
1211
from typing import Set, Tuple
1312

14-
import yaml
15-
from jinja2 import Environment, meta, nodes
13+
import yaml # pylint: disable=E0401
14+
from jinja2 import Environment, meta, nodes # pylint: disable=E0401
1615

1716
from k8t import config
1817

@@ -113,6 +112,6 @@ def render(template_path: str, values: dict, engine: Environment) -> str:
113112
try:
114113
yaml.safe_load_all(output)
115114
except (yaml.scanner.ScannerError, yaml.parser.ParserError) as err:
116-
raise YamlValidationError(err)
115+
raise YamlValidationError(err) from err
117116

118117
return output

tests/cli.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
from click.testing import CliRunner
1313

1414
import boto3
15+
from moto import mock_ssm # pylint: disable=E0401
16+
1517
from k8t import __license__, __version__
1618
from k8t.cli import root
1719
from k8t.scaffolding import list_available_templates
18-
from moto import mock_ssm
1920

2021

2122
def test_print_version():
@@ -25,13 +26,15 @@ def test_print_version():
2526
assert result.exit_code == 0
2627
assert __version__ in result.output
2728

29+
2830
def test_print_license():
2931
runner = CliRunner()
3032

3133
result = runner.invoke(root, ['license'])
3234
assert result.exit_code == 0
3335
assert __license__ in result.output
3436

37+
3538
def test_new_project():
3639
runner = CliRunner()
3740

@@ -46,6 +49,7 @@ def test_new_project():
4649
assert os.path.exists('test/values.yaml')
4750
assert os.path.exists('test/config.yaml')
4851

52+
4953
def test_new_cluster():
5054
runner = CliRunner()
5155

@@ -60,6 +64,7 @@ def test_new_cluster():
6064
assert os.path.exists('./clusters/cluster-1/values.yaml')
6165
assert os.path.exists('./clusters/cluster-1/config.yaml')
6266

67+
6368
def test_new_environment():
6469
runner = CliRunner()
6570

@@ -84,6 +89,7 @@ def test_new_environment():
8489
assert os.path.exists('./clusters/cluster-1/environments/production/values.yaml')
8590
assert os.path.exists('./clusters/cluster-1/environments/production/config.yaml')
8691

92+
8793
def test_new_template():
8894
template_type = list(list_available_templates())[0]
8995
runner = CliRunner()
@@ -137,15 +143,16 @@ def test_new_template():
137143
assert f'Template created: ./templates/{template_type}.yaml.j2' in result.output
138144
assert os.path.exists(f'./templates/{template_type}.yaml.j2')
139145

146+
140147
def test_get_clusters():
141148
runner = CliRunner()
142149

143150
result = runner.invoke(root, ['get', 'clusters', 'tests/resources/good'])
144151
assert result.exit_code == 0
145-
# TODO: Fix that, should return clusters, not environments
146152
assert 'cluster-1' in result.output
147153
assert 'cluster-2' in result.output
148154

155+
149156
def test_get_environments():
150157
runner = CliRunner()
151158

@@ -165,7 +172,8 @@ def test_get_environments():
165172
assert result.exit_code == 0
166173
assert not result.output
167174

168-
def test_get_templates():
175+
176+
def test_get_templates(): # pylint: disable=R0915
169177
runner = CliRunner()
170178

171179
result = runner.invoke(root, ['get', 'templates', 'tests/resources/good'])
@@ -224,7 +232,8 @@ def test_get_templates():
224232
assert 'cluster-1-env-template.yaml.j2' not in result.output
225233
assert 'composite-template.yaml.j2' in result.output
226234

227-
def test_validate_successful():
235+
236+
def test_validate_successful(): # pylint: disable=R0915
228237
runner = CliRunner()
229238

230239
result = runner.invoke(root, ['validate', 'tests/resources/good'])
@@ -283,11 +292,12 @@ def test_validate_successful():
283292
assert 'cluster-1-env-template.yaml.j2: ✔' not in result.output
284293
assert 'composite-template.yaml.j2: ✔' in result.output
285294

295+
286296
def test_validate_with_values():
287297
runner = CliRunner()
288298

289299
result = runner.invoke(root, ['validate', 'tests/resources/missing_values'])
290-
assert result.exit_code # TODO: Should be 1
300+
assert result.exit_code == 1
291301
assert 'template.yaml.j2: ✗' in result.output
292302
assert '- undefined variable: test' in result.output
293303

@@ -302,6 +312,7 @@ def test_validate_with_values():
302312
assert result.exit_code == 0
303313
assert 'template.yaml.j2: ✔' in result.output
304314

315+
305316
def test_validate_failure():
306317
runner = CliRunner()
307318

@@ -310,7 +321,7 @@ def test_validate_failure():
310321
# assert 'filter-template.yaml.j2: ✗' in result.output
311322
# assert 'nested-value-adding-template.yaml.j2: ✗' in result.output
312323
# assert 'nested-value-template.yaml.j2: ✗' in result.output
313-
assert 'secret-template.yaml.j2: ✗' in result.output # TODO: Crushes, check file
324+
assert 'secret-template.yaml.j2: ✗' in result.output
314325
assert 'several-template.yaml.j2: ✗' in result.output
315326
assert 'value-template.yaml.j2: ✗' in result.output
316327
assert 'composite-template.yaml.j2: ✗' in result.output

tests/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
#
88
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
99

10-
from k8t import config
10+
from k8t import config # pylint: disable=W0611

tests/engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
# Copyright © 2020 Clark Germany GmbH
1212
# Author: Aljosha Friemann <[email protected]>
1313

14-
from k8t.engine import build
14+
from k8t.engine import build # pylint: disable=W0611
1515

1616
# vim: fenc=utf-8:ts=4:sw=4:expandtab

tests/examples.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#
77
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
88

9-
import os
10-
11-
from click.testing import CliRunner
9+
from click.testing import CliRunner # pylint: disable=E0401
1210

1311
from k8t.cli import root
1412

tests/filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# Author: Aljosha Friemann <[email protected]>
1313

1414
import random
15-
import pytest
16-
from mock import patch
15+
import pytest # pylint: disable=E0401
16+
from mock import patch # pylint: disable=E0401
1717

1818
from k8t import config, secret_providers
1919
from k8t.filters import b64decode, b64encode, hashf, random_password, to_bool, get_secret

tests/secret_providers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
99

1010
import boto3
11-
import pytest
11+
import pytest # pylint: disable=E0401
12+
from moto import mock_ssm # pylint: disable=E0401
13+
1214
from k8t import config
1315
from k8t.secret_providers import random, ssm
14-
from moto import mock_ssm
15-
1616

1717
def test_random():
1818
config.CONFIG = {"secrets": {"provider": "random"}}

tests/templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
# Copyright © 2020 Clark Germany GmbH
1212
# Author: Aljosha Friemann <[email protected]>
1313

14-
from k8t.templates import analyze
14+
from k8t.templates import analyze # pylint: disable=W0611
1515

1616
# vim: fenc=utf-8:ts=4:sw=4:expandtab

tests/util.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#
88
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
99

10-
import random
11-
1210
from k8t.util import deep_merge, merge
1311

1412

0 commit comments

Comments
 (0)