Esempio n. 1
0
    def exit(error_type: int) -> NoReturn:
        """Using mypy's argument parser, raise `SystemExit` to fail hard if validation fails.

        Considering that the plugin's startup duration is around double as long as mypy's, this aims to
        import and construct objects only when that's required - which happens once and terminates the
        run. Considering that most of the runs are successful, there's no need for this to linger in the
        global scope.
        """
        from mypy.main import CapturableArgumentParser

        usage = """(config)
        ...
        [mypy.plugins.django_stubs]
            django_settings_module: str (required)
        ...
        """.replace(
            "\n" + 8 * " ", "\n"
        )
        handler = CapturableArgumentParser(prog="(django-stubs) mypy", usage=usage)
        messages = {
            1: "mypy config file is not specified or found",
            2: "no section [mypy.plugins.django-stubs]",
            3: "the setting is not provided",
        }
        handler.error("'django_settings_module' is not set: " + messages[error_type])
Esempio n. 2
0
def exit_with_error(msg: str, is_toml: bool = False) -> NoReturn:
    """Using mypy's argument parser, raise `SystemExit` to fail hard if validation fails.

    Considering that the plugin's startup duration is around double as long as mypy's, this aims to
    import and construct objects only when that's required - which happens once and terminates the
    run. Considering that most of the runs are successful, there's no need for this to linger in the
    global scope.
    """
    from mypy.main import CapturableArgumentParser

    handler = CapturableArgumentParser(
        prog="(django-stubs) mypy",
        usage=textwrap.dedent(TOML_USAGE if is_toml else INI_USAGE))
    handler.error(msg)
Esempio n. 3
0
    def exit_toml(error_type: int) -> NoReturn:
        from mypy.main import CapturableArgumentParser

        usage = """
        (config)
        ...
        [tool.django-stubs]
        django_settings_module = str (required)
        ...
        """
        handler = CapturableArgumentParser(prog="(django-stubs) mypy",
                                           usage=textwrap.dedent(usage))
        messages = {
            1: "mypy config file is not specified or found",
            2: "no section [tool.django-stubs]",
            3: "the setting is not provided",
            4: "the setting must be a string",
        }
        handler.error("'django_settings_module' not found or invalid: " +
                      messages[error_type])