1 |
commit: aa32986eecd93ed87cbdb347c3ee4f943f397510 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Feb 16 07:24:35 2017 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Feb 16 07:24:35 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=aa32986e |
7 |
|
8 |
ekeyword: add a linter helper |
9 |
|
10 |
src/ekeyword/.pylintrc | 37 +++++++++++++++++++++++++++++ |
11 |
src/ekeyword/ekeyword.py | 15 ++++++++---- |
12 |
src/ekeyword/ekeyword_unittest.py | 2 ++ |
13 |
src/ekeyword/pylint | 49 +++++++++++++++++++++++++++++++++++++++ |
14 |
4 files changed, 99 insertions(+), 4 deletions(-) |
15 |
|
16 |
diff --git a/src/ekeyword/.pylintrc b/src/ekeyword/.pylintrc |
17 |
new file mode 100644 |
18 |
index 0000000..6a040d8 |
19 |
--- /dev/null |
20 |
+++ b/src/ekeyword/.pylintrc |
21 |
@@ -0,0 +1,37 @@ |
22 |
+[MESSAGES CONTROL] |
23 |
+# Disable the message, report, category or checker with the given id(s). You |
24 |
+# can either give multiple identifier separated by comma (,) or put this option |
25 |
+# multiple times (only on the command line, not in the configuration file where |
26 |
+# it should appear only once). |
27 |
+disable= |
28 |
+ missing-docstring, |
29 |
+ too-many-lines, |
30 |
+ too-many-branches, |
31 |
+ too-many-statements, |
32 |
+ too-few-public-methods, |
33 |
+ too-many-instance-attributes, |
34 |
+ too-many-public-methods, |
35 |
+ too-many-locals, |
36 |
+ too-many-arguments, |
37 |
+ locally-enabled, |
38 |
+ locally-disabled, |
39 |
+ fixme, |
40 |
+ bad-whitespace, |
41 |
+ bad-continuation, |
42 |
+ invalid-name, |
43 |
+ |
44 |
+[REPORTS] |
45 |
+reports=no |
46 |
+ |
47 |
+[FORMAT] |
48 |
+max-line-length=80 |
49 |
+indent-string='\t' |
50 |
+ |
51 |
+[SIMILARITIES] |
52 |
+min-similarity-lines=20 |
53 |
+ |
54 |
+[VARIABLES] |
55 |
+dummy-variables-rgx=_ |
56 |
+ |
57 |
+[DESIGN] |
58 |
+max-parents=10 |
59 |
|
60 |
diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py |
61 |
index a36dcd3..56e284b 100755 |
62 |
--- a/src/ekeyword/ekeyword.py |
63 |
+++ b/src/ekeyword/ekeyword.py |
64 |
@@ -179,7 +179,7 @@ def process_keywords(keywords, ops, arch_status=None): |
65 |
# Process all possible keywords. We use the arch_status as a |
66 |
# master list. If it lacks some keywords, then we might miss |
67 |
# somethings here, but not much we can do. |
68 |
- arches = old_arches |
69 |
+ arches = list(old_arches) |
70 |
|
71 |
# We ignore the glob arch as we never want to tweak it. |
72 |
if '*' in arches: |
73 |
@@ -192,7 +192,7 @@ def process_keywords(keywords, ops, arch_status=None): |
74 |
# in these cases. |
75 |
arches = [x for x in arches if '-' + x not in new_keywords] |
76 |
else: |
77 |
- arches = (oarch,) |
78 |
+ arches = [oarch] |
79 |
|
80 |
if refarch: |
81 |
# Figure out the state for this arch based on the reference arch. |
82 |
@@ -319,6 +319,13 @@ def process_ebuild(ebuild, ops, arch_status=None, verbose=0, quiet=0, |
83 |
return updated |
84 |
|
85 |
|
86 |
+def portage_settings(): |
87 |
+ """Return the portage settings we care about.""" |
88 |
+ # Portage creates the db member on the fly which confuses the linter. |
89 |
+ # pylint: disable=no-member |
90 |
+ return portage.db['/']['vartree'].settings |
91 |
+ |
92 |
+ |
93 |
def load_profile_data(portdir=None, repo='gentoo'): |
94 |
"""Load the list of known arches from the tree |
95 |
|
96 |
@@ -331,7 +338,7 @@ def load_profile_data(portdir=None, repo='gentoo'): |
97 |
{'x86': 'stable', 'mips': 'dev', ...} |
98 |
""" |
99 |
if portdir is None: |
100 |
- portdir = portage.db['/']['vartree'].settings.repositories[repo].location |
101 |
+ portdir = portage_settings().repositories[repo].location |
102 |
|
103 |
arch_status = {} |
104 |
|
105 |
@@ -497,7 +504,7 @@ def main(argv): |
106 |
parser.error('need arches/ebuilds to process') |
107 |
|
108 |
if opts.style == 'auto': |
109 |
- if not portage.db['/']['vartree'].settings.get('NOCOLOR', 'false').lower() in ('no', 'false'): |
110 |
+ if not portage_settings().get('NOCOLOR', 'false').lower() in ('no', 'false'): |
111 |
nocolor() |
112 |
opts.style = 'short' |
113 |
else: |
114 |
|
115 |
diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py |
116 |
index 7b9017e..be84cc1 100755 |
117 |
--- a/src/ekeyword/ekeyword_unittest.py |
118 |
+++ b/src/ekeyword/ekeyword_unittest.py |
119 |
@@ -3,6 +3,8 @@ |
120 |
# Distributed under the terms of the GNU General Public License v2 |
121 |
# Written by Mike Frysinger <vapier@g.o> |
122 |
|
123 |
+# pylint: disable=no-self-use |
124 |
+ |
125 |
"""Unittests for ekeyword""" |
126 |
|
127 |
import os |
128 |
|
129 |
diff --git a/src/ekeyword/pylint b/src/ekeyword/pylint |
130 |
new file mode 100755 |
131 |
index 0000000..3a9a368 |
132 |
--- /dev/null |
133 |
+++ b/src/ekeyword/pylint |
134 |
@@ -0,0 +1,49 @@ |
135 |
+#!/usr/bin/python |
136 |
+# -*- coding: utf-8 -*- |
137 |
+# Copyright 1999-2017 Gentoo Foundation |
138 |
+# Distributed under the terms of the GNU General Public License v2 |
139 |
+ |
140 |
+"""Run pylint with the right settings.""" |
141 |
+ |
142 |
+from __future__ import print_function |
143 |
+ |
144 |
+import os |
145 |
+import sys |
146 |
+ |
147 |
+ |
148 |
+def find_all_modules(source_root): |
149 |
+ """Locate all python modules in the tree for scanning""" |
150 |
+ ret = [] |
151 |
+ |
152 |
+ for root, _dirs, files in os.walk(source_root, topdown=False): |
153 |
+ # Add all of the .py modules in the tree. |
154 |
+ ret += [os.path.join(root, x) for x in files if x.endswith('.py')] |
155 |
+ |
156 |
+ # Add the main scripts that don't end in .py. |
157 |
+ ret += [os.path.join(source_root, x) for x in ('pylint',)] |
158 |
+ |
159 |
+ return ret |
160 |
+ |
161 |
+ |
162 |
+def main(argv): |
163 |
+ """The main entry point""" |
164 |
+ source_root = os.path.dirname(os.path.realpath(__file__)) |
165 |
+ |
166 |
+ if not argv: |
167 |
+ argv = find_all_modules(source_root) |
168 |
+ |
169 |
+ pympath = source_root |
170 |
+ pythonpath = os.environ.get('PYTHONPATH') |
171 |
+ if pythonpath is None: |
172 |
+ pythonpath = pympath |
173 |
+ else: |
174 |
+ pythonpath = pympath + ':' + pythonpath |
175 |
+ os.environ['PYTHONPATH'] = pythonpath |
176 |
+ |
177 |
+ pylintrc = os.path.join(source_root, '.pylintrc') |
178 |
+ cmd = ['pylint', '--rcfile', pylintrc] |
179 |
+ os.execvp(cmd[0], cmd + argv) |
180 |
+ |
181 |
+ |
182 |
+if __name__ == '__main__': |
183 |
+ sys.exit(main(sys.argv[1:])) |