Exemple #1
0
def validate() -> None:
    """
    Crash with an error to stdout if something about this module seems amiss.

    This does not prove the module is bug-free. It just helps catch some errors
    early.

    There are three types of error we can catch early in a module:

    * Compile error (such as a syntax error) -- we never get to call validate()
    * Exec error (such as bad global variable ref) -- we never get to call
      validate()
    * Validate error (such as wrong `render()` signature) -- this is what
      validate() can catch.
    """
    render_spec = inspect.getfullargspec(render)
    assert render_spec.varargs is None, "render must not accept varargs"
    assert len(
        render_spec.args) == 2, "render must take two positional arguments"
    assert not (set(render_spec.kwonlyargs) -
                {"fetch_result", "tab_name", "input_columns"
                 }), "one of this module's keyword arguments is misspelled"

    migrate_params_spec = inspect.getfullargspec(migrate_params)
    assert (len(migrate_params_spec.args) == 1
            ), "migrate_params must take one positional argument"
    assert migrate_params_spec.varargs is None, "migrate_params must not accept varargs"
    assert migrate_params_spec.varkw is None, "migrate_params must not accept kwargs"
    assert not migrate_params_spec.kwonlyargs, "migrate_params must not accept kwargs"

    return ttypes.ValidateModuleResult()
 def _validate(self, compiled_module: CompiledModule) -> None:
     self._run_in_child(
         chroot_dir=READONLY_CHROOT_DIR,
         network_config=None,
         compiled_module=compiled_module,
         timeout=self.validate_timeout,
         result=ttypes.ValidateModuleResult(),
         function="validate_thrift",
         args=[],
     )
Exemple #3
0
def validate_thrift() -> ttypes.ValidateModuleResult:
    """
    Crash with an error to stdout if something about this module seems amiss.

    This does not prove the module is bug-free. It just helps catch some errors
    early.

    There are three types of error we can catch early in a module:

    * Compile error (such as a syntax error) -- we never get to call validate()
    * Exec error (such as bad global variable ref) -- we never get to call
      validate()
    * Validate error (such as wrong `render()` signature) -- this is what
      validate() can catch.
    """
    render_spec = inspect.getfullargspec(render)
    assert render_spec.varargs is None, "render must not accept varargs"
    if len(render_spec.args) == 3:
        assert render_spec.args[0] == "arrow_table", (
            "render must take two positional arguments, "
            "or its first argument must be `arrow_table`")
        assert render_spec.args[2] == "output_path", (
            "render must take two positional arguments, "
            "or its third argument must be `output_path`")
        assert (render_spec.varkw
                ), "render() must accept **kwargs (for forward-compatibility)"
        assert not (set(render_spec.kwonlyargs) -
                    {"fetch_result", "columns", "settings", "tab_name"
                     }), "a render() keyword argument is misspelled"
    else:
        assert len(
            render_spec.args) == 2, "render must take two positional arguments"
        assert not (set(render_spec.kwonlyargs) -
                    {"fetch_result", "tab_name", "input_columns", "settings"
                     }), "a render() keyword argument is misspelled"

    migrate_params_spec = inspect.getfullargspec(migrate_params)
    assert (len(migrate_params_spec.args) == 1
            ), "migrate_params must take one positional argument"
    assert migrate_params_spec.varargs is None, "migrate_params must not accept varargs"
    assert migrate_params_spec.varkw is None, "migrate_params must not accept kwargs"
    assert not migrate_params_spec.kwonlyargs, "migrate_params must not accept kwargs"

    fetch_spec = inspect.getfullargspec(fetch)
    assert fetch_spec.varargs is None, "fetch must not accept varargs"
    assert len(fetch_spec.args) == 1, "fetch must take one positional argument"
    assert not (set(fetch_spec.kwonlyargs) - {
        "secrets",
        "get_input_dataframe",
        "get_stored_dataframe",
        "output_path",
        "settings",
    }), "a fetch() keyword argument is misspelled"

    return ttypes.ValidateModuleResult()
Exemple #4
0
 def _validate(self, compiled_module: CompiledModule) -> None:
     with _chroot_dir_context() as chroot:
         self._run_in_child(
             chroot=chroot,
             chroot_paths=DATA_PATHS,
             compiled_module=compiled_module,
             timeout=self.validate_timeout,
             result=ttypes.ValidateModuleResult(),
             function="validate_thrift",
             args=[],
         )
Exemple #5
0
    def validate(self, compiled_module: CompiledModule) -> None:
        """Detect common errors in the user's code.

        Raise ModuleExitedError or ModuleTimeoutError on error.
        """
        self._run_in_child(
            chroot_dir=READONLY_CHROOT_DIR,
            network_config=None,
            compiled_module=compiled_module,
            timeout=self.validate_timeout,
            result=ttypes.ValidateModuleResult(),
            function="validate_thrift",
            args=[],
        )