Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: third_party/pylint/pylint/config.py

Issue 1920403002: [content/test/gpu] Run pylint check of gpu tests in unittest instead of PRESUBMIT (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update path to LICENSE.txt of logilab/README.chromium Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/pylint/pylint/checkers/variables.py ('k') | third_party/pylint/pylint/epylint.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
2 # This program is free software; you can redistribute it and/or modify it under
3 # the terms of the GNU General Public License as published by the Free Software
4 # Foundation; either version 2 of the License, or (at your option) any later
5 # version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT
8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
10 #
11 # You should have received a copy of the GNU General Public License along with
12 # this program; if not, write to the Free Software Foundation, Inc.,
13 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14 """utilities for Pylint configuration :
15
16 * pylintrc
17 * pylint.d (PYLINTHOME)
18 """
19 from __future__ import with_statement
20 from __future__ import print_function
21
22 import pickle
23 import os
24 import sys
25 from os.path import exists, isfile, join, expanduser, abspath, dirname
26
27 # pylint home is used to save old runs results ################################
28
29 USER_HOME = expanduser('~')
30 if 'PYLINTHOME' in os.environ:
31 PYLINT_HOME = os.environ['PYLINTHOME']
32 if USER_HOME == '~':
33 USER_HOME = dirname(PYLINT_HOME)
34 elif USER_HOME == '~':
35 PYLINT_HOME = ".pylint.d"
36 else:
37 PYLINT_HOME = join(USER_HOME, '.pylint.d')
38
39 def get_pdata_path(base_name, recurs):
40 """return the path of the file which should contain old search data for the
41 given base_name with the given options values
42 """
43 base_name = base_name.replace(os.sep, '_')
44 return join(PYLINT_HOME, "%s%s%s"%(base_name, recurs, '.stats'))
45
46 def load_results(base):
47 """try to unpickle and return data from file if it exists and is not
48 corrupted
49
50 return an empty dictionary if it doesn't exists
51 """
52 data_file = get_pdata_path(base, 1)
53 try:
54 with open(data_file, _PICK_LOAD) as stream:
55 return pickle.load(stream)
56 except Exception: # pylint: disable=broad-except
57 return {}
58
59 if sys.version_info < (3, 0):
60 _PICK_DUMP, _PICK_LOAD = 'w', 'r'
61 else:
62 _PICK_DUMP, _PICK_LOAD = 'wb', 'rb'
63
64 def save_results(results, base):
65 """pickle results"""
66 if not exists(PYLINT_HOME):
67 try:
68 os.mkdir(PYLINT_HOME)
69 except OSError:
70 print('Unable to create directory %s' % PYLINT_HOME, file=sys.stderr )
71 data_file = get_pdata_path(base, 1)
72 try:
73 with open(data_file, _PICK_DUMP) as stream:
74 pickle.dump(results, stream)
75 except (IOError, OSError) as ex:
76 print('Unable to create file %s: %s' % (data_file, ex), file=sys.stderr)
77
78 # location of the configuration file ##########################################
79
80
81 def find_pylintrc():
82 """search the pylint rc file and return its path if it find it, else None
83 """
84 # is there a pylint rc file in the current directory ?
85 if exists('pylintrc'):
86 return abspath('pylintrc')
87 if isfile('__init__.py'):
88 curdir = abspath(os.getcwd())
89 while isfile(join(curdir, '__init__.py')):
90 curdir = abspath(join(curdir, '..'))
91 if isfile(join(curdir, 'pylintrc')):
92 return join(curdir, 'pylintrc')
93 if 'PYLINTRC' in os.environ and exists(os.environ['PYLINTRC']):
94 pylintrc = os.environ['PYLINTRC']
95 else:
96 user_home = expanduser('~')
97 if user_home == '~' or user_home == '/root':
98 pylintrc = ".pylintrc"
99 else:
100 pylintrc = join(user_home, '.pylintrc')
101 if not isfile(pylintrc):
102 pylintrc = join(user_home, '.config', 'pylintrc')
103 if not isfile(pylintrc):
104 if isfile('/etc/pylintrc'):
105 pylintrc = '/etc/pylintrc'
106 else:
107 pylintrc = None
108 return pylintrc
109
110 PYLINTRC = find_pylintrc()
111
112 ENV_HELP = '''
113 The following environment variables are used:
114 * PYLINTHOME
115 Path to the directory where the persistent for the run will be stored. If
116 not found, it defaults to ~/.pylint.d/ or .pylint.d (in the current working
117 directory).
118 * PYLINTRC
119 Path to the configuration file. See the documentation for the method used
120 to search for configuration file.
121 ''' % globals()
122
123 # evaluation messages #########################################################
124
125 def get_note_message(note):
126 """return a message according to note
127 note is a float < 10 (10 is the highest note)
128 """
129 assert note <= 10, "Note is %.2f. Either you cheated, or pylint's \
130 broken!" % note
131 if note < 0:
132 msg = 'You have to do something quick !'
133 elif note < 1:
134 msg = 'Hey! This is really dreadful. Or maybe pylint is buggy?'
135 elif note < 2:
136 msg = "Come on! You can't be proud of this code"
137 elif note < 3:
138 msg = 'Hum... Needs work.'
139 elif note < 4:
140 msg = 'Wouldn\'t you be a bit lazy?'
141 elif note < 5:
142 msg = 'A little more work would make it acceptable.'
143 elif note < 6:
144 msg = 'Just the bare minimum. Give it a bit more polish. '
145 elif note < 7:
146 msg = 'This is okay-ish, but I\'m sure you can do better.'
147 elif note < 8:
148 msg = 'If you commit now, people should not be making nasty \
149 comments about you on c.l.py'
150 elif note < 9:
151 msg = 'That\'s pretty good. Good work mate.'
152 elif note < 10:
153 msg = 'So close to being perfect...'
154 else:
155 msg = 'Wow ! Now this deserves our uttermost respect.\nPlease send \
156 your code to python-projects@logilab.org'
157 return msg
OLDNEW
« no previous file with comments | « third_party/pylint/pylint/checkers/variables.py ('k') | third_party/pylint/pylint/epylint.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698