Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing python interface file #218

Open
JasperJuergensen opened this issue Nov 29, 2022 · 0 comments
Open

Missing python interface file #218

JasperJuergensen opened this issue Nov 29, 2022 · 0 comments

Comments

@JasperJuergensen
Copy link

The compiled yara-python is missing a python interface file (.pyi).

Without such an interface definition, support in IDEs is quite limited (no type hinting, no code completion).

I've created a small interface file based on the documentation, which is definitely not 100% correct, but enough to enable code completion and type hinting in VSCode:

from typing import IO, Callable, Dict, List, Tuple, Union

class Match:

    rule: str
    namespace: str
    tags: List[str]
    meta: Dict[str, str]
    strings: List[Tuple[int, str, str]]

class Rules:
    def match(
        self,
        filepath: str = "",
        pid: int = 0,
        data: Union[str, bytes] = "",
        externals: dict = {},
        callback: Callable = lambda x: x,
        fast: bool = False,
        timeout: int = -1,
        modules_data: dict = {},
        modules_callback: Callable = lambda x: x,
        warnings_callback: Callable = lambda x: x,
        which_callbacks: int = 0,
        console_callback: Callable = lambda x: x,
    ) -> List[Match]:
        pass
    def save(self, filepath: str = "", file: IO = None) -> None:
        pass

def compile(
    filepath: str = "",
    source: str = "",
    file: IO = None,
    filepaths: dict = {},
    sources: dict = {},
    externals: dict = {},
    includes: bool = True,
    error_on_warning: bool = False,
) -> Rules:
    pass

def load(filepath: str = "", file: IO = None) -> Rules:
    pass

def set_config(
    stack_size: int = -1, max_strings_per_rule: int = -1, max_match_data: int = -1
) -> None:
    pass

Adding a correct .pyi file to this repo, which can also be autogenerated using mypys stubgen (https://mypy.readthedocs.io/en/stable/stubgen.html), would obviously be the preferred solution.
I already tried autogeneration with stubgen, which did not work that good (function parameters and type hints were missing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant