Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-sdk-tools by
test/pylint.py@32:8ea194f6145b, 2017-01-04 (annotated)
- Committer:
- The Other Jimmy
- Date:
- Wed Jan 04 11:58:24 2017 -0600
- Revision:
- 32:8ea194f6145b
- Parent:
- 29:1210849dba19
Update tools to follow mbed-os tools release 5.3.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 29:1210849dba19 | 1 | """A test that all code scores above a 9.25 in pylint""" |
screamer | 29:1210849dba19 | 2 | |
screamer | 29:1210849dba19 | 3 | import subprocess |
screamer | 29:1210849dba19 | 4 | import re |
screamer | 29:1210849dba19 | 5 | import os.path |
screamer | 29:1210849dba19 | 6 | |
screamer | 29:1210849dba19 | 7 | SCORE_REGEXP = re.compile( |
screamer | 29:1210849dba19 | 8 | r'^Your\ code\ has\ been\ rated\ at\ (\-?[0-9\.]+)/10') |
screamer | 29:1210849dba19 | 9 | |
screamer | 29:1210849dba19 | 10 | TOOLS_ROOT = os.path.dirname(os.path.dirname(__file__)) |
screamer | 29:1210849dba19 | 11 | |
screamer | 29:1210849dba19 | 12 | |
screamer | 29:1210849dba19 | 13 | def parse_score(pylint_output): |
screamer | 29:1210849dba19 | 14 | """Parse the score out of pylint's output as a float If the score is not |
screamer | 29:1210849dba19 | 15 | found, return 0.0. |
screamer | 29:1210849dba19 | 16 | """ |
screamer | 29:1210849dba19 | 17 | for line in pylint_output.splitlines(): |
screamer | 29:1210849dba19 | 18 | match = re.match(SCORE_REGEXP, line) |
screamer | 29:1210849dba19 | 19 | if match: |
screamer | 29:1210849dba19 | 20 | return float(match.group(1)) |
screamer | 29:1210849dba19 | 21 | return 0.0 |
screamer | 29:1210849dba19 | 22 | |
screamer | 29:1210849dba19 | 23 | def execute_pylint(filename): |
screamer | 29:1210849dba19 | 24 | """Execute a pylint process and collect it's output |
screamer | 29:1210849dba19 | 25 | """ |
screamer | 29:1210849dba19 | 26 | process = subprocess.Popen( |
screamer | 29:1210849dba19 | 27 | ["pylint", filename], |
screamer | 29:1210849dba19 | 28 | stdout=subprocess.PIPE, |
screamer | 29:1210849dba19 | 29 | stderr=subprocess.PIPE |
screamer | 29:1210849dba19 | 30 | ) |
screamer | 29:1210849dba19 | 31 | stout, sterr = process.communicate() |
screamer | 29:1210849dba19 | 32 | status = process.poll() |
screamer | 29:1210849dba19 | 33 | return status, stout, sterr |
screamer | 29:1210849dba19 | 34 | |
screamer | 29:1210849dba19 | 35 | FILES = ["build_api.py", "config.py", "colorize.py", "detect_targets.py", |
screamer | 29:1210849dba19 | 36 | "hooks.py", "libraries.py", "memap.py", "options.py", "paths.py", |
screamer | 29:1210849dba19 | 37 | "targets.py", "test/pylint.py"] |
screamer | 29:1210849dba19 | 38 | |
screamer | 29:1210849dba19 | 39 | if __name__ == "__main__": |
screamer | 29:1210849dba19 | 40 | for python_module in FILES: |
screamer | 29:1210849dba19 | 41 | _, stdout, stderr = execute_pylint(os.path.join(TOOLS_ROOT, |
screamer | 29:1210849dba19 | 42 | python_module)) |
screamer | 29:1210849dba19 | 43 | score = parse_score(stdout) |
screamer | 29:1210849dba19 | 44 | if score < 9.25: |
screamer | 29:1210849dba19 | 45 | print(stdout) |
screamer | 29:1210849dba19 | 46 | |
screamer | 29:1210849dba19 | 47 | |
screamer | 29:1210849dba19 | 48 |