def _find_used_libraries(self, config, profile): libraries = [] # Bring in adaptors that we automatically detect are needed if config.autodetect and profile.autodetect is True: map(libraries.append, autodetect_libraries(self.workdir)) # Bring in adaptors for the specified libraries for name in set(config.uses + profile.uses): if name not in libraries: libraries.append(name) return libraries
def _determine_adapters(self): # Bring in the common adaptor if self.config.common_plugin: self.adaptors.append(CommonAdaptor()) # Bring in adaptors that we automatically detect are needed if self.config.autodetect: for name, adaptor in autodetect_libraries(self.path): self.libraries.append(name) self.adaptors.append(adaptor) # Bring in adaptors for the specified libraries for name in self.config.uses: if name not in self.libraries: self.libraries.append(name) self.adaptors.append(LIBRARY_ADAPTORS[name]())
def run(): parser = make_arg_parser() args = parser.parse_args() if args.version: sys.stdout.write("Prospector version %s\n" % __pkginfo__.get_version()) sys.exit(0) summary = { 'started': datetime.now() } path = args.path or os.path.abspath(os.getcwd()) try: formatter = FORMATTERS[args.output_format] summary['formatter'] = args.output_format except KeyError: _die("Formatter %s is not valid - possible values are %s" % ( args.output_format, ', '.join(FORMATTERS.keys()), )) libraries_used = [] profiles = [] adaptors = [] if not args.no_common_plugin: adaptors.append(CommonAdaptor()) if not args.no_autodetect: for libname, adaptor in autodetect_libraries(path): libraries_used.append(libname) adaptors.append(adaptor) strictness = args.strictness strictness_options = ('veryhigh', 'high', 'medium', 'low', 'verylow') if strictness not in strictness_options: possible = ', '.join(strictness_options) _die( "%s is not a valid value for strictness - possible values are %s" % (strictness, possible) ) else: profiles.append('strictness_%s' % strictness) summary['strictness'] = strictness for library in args.uses: if library not in LIBRARY_ADAPTORS: possible = ', '.join(LIBRARY_ADAPTORS.keys()) _die( "Library/framework %s is not valid - possible values are %s" % (library, possible) ) libraries_used.append(library) adaptors.append(LIBRARY_ADAPTORS[library]()) summary['libraries'] = ', '.join(libraries_used) if not args.doc_warnings: profiles.append('no_doc_warnings') if not args.test_warnings: profiles.append('no_test_warnings') if args.no_style_warnings: profiles.append('no_pep8') profiles += args.profiles profile_adaptor = ProfileAdaptor(profiles) adaptors.append(profile_adaptor) summary['adaptors'] = [] for adaptor in adaptors: summary['adaptors'].append(adaptor.name) summary['adaptors'] = ', '.join(summary['adaptors']) tool_runners = [] tool_names = args.tools or tools.DEFAULT_TOOLS for tool in tool_names: if not tool in tools.TOOLS: _die("Tool %s is not valid - possible values are %s" % ( tool, ', '.join(tools.TOOLS.keys()) )) if not profile_adaptor.is_tool_enabled(tool): continue tool_runners.append(tools.TOOLS[tool]()) summary['tools'] = ', '.join(tool_names) ignore = [re.compile(ignore) for ignore in profile_adaptor.profile.ignore] for tool in tool_runners: tool.prepare(path, ignore, args, adaptors) messages = [] for tool in tool_runners: try: messages += tool.run() except Exception: if args.die_on_tool_error: raise loc = Location(path, None, None, None, None) message = "Tool %s failed to run (exception was raised)" % tool.__class__.__name__ msg = Message(tool.__class__.__name__, 'failure', loc, message=message) messages.append(msg) for message in messages: if args.absolute_paths: message.to_absolute_path(path) else: message.to_relative_path(path) if not args.no_blending: messages = blender.blend(messages) summary['message_count'] = len(messages) summary['completed'] = datetime.now() delta = (summary['completed'] - summary['started']) summary['time_taken'] = '%0.2f' % delta.total_seconds() summary['started'] = str(summary['started']) summary['completed'] = str(summary['completed']) if args.messages_only: summary = None if args.summary_only: messages = None formatter(summary, messages) sys.exit(0)