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

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

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