Esempio n. 1
0
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)
Esempio n. 2
0
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)