def parse_options(program_text: str, testcase: DataDrivenTestCase, incremental_step: int) -> Options: """Parse comments like '# flags: --foo' in a test case.""" options = Options() flags = re.search('# flags: (.*)$', program_text, flags=re.MULTILINE) if incremental_step > 1: flags2 = re.search(f'# flags{incremental_step}: (.*)$', program_text, flags=re.MULTILINE) if flags2: flags = flags2 if flags: flag_list = flags.group(1).split() flag_list.append('--no-site-packages') # the tests shouldn't need an installed Python targets, options = process_options(flag_list, require_targets=False) if targets: # TODO: support specifying targets via the flags pragma raise RuntimeError('Specifying targets via the flags pragma is not supported.') else: flag_list = [] options = Options() # TODO: Enable strict optional in test cases by default (requires *many* test case changes) options.strict_optional = False options.error_summary = False # Allow custom python version to override testcase_pyversion. if all(flag.split('=')[0] not in ['--python-version', '-2', '--py2'] for flag in flag_list): options.python_version = testcase_pyversion(testcase.file, testcase.name) if testcase.config.getoption('--mypy-verbose'): options.verbosity = testcase.config.getoption('--mypy-verbose') return options
def start_server_and_analyze(config, workspace, python_executable=None): if settings is None: log.error('Settings is None') return log.info(f'mypy version: {mypy_version}') log.info(f'mypyls version: {mypyls_version}') options = Options() options.check_untyped_defs = True options.follow_imports = 'error' options.use_fine_grained_cache = True options.python_executable = python_executable stderr_stream = StringIO() config_file = settings.get('configFile') if config_file == '': # Use empty string rather than null in vscode settings, so that it's shown in settings editor GUI. config_file = None log.info(f'Trying to read mypy config file from {config_file or "default locations"}') with redirect_stderr(stderr_stream): if mypy_version >= '0.770': def set_strict_flags(): # The code to set all strict options using the 'strict' flag is in mypy.main.process_options, # and we cannot access it from here, so we disable `strict = True` in the config file for now. stderr_stream.write( "Setting 'strict' in the configuration file is not supported by mypy-vscode for now. " "The option will be ignored. You may set individual strict flags instead " "(see 'mypy -h' for the list of flags enabled in strict mode).") parse_config_file(options, set_strict_flags, config_file) else: parse_config_file(options, config_file) stderr = stderr_stream.getvalue() if stderr: log.error(f'Error reading mypy config file:\n{stderr}') workspace.show_message(f'Error reading mypy config file:\n{stderr}') if options.config_file: log.info(f'Read mypy config from: {options.config_file}') else: log.info(f'Mypy configuration not read, using defaults.') if config_file: workspace.show_message(f'Mypy config file not found:\n{config_file}') options.show_column_numbers = True if options.follow_imports not in ('error', 'skip'): workspace.show_message(f"Cannot use follow_imports='{options.follow_imports}', using 'error' instead.") options.follow_imports = 'error' if mypy_version > '0.720': options.color_output = False options.error_summary = False options.pretty = False log.info(f'python_executable after applying config: {options.python_executable}') workspace.mypy_server = Server(options, DEFAULT_STATUS_FILE) mypy_check(workspace, config)
def start_server_and_analyze(config, workspace, python_executable=None): if settings is None: log.error('Settings is None') return log.info(f'mypy version: {mypy_version}') log.info(f'mypyls version: {mypyls_version}') options = Options() options.check_untyped_defs = True options.follow_imports = 'error' options.use_fine_grained_cache = True options.python_executable = python_executable stderr_stream = StringIO() config_file = settings.get('configFile') if config_file == '': # Use empty string rather than null in vscode settings, so that it's shown in settings editor GUI. config_file = None log.info( f'Trying to read mypy config file from {config_file or "default locations"}' ) with redirect_stderr(stderr_stream): parse_config_file(options, config_file) stderr = stderr_stream.getvalue() if stderr: log.error(f'Error reading mypy config file:\n{stderr}') workspace.show_message(f'Error reading mypy config file:\n{stderr}') if options.config_file: log.info(f'Read mypy config from: {options.config_file}') else: log.info(f'Mypy configuration not read, using defaults.') if config_file: workspace.show_message( f'Mypy config file not found:\n{config_file}') options.show_column_numbers = True if options.follow_imports not in ('error', 'skip'): workspace.show_message( f"Cannot use follow_imports='{options.follow_imports}', using 'error' instead." ) options.follow_imports = 'error' if mypy_version > '0.720': options.color_output = False options.error_summary = False log.info( f'python_executable after applying config: {options.python_executable}' ) workspace.mypy_server = Server(options, DEFAULT_STATUS_FILE) mypy_check(workspace, config)