Your IP : 216.73.216.213
from __future__ import absolute_import
import mimetypes
import os
import re
from dodgy.run import check_file
from prospector.message import Location, Message
from prospector.tools.base import ToolBase
def module_from_path(path):
# note : assumes a relative path
module = re.sub(r'\.py', '', path)
return '.'.join(module.split(os.path.sep)[1:])
class DodgyTool(ToolBase):
def run(self, found_files):
warnings = []
for filepath in found_files.iter_file_paths():
mimetype = mimetypes.guess_type(filepath)
if mimetype[0] is None or not mimetype[0].startswith('text/'):
continue
for line, code, message in check_file(filepath):
warnings.append({
'line': line, 'code': code, 'message': message,
'path': filepath
})
messages = []
for warning in warnings:
path = warning['path']
prefix = os.path.commonprefix([found_files.rootpath, path])
loc = Location(path, module_from_path(path[len(prefix):]), '', warning['line'], 0, absolute_path=True)
msg = Message('dodgy', warning['code'], loc, warning['message'])
messages.append(msg)
return messages