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

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

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

Powered by Google App Engine
This is Rietveld 408576698