How to use _prospector_configure method in prospector

Best Python code snippet using prospector_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...20 def __init__(self):21 self._args = self._extra_sys_path = None22 self._collector = self._linter = None23 self._orig_sys_path = []24 def _prospector_configure(self, prospector_config, linter):25 errors = []26 linter.load_default_plugins()27 if 'django' in prospector_config.libraries:28 linter.load_plugin_modules(['pylint_django'])29 if 'celery' in prospector_config.libraries:30 linter.load_plugin_modules(['pylint_celery'])31 if 'flask' in prospector_config.libraries:32 linter.load_plugin_modules(['pylint_flask'])33 profile_path = os.path.join(34 prospector_config.workdir, prospector_config.profile.name)35 for plugin in prospector_config.profile.pylint.get('load-plugins', []):36 try:37 linter.load_plugin_modules([plugin])38 except ImportError:39 errors.append(40 self._error_message(41 profile_path, "Could not load plugin %s" % plugin))42 for msg_id in prospector_config.get_disabled_messages('pylint'):43 try:44 linter.disable(msg_id)45 # pylint: disable=pointless-except46 except UnknownMessageError:47 # If the msg_id doesn't exist in PyLint any more,48 # don't worry about it.49 pass50 options = prospector_config.tool_options('pylint')51 for checker in linter.get_checkers():52 if not hasattr(checker, 'options'):53 continue54 for option in checker.options:55 if option[0] in options:56 checker.set_option(option[0], options[option[0]])57 # The warnings about disabling warnings are useful for figuring out58 # with other tools to suppress messages from. For example, an unused59 # import which is disabled with 'pylint disable=unused-import' will60 # still generate an 'FL0001' unused import warning from pyflakes.61 # Using the information from these messages, we can figure out what62 # was disabled.63 linter.disable(64 'locally-disabled') # notification about disabling a message65 linter.enable(66 'file-ignored') # notification about disabling an entire file67 linter.enable('suppressed-message'68 ) # notification about a message being supressed69 linter.disable(70 'useless-suppression'71 ) # notification about message supressed which was not raised72 linter.disable(73 'deprecated-pragma'74 ) # notification about use of deprecated 'pragma' option75 # disable the 'mixed indentation' warning, since it actually will only76 # allow the indentation specified in the pylint configuration file; we77 # replace it instead with our own version which is more lenient and78 # configurable79 linter.disable('mixed-indentation')80 indent_checker = IndentChecker(linter)81 linter.register_checker(indent_checker)82 max_line_length = prospector_config.max_line_length83 for checker in linter.get_checkers():84 if not hasattr(checker, 'options'):85 continue86 for option in checker.options:87 if max_line_length is not None:88 if option[0] == 'max-line-length':89 checker.set_option('max-line-length', max_line_length)90 return errors91 def _error_message(self, filepath, message):92 location = Location(filepath, None, None, 0, 0)93 return Message('prospector', 'config-problem', location, message)94 def _pylintrc_configure(self, pylintrc, linter):95 errors = []96 linter.load_default_plugins()97 are_plugins_loaded = linter.config_from_file(pylintrc)98 if not are_plugins_loaded and hasattr(linter.config, 'load_plugins'):99 for plugin in linter.config.load_plugins:100 try:101 linter.load_plugin_modules([plugin])102 except ImportError:103 errors.append(104 self._error_message(105 pylintrc, "Could not load plugin %s" % plugin))106 return errors107 def configure(self, prospector_config, found_files):108 config_messages = []109 extra_sys_path = found_files.get_minimal_syspath()110 # create a list of packages, but don't include packages which are111 # subpackages of others as checks will be duplicated112 packages = [113 os.path.split(p)114 for p in found_files.iter_package_paths(abspath=False)115 ]116 packages.sort(key=len)117 check_paths = set()118 for package in packages:119 package_path = os.path.join(*package)120 if len(package) == 1:121 check_paths.add(package_path)122 continue123 for i in range(1, len(package)):124 if os.path.join(*package[:-i]) in check_paths:125 break126 else:127 check_paths.add(package_path)128 for filepath in found_files.iter_module_paths(abspath=False):129 package = os.path.dirname(filepath).split(os.path.sep)130 for i in range(0, len(package)):131 if os.path.join(*package[:i + 1]) in check_paths:132 break133 else:134 check_paths.add(filepath)135 check_paths = [found_files.to_absolute_path(p) for p in check_paths]136 # insert the target path into the system path to get correct behaviour137 self._orig_sys_path = sys.path138 # note: we prepend, so that modules are preferentially found in the139 # path given as an argument. This prevents problems where we are140 # checking a module which is already on sys.path before this141 # manipulation - for example, if we are checking 'requests' in a local142 # checkout, but 'requests' is already installed system wide, pylint143 # will discover the system-wide modules first if the local checkout144 # does not appear first in the path145 sys.path = list(extra_sys_path) + sys.path146 ext_found = False147 configured_by = None148 linter = ProspectorLinter(found_files)149 if prospector_config.use_external_config('pylint'):150 # try to find a .pylintrc151 pylint_options = prospector_config.tool_options('pylint')152 pylintrc = pylint_options.get('config_file')153 external_config = prospector_config.external_config_location('pylint')154 if pylintrc is None or external_config:155 pylintrc = external_config156 if pylintrc is None:157 pylintrc = find_pylintrc()158 if pylintrc is None:159 pylintrc_path = os.path.join(prospector_config.workdir,160 '.pylintrc')161 if os.path.exists(pylintrc_path):162 pylintrc = pylintrc_path163 if pylintrc is not None:164 # load it!165 configured_by = pylintrc166 ext_found = True167 self._args = linter.load_command_line_configuration(168 check_paths)169 config_messages += self._pylintrc_configure(pylintrc, linter)170 if not ext_found:171 linter.reset_options()172 self._args = linter.load_command_line_configuration(check_paths)173 config_messages = self._prospector_configure(174 prospector_config, linter)175 # Pylint 1.4 introduced the idea of explicitly specifying which176 # C-extensions to load. This is because doing so allows them to177 # execute any code whatsoever, which is considered to be unsafe.178 # The following option turns off this, allowing any extension to179 # load again, since any setup.py can execute arbitrary code and180 # the safety gained through this approach seems minimal. Leaving181 # it on means that the inference engine cannot do much inference182 # on modules with C-extensions which is a bit useless.183 linter.set_option('unsafe-load-any-extension', True)184 # we don't want similarity reports right now185 linter.disable('similarities')186 # use the collector 'reporter' to simply gather the messages187 # given by PyLint...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run prospector automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful