Skip to content

Commit 869b5d7

Browse files
authored
Merge pull request #2458 from theotherjimmy/pylint
[tools!] Pylint checking and formatting
2 parents 8d36877 + dabd7b8 commit 869b5d7

File tree

16 files changed

+2180
-1066
lines changed

16 files changed

+2180
-1066
lines changed

.pylintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Format]
2+
max-line-length=80

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ python:
33

44
script:
55
- PYTHONPATH=. python tools/test/config_test/config_test.py
6+
- python tools/test/pylint.py
67
- py.test tools/test/toolchains/api.py
78
- python tools/build_travis.py
89
before_install:
@@ -17,3 +18,4 @@ install:
1718
- sudo pip install prettytable
1819
- sudo pip install jinja2
1920
- sudo pip install pytest
21+
- sudo pip install pylint

tools/build_api.py

Lines changed: 572 additions & 273 deletions
Large diffs are not rendered by default.

tools/colorize.py

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
"""
2-
mbed SDK
3-
Copyright (c) 2016 ARM Limited
4-
5-
Licensed under the Apache License, Version 2.0 (the "License");
6-
you may not use this file except in compliance with the License.
7-
You may obtain a copy of the License at
8-
9-
http://www.apache.org/licenses/LICENSE-2.0
10-
11-
Unless required by applicable law or agreed to in writing, software
12-
distributed under the License is distributed on an "AS IS" BASIS,
13-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
See the License for the specific language governing permissions and
15-
limitations under the License.
16-
"""
1+
# mbed SDK
2+
# Copyright (c) 2016 ARM Limited
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
1715

1816
""" This python file is responsible for generating colorized notifiers.
1917
"""
@@ -23,7 +21,7 @@
2321
from colorama import init, Fore, Back, Style
2422
init()
2523

26-
colors = {
24+
COLORS = {
2725
'none' : "",
2826
'default' : Style.RESET_ALL,
2927

@@ -46,26 +44,37 @@
4644
'on_white' : Back.WHITE,
4745
}
4846

49-
# Convert a color string from a string into an ascii escape code that will print
50-
# that color on the terminal.
51-
color_matcher = re.compile(r"(\w+)(\W+on\W+\w+)?")
47+
COLOR_MATCHER = re.compile(r"(\w+)(\W+on\W+\w+)?")
5248
def colorstring_to_escapecode(color_string):
53-
match = re.match(color_matcher, color_string)
49+
""" Convert a color string from a string into an ascii escape code that
50+
will print that color on the terminal.
51+
52+
Positional arguments:
53+
color_string - the string to parse
54+
"""
55+
match = re.match(COLOR_MATCHER, color_string)
5456
if match:
55-
return colors[match.group(1)] + (colors[match.group(2).strip().replace(" ","_")] if match.group(2) else "")
57+
return COLORS[match.group(1)] + \
58+
(COLORS[match.group(2).strip().replace(" ", "_")]
59+
if match.group(2) else "")
5660
else:
57-
return corols['default']
61+
return COLORS['default']
62+
5863

59-
# Wrap a toolchain notifier in a colorizer. This colorizer will wrap notifications
60-
# in a color if the severity matches a color in the *color_map*.
61-
def print_in_color_notifier (color_map, print_fn):
64+
def print_in_color_notifier(color_map, print_fn):
65+
""" Wrap a toolchain notifier in a colorizer. This colorizer will wrap
66+
notifications in a color if the severity matches a color in the *color_map*.
67+
"""
6268
def wrap(event, silent=False):
63-
fd = sys.stdout
69+
"""The notification function inself"""
70+
file_desc = sys.stdout
6471
self = event['toolchain']
65-
if fd.isatty() and 'severity' in event and event['severity'] in color_map:
66-
fd.write(colorstring_to_escapecode(color_map[event['severity']]))
72+
if file_desc.isatty() and 'severity' in event and \
73+
event['severity'] in color_map:
74+
file_desc.write(colorstring_to_escapecode(
75+
color_map[event['severity']]))
6776
print_fn(self, event, silent)
68-
fd.write(colorstring_to_escapecode('default'))
77+
file_desc.write(colorstring_to_escapecode('default'))
6978
else:
7079
print_fn(self, event, silent)
7180
return wrap

0 commit comments

Comments
 (0)