Esempio n. 1
0
def test_hook_man_generator_no_pyd(datadir, file_regression):
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / 'hook_specs_no_pyd.py'))
    hg.generate_project_files(dst_path=datadir)

    obtained_hook_caller_file = datadir / 'cpp' / 'HookCaller.hpp'
    file_regression.check(obtained_hook_caller_file.read_text(), basename='HookCallerNoPyd', extension='.hpp')
    assert not (datadir / 'binding').is_dir()
Esempio n. 2
0
def update(ctx, plugin_dir):
    """
    Updates plugin files automatically generated by ALFAsim-SDK.
    The plugin folder is informed with plugin-dir option.
    When not provided plugin-dir will be the current folder location.

    It is important to update the automatically generated files from each plugin when
    a new version of ALFAsim-SDK is released. Otherwise compilation problems can occur.

    The files updated are: |br|
    - ´<plugin_folder>/src/hook_specs.h´ |br|
    """
    hook_specs_file_path = _get_hook_specs_file_path()
    hm = HookManGenerator(hook_spec_file_path=hook_specs_file_path)

    plugin_folder = Path(plugin_dir)
    hook_specs_h_path = plugin_folder / "src" / "hook_specs.h"

    if not hook_specs_h_path.exists() or not hook_specs_h_path.is_file():
        raise FileNotFoundError(
            f"Was not possible to find 'src/hook_specs.h' file in {plugin_dir}"
        )

    plugin_id = plugin_folder.name
    plugin_location = plugin_folder.parent
    hm.generate_hook_specs_header(plugin_id, plugin_location)
Esempio n. 3
0
def generate_plugin_template(
    specs_path: str,
    caption: str,
    plugin_id: str,
    author_email: str,
    author_name: str,
    dst_path: Path,
):
    """
    Generate a plugin starting template with the necessary structure and files to create a plugin.

    SPECS_PATH    Path to where the hook_specs.py file is located.
    CAPTION       Caption to be used across the application to identify the plugin.
    PLUGIN_ID     A unique string to identify the plugin.
    AUTHOR_NAME   Name of the plugin author to be displayed.
    AUTHOR_EMAIL  Email of the plugin author to be displayed.

    """
    hm_generator = HookManGenerator(hook_spec_file_path=specs_path)
    hm_generator.generate_plugin_template(
        caption=caption,
        plugin_id=plugin_id,
        author_email=author_email,
        author_name=author_name,
        dst_path=Path(dst_path),
    )
    return 0
Esempio n. 4
0
def generate_build_files(ctx):
    """
    Task to generate the files necessaries to compile the tests
    """

    project_dir = Path(__file__).parent

    directory_of_the_tests = project_dir / "tests/plugins"
    directory_to_build_tests = project_dir / "build/build_directory_for_tests"

    # Clean UP
    if directory_to_build_tests.exists():
        shutil.rmtree(directory_to_build_tests)
    os.makedirs(directory_to_build_tests)

    # Finding hook_specs.py, each hook_specs represent a different project with different hooks
    hook_spec_paths = [
        path for path in directory_of_the_tests.glob("**/hook_specs.py")
        if "tmp" not in path.parts
    ]

    # CMakeList.txt that includes all sub_directory with tests to be compiled
    root_cmake_list = directory_to_build_tests / "CMakeLists.txt"
    cmake_file_of_test_build_dir = [
        f"add_subdirectory({i.parent.name })\n" for i in hook_spec_paths
    ]
    root_cmake_list.write_text("".join(cmake_file_of_test_build_dir))

    # For each hook_specs, create a directory for the compilation and generate the files
    for project_hook_spec_path in hook_spec_paths:
        project_dir_for_build = directory_to_build_tests / project_hook_spec_path.parent.name
        project_dir_for_build.mkdir(parents=True)

        hm_generator = HookManGenerator(
            hook_spec_file_path=project_hook_spec_path)
        hm_generator.generate_project_files(dst_path=project_dir_for_build)

        # Find folder with Plugins
        plugins_dirs = [
            x for x in project_hook_spec_path.parent.iterdir()
            if x.is_dir() and (x / "assets").exists()
        ]

        # Copy all the plugins to the build dir
        for plugin in plugins_dirs:
            plugin_dir_build = project_dir_for_build / f"plugin/{plugin.name}"
            shutil.copytree(src=plugin, dst=plugin_dir_build)
            (plugin_dir_build / "src/hook_specs.h").write_text(
                hm_generator._hook_specs_header_content(plugin.stem))

        # Create the CMakeFile on root of the project to include others CMake files.
        main_cmakelist = project_dir_for_build / "CMakeLists.txt"
        main_cmakelist_content = []
        main_cmakelist_content.append(
            "add_subdirectory(cpp)\nadd_subdirectory(binding)\n")
        main_cmakelist_content += [
            f"add_subdirectory(plugin/{plugin.name}/src)\n"
            for plugin in plugins_dirs
        ]
        main_cmakelist.write_text("".join(main_cmakelist_content))
Esempio n. 5
0
def generate_hook_specs_h(specs_path: str, shared_lib_name: str,
                          dst_path: Path):
    """Generates or update the hook_specs.h header file."""
    hm_generator = HookManGenerator(hook_spec_file_path=specs_path)
    hm_generator.generate_hook_specs_header(shared_lib_name=shared_lib_name,
                                            dst_path=Path(dst_path))
    return 0
Esempio n. 6
0
def test_generate_plugin_template(datadir, file_regression):
    plugin_dir = datadir / 'test_generate_plugin_template'
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / 'hook_specs.py'))

    hg.generate_plugin_template(
        caption='Acme',
        plugin_id='acme',
        author_name='FOO',
        author_email='*****@*****.**',
        dst_path=plugin_dir
    )

    obtained_hook_specs_file = datadir / 'test_generate_plugin_template/acme/src/hook_specs.h'
    file_regression.check(obtained_hook_specs_file.read_text(), basename='generate_hook_specs', extension='.h')

    obtained_plugin_yaml = datadir / 'test_generate_plugin_template/acme/assets/plugin.yaml'
    file_regression.check(obtained_plugin_yaml.read_text(), basename='generate_plugin', extension='.yaml')

    obtained_plugin_file = datadir / 'test_generate_plugin_template/acme/src/acme.cpp'
    file_regression.check(obtained_plugin_file.read_text(), basename='generate_plugin', extension='.cpp')

    obtained_readme = datadir / 'test_generate_plugin_template/acme/assets/README.md'
    file_regression.check(obtained_readme.read_text(), basename='generate_README', extension='.md')

    obtained_cmake_list = datadir / 'test_generate_plugin_template/acme/CMakeLists.txt'
    file_regression.check(obtained_cmake_list.read_text(), basename='generate_CMakeLists', extension='.txt')

    obtained_cmake_list_src = datadir / 'test_generate_plugin_template/acme/src/CMakeLists.txt'
    file_regression.check(obtained_cmake_list_src.read_text(), basename='generate_src_CMakeLists', extension='.txt')

    obtained_compile_script = datadir / 'test_generate_plugin_template/acme/compile.py'
    file_regression.check(obtained_compile_script.read_text(), basename='generate_compile', extension='.py')
Esempio n. 7
0
def _package_plugins(ctx):
    """
    This functions can be just called when the generate_project_files and compile tasks have been already invoked
    """
    print("\n\n-- Creating Zip Files \n")

    project_dir = Path(__file__).parent
    plugins_projects = [x for x in (project_dir / "build/build_directory_for_tests/").iterdir() if x.is_dir()]
    artifacts_dir = project_dir / 'build/artifacts'

    plugins_zip = project_dir / 'build/plugin_zip'
    if plugins_zip.exists():
        shutil.rmtree(plugins_zip)

    plugins_zip.mkdir()

    for project in plugins_projects:
        plugins_dirs = [x for x in (project / 'plugin').iterdir() if x.is_dir() and (x / 'assets').exists()]
        hm_generator = HookManGenerator(hook_spec_file_path=project_dir / f"tests/plugins/{project.name}/hook_specs.py")

        for plugin in plugins_dirs:
            (plugin / 'artifacts').mkdir()
            if sys.platform == 'win32':
                shutil.copy2(src=artifacts_dir / f'{plugin.name}.dll', dst=plugin / 'artifacts')
            else:
                shutil.copy2(src=artifacts_dir / f'lib{plugin.name}.so', dst=plugin / 'artifacts')

            hm_generator.generate_plugin_package(
                package_name=plugin.name,
                plugin_dir=plugin,
                dst_path=plugins_zip
            )
Esempio n. 8
0
def package_plugin(specs_path: str, package_name: str, plugin_dir: str,
                   dst_path: Path):
    """Packages a plugin for distribution."""
    hm_generator = HookManGenerator(hook_spec_file_path=specs_path)
    hm_generator.generate_plugin_package(package_name=package_name,
                                         plugin_dir=plugin_dir,
                                         dst_path=Path(dst_path))
    return 0
def test_hook_man_generator_no_pyd(datadir, file_regression):
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / "hook_specs_no_pyd.py"))
    hg.generate_project_files(dst_path=datadir)

    obtained_hook_caller_file = datadir / "cpp" / "HookCaller.hpp"
    file_regression.check(
        obtained_hook_caller_file.read_text(), basename="HookCallerNoPyd", extension=".hpp"
    )
    assert not (datadir / "binding").is_dir()
Esempio n. 10
0
def template(dst, caption, plugin_id, author_name, author_email):
    r"""
    Generate a template with the necessary files and structure to create a plugin.

    The template folder will be placed on the ``dst`` option, that by default is the current directory from where the command
    was invoked.

    The files generated and their contents are ready to be used or customized and have the following structure:

    .. code-block:: bash

        \---myplugin
        |   CMakeLists.txt
        |   compile.py
        |
        +---assets
        |       plugin.yaml
        |       README.md
        |
        \---src
            |   CMakeLists.txt
            |   hook_specs.h
            |   myplugin.cpp
            |
            \---python
                    myplugin.py

    """
    dst = Path(dst)
    hook_specs_file_path = _get_hook_specs_file_path()
    hm = HookManGenerator(hook_spec_file_path=hook_specs_file_path)
    alfasim_sdk_include = ["<alfasim_sdk_api/alfasim_sdk.h>"]
    default_impls_for_hooks = [
        "HOOK_INITIALIZE(ctx){",
        "    return 0;",
        "}",
        "HOOK_FINALIZE(ctx){",
        "    return 0;",
        "}",
    ]

    hm.generate_plugin_template(
        caption,
        plugin_id,
        author_email,
        author_name,
        dst,
        extra_includes=alfasim_sdk_include,
        extra_body_lines=default_impls_for_hooks,
        exclude_hooks=["HOOK_FINALIZE", "HOOK_INITIALIZE"],
    )

    source_folder = dst / plugin_id / "src"
    python_folder = source_folder / "python"
    python_folder.mkdir()
    Path(python_folder / f"{plugin_id}.py").touch()
Esempio n. 11
0
def generate_plugin_template(specs_path: str, plugin_name: str,
                             shared_lib_name: str, author_email: str,
                             author_name: str, dst_path: Path):
    """Generate a plugin starting template."""
    hm_generator = HookManGenerator(hook_spec_file_path=specs_path)
    hm_generator.generate_plugin_template(plugin_name=plugin_name,
                                          shared_lib_name=shared_lib_name,
                                          author_email=author_email,
                                          author_name=author_name,
                                          dst_path=Path(dst_path))
    return 0
Esempio n. 12
0
def generate_hook_specs_h(specs_path: str, plugin_id: str, dst_path: Path):
    """
    Generates or update the hook_specs.h header file.

    SPECS_PATH   Path to where the hook_specs.py file is located.
    PLUGIN_ID    A unique string to identify the plugin.
    """
    hm_generator = HookManGenerator(hook_spec_file_path=specs_path)
    hm_generator.generate_hook_specs_header(plugin_id=plugin_id,
                                            dst_path=Path(dst_path))
    return 0
Esempio n. 13
0
def test_generate_plugin_package_invalid_shared_lib_name(acme_hook_specs_file, tmpdir):
    hg = HookManGenerator(hook_spec_file_path=acme_hook_specs_file)

    from hookman.exceptions import HookmanError
    with pytest.raises(HookmanError):
        hg.generate_plugin_template(
            caption='acme',
            plugin_id='acm#e',
            author_email='acme1',
            author_name='acme2',
            dst_path=Path(tmpdir)
        )

    with pytest.raises(HookmanError):
        hg.generate_plugin_template(
            caption='acme',
            plugin_id='acm e',
            author_email='acme1',
            author_name='acme2',
            dst_path=Path(tmpdir)
        )

    with pytest.raises(HookmanError):
        hg.generate_plugin_template(
            caption='1acme',
            plugin_id='acm e',
            author_email='acme1',
            author_name='acme2',
            dst_path=Path(tmpdir)
        )
Esempio n. 14
0
def test_generate_plugin_template_source_content_with_extra_includes (datadir, file_regression):
    plugin_dir = datadir / 'test_generate_plugin_template_with_extra_include'
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / 'hook_specs.py'))

    hg.generate_plugin_template(
        caption='Acme',
        plugin_id='acme',
        author_name='FOO',
        author_email='*****@*****.**',
        dst_path=plugin_dir,
        extra_includes=['<my_sdk/sdk.h>'],
    )

    obtained_plugin_file = datadir / 'test_generate_plugin_template_with_extra_include/acme/src/acme.cpp'
    file_regression.check(obtained_plugin_file.read_text(), basename='plugin_file_with_extra_includes', extension='.cpp')
Esempio n. 15
0
def package_plugin(specs_path: str, package_name: str, plugin_dir: str,
                   dst_path: Path):
    """
    Creates a PACKAGE_NAME for distribution on the current directory from the given PLUGIN_DIR for the project.

    If --dst-path is not provide, the PACKAGE_NAME will be created inside the PLUGIN_DIR folder.

    SPECS_PATH    Path to where the hook_specs.py file is located.
    PACKAGE_NAME  The name of the generated package
    PLUGIN_DIR    Path to the plugin directory, where configuration and the shared library is located.
    """
    hm_generator = HookManGenerator(hook_spec_file_path=specs_path)
    hm_generator.generate_plugin_package(package_name=package_name,
                                         plugin_dir=plugin_dir,
                                         dst_path=Path(dst_path))
    return 0
def test_generate_plugin_template(datadir, file_regression):
    plugin_dir = datadir / "test_generate_plugin_template"
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / "hook_specs.py"))

    hg.generate_plugin_template(
        caption="Acme",
        plugin_id="acme",
        author_name="FOO",
        author_email="*****@*****.**",
        dst_path=plugin_dir,
    )

    obtained_hook_specs_file = datadir / "test_generate_plugin_template/acme/src/hook_specs.h"
    file_regression.check(
        obtained_hook_specs_file.read_text(), basename="generate_hook_specs", extension=".h"
    )

    obtained_plugin_yaml = datadir / "test_generate_plugin_template/acme/assets/plugin.yaml"
    file_regression.check(
        obtained_plugin_yaml.read_text(), basename="generate_plugin", extension=".yaml"
    )

    obtained_plugin_file = datadir / "test_generate_plugin_template/acme/src/acme.cpp"
    file_regression.check(
        obtained_plugin_file.read_text(), basename="generate_plugin", extension=".cpp"
    )

    obtained_readme = datadir / "test_generate_plugin_template/acme/assets/README.md"
    file_regression.check(obtained_readme.read_text(), basename="generate_README", extension=".md")

    obtained_cmake_list = datadir / "test_generate_plugin_template/acme/CMakeLists.txt"
    file_regression.check(
        obtained_cmake_list.read_text(), basename="generate_CMakeLists", extension=".txt"
    )

    obtained_cmake_list_src = datadir / "test_generate_plugin_template/acme/src/CMakeLists.txt"
    file_regression.check(
        obtained_cmake_list_src.read_text(), basename="generate_src_CMakeLists", extension=".txt"
    )

    obtained_compile_script = datadir / "test_generate_plugin_template/acme/compile.py"
    file_regression.check(
        obtained_compile_script.read_text(), basename="generate_compile", extension=".py"
    )
Esempio n. 17
0
def test_generate_hook_specs_header(datadir, file_regression):
    plugin_dir = datadir / 'my-plugin'

    hg = HookManGenerator(hook_spec_file_path=Path(datadir / 'hook_specs.py'))
    hg.generate_hook_specs_header(plugin_id='acme', dst_path=plugin_dir)

    obtained_hook_specs_file = plugin_dir / 'acme/src/hook_specs.h'
    file_regression.check(obtained_hook_specs_file.read_text(), basename='generate_hook_specs_header1', extension='.h')

    hg = HookManGenerator(hook_spec_file_path=Path(datadir / 'hook_specs_2.py'))
    hg.generate_hook_specs_header(plugin_id='acme', dst_path=plugin_dir)
    file_regression.check(obtained_hook_specs_file.read_text(), basename='generate_hook_specs_header2', extension='.h')
Esempio n. 18
0
def generate_project_files(specs_path, dst_path):
    """
    Generate hooks_pecs.h, HookCaller c++ class and bindings.

    This task will invoke a code generation to produce the following files:
        - hook_specs.h - `File to be used by the plugin implementation`
        - HookCaller.hpp - `File to be passed to the application`
        - HookCallerPython.cpp - `Bindings for the function available on the plugin implementation`

    In order to call this command is necessary to inform the hook_specs.py file that has the
    specifications of the hooks available, and the destination path, (where the files will be created).

    Per default dst-path is the same directory that the command is called.

    Example:
    > hookman /<some_dir>/hook_specs.py --dst-path=/home/<some_other_path>
    """
    hm_generator = HookManGenerator(hook_spec_file_path=specs_path)
    hm_generator.generate_project_files(Path(dst_path))
    return 0
Esempio n. 19
0
def test_generate_plugin_template(datadir):
    plugin_dir = datadir / 'test_generate_plugin_template'
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / 'hook_specs.py'))

    hg.generate_plugin_template(plugin_name='Acme',
                                shared_lib_name='acme',
                                author_name='FOO',
                                author_email='*****@*****.**',
                                dst_path=plugin_dir)

    obtained_hook_specs_file = datadir / 'test_generate_plugin_template/acme/src/hook_specs.h'
    expected_hook_specs_file = datadir / 'test_generate_plugin_template/expected_hook_specs.h'

    obtained_plugin_yaml = datadir / 'test_generate_plugin_template/acme/assets/plugin.yaml'
    expected_plugin_yaml = datadir / 'test_generate_plugin_template/expected_plugin.yaml'

    obtained_plugin_c = datadir / 'test_generate_plugin_template/acme/src/plugin.c'
    expected_plugin_c = datadir / 'test_generate_plugin_template/expected_plugin.c'

    obtained_readme = datadir / 'test_generate_plugin_template/acme/assets/README.md'
    expected_readme = datadir / 'test_generate_plugin_template/expected_readme.md'

    obtained_cmake_list = datadir / 'test_generate_plugin_template/acme/CMakeLists.txt'
    expected_cmake_list = datadir / 'test_generate_plugin_template/expected_cmakelists.txt'

    obtained_cmake_list_src = datadir / 'test_generate_plugin_template/acme/src/CMakeLists.txt'
    expected_cmake_list_src = datadir / 'test_generate_plugin_template/expected_cmakelists_src.txt'

    obtained_compile_script = datadir / 'test_generate_plugin_template/acme/compile.py'
    expected_compile_script = datadir / 'test_generate_plugin_template/expected_compile.py'

    assert obtained_hook_specs_file.read_text(
    ) == expected_hook_specs_file.read_text()
    assert obtained_plugin_yaml.read_text() == expected_plugin_yaml.read_text()
    assert obtained_plugin_c.read_text() == expected_plugin_c.read_text()
    assert obtained_readme.read_text() == expected_readme.read_text()
    assert obtained_cmake_list.read_text() == expected_cmake_list.read_text()
    assert obtained_compile_script.read_text(
    ) == expected_compile_script.read_text()
    assert obtained_cmake_list_src.read_text(
    ) == expected_cmake_list_src.read_text()
def test_generate_plugin_template_source_content_with_extra_includes(datadir, file_regression):
    plugin_dir = datadir / "test_generate_plugin_template_with_extra_include"
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / "hook_specs.py"))

    hg.generate_plugin_template(
        caption="Acme",
        plugin_id="acme",
        author_name="FOO",
        author_email="*****@*****.**",
        dst_path=plugin_dir,
        extra_includes=["<my_sdk/sdk.h>"],
    )

    obtained_plugin_file = (
        datadir / "test_generate_plugin_template_with_extra_include/acme/src/acme.cpp"
    )
    file_regression.check(
        obtained_plugin_file.read_text(),
        basename="plugin_file_with_extra_includes",
        extension=".cpp",
    )
Esempio n. 21
0
def package_only(ctx, plugin_dir, package_name, dst):
    """
    Generate a ``<package_name>.hmplugin`` file with all the content from the directory assets and artifacts.

    By default, the package will be created inside the folder plugin_dir, however, it's possible
    to give another path filling the dst argument.
    """
    plugin_dir = Path(plugin_dir)
    dst = Path(dst)
    hook_specs_file_path = _get_hook_specs_file_path()
    hm = HookManGenerator(hook_spec_file_path=hook_specs_file_path)
    from alfasim_sdk._internal.constants import EXTRAS_REQUIRED_VERSION_KEY
    from alfasim_sdk._internal.alfasim_sdk_utils import (
        get_extras_default_required_version, )

    extras_defaults = {
        EXTRAS_REQUIRED_VERSION_KEY: get_extras_default_required_version()
    }
    hm.generate_plugin_package(package_name,
                               plugin_dir,
                               dst,
                               extras_defaults=extras_defaults)
def test_generate_plugin_template_source_wrong_arguments(datadir):
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / "hook_specs.py"))

    with pytest.raises(ValueError, match="extra_includes parameter must be a list, got int"):
        hg._validate_parameter("extra_includes", 1)

    with pytest.raises(ValueError, match="All elements of extra_includes must be a string"):
        hg._validate_parameter("extra_includes", ["xx", 1])
Esempio n. 23
0
def test_generate_plugin_template_source_wrong_arguments(datadir):
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / 'hook_specs.py'))

    with pytest.raises(ValueError, match='extra_includes parameter must be a list, got int'):
        hg._validate_parameter('extra_includes', 1)

    with pytest.raises(ValueError, match='All elements of extra_includes must be a string'):
        hg._validate_parameter('extra_includes', ['xx', 1])
Esempio n. 24
0
def test_generate_plugin_template_source_content_with_default_impls(datadir, file_regression):
    plugin_dir = datadir / 'test_generate_plugin_template_source_content_with_default_impls'
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / 'hook_specs.py'))

    extra_body_lines = [
        'HOOK_FRICTION_FACTOR(v1, v2)',
        '{',
        '    return 0;',
        '}',
    ]

    hg.generate_plugin_template(
        caption='Acme',
        plugin_id='acme',
        author_name='FOO',
        author_email='*****@*****.**',
        dst_path=plugin_dir,
        extra_body_lines=extra_body_lines,
        exclude_hooks=['HOOK_FRICTION_FACTOR']
    )

    obtained_plugin_file = datadir / 'test_generate_plugin_template_source_content_with_default_impls/acme/src/acme.cpp'
    file_regression.check(obtained_plugin_file.read_text(), basename='plugin_file_with_default_impl', extension='.cpp')
def test_generate_plugin_template_source_content_with_default_impls(datadir, file_regression):
    plugin_dir = datadir / "test_generate_plugin_template_source_content_with_default_impls"
    hg = HookManGenerator(hook_spec_file_path=Path(datadir / "hook_specs.py"))

    extra_body_lines = ["HOOK_FRICTION_FACTOR(v1, v2)", "{", "    return 0;", "}"]

    hg.generate_plugin_template(
        caption="Acme",
        plugin_id="acme",
        author_name="FOO",
        author_email="*****@*****.**",
        dst_path=plugin_dir,
        extra_body_lines=extra_body_lines,
        exclude_hooks=["HOOK_FRICTION_FACTOR"],
    )

    obtained_plugin_file = (
        datadir
        / "test_generate_plugin_template_source_content_with_default_impls/acme/src/acme.cpp"
    )
    file_regression.check(
        obtained_plugin_file.read_text(), basename="plugin_file_with_default_impl", extension=".cpp"
    )
def test_generate_hook_specs_header(datadir, file_regression):
    plugin_dir = datadir / "my-plugin"

    hg = HookManGenerator(hook_spec_file_path=Path(datadir / "hook_specs.py"))
    hg.generate_hook_specs_header(plugin_id="acme", dst_path=plugin_dir)

    obtained_hook_specs_file = plugin_dir / "acme/src/hook_specs.h"
    file_regression.check(
        obtained_hook_specs_file.read_text(), basename="generate_hook_specs_header1", extension=".h"
    )

    hg = HookManGenerator(hook_spec_file_path=Path(datadir / "hook_specs_2.py"))
    hg.generate_hook_specs_header(plugin_id="acme", dst_path=plugin_dir)
    file_regression.check(
        obtained_hook_specs_file.read_text(), basename="generate_hook_specs_header2", extension=".h"
    )
Esempio n. 27
0
def test_generate_plugin_package_invalid_version(acme_hook_specs_file, tmp_path, mocker, mock_plugin_id_from_dll):
    hg = HookManGenerator(hook_spec_file_path=acme_hook_specs_file)
    plugin_id = 'acme'
    hg.generate_plugin_template(plugin_id, plugin_id, 'acme1', 'acme2', tmp_path)

    plugin_yaml = tmp_path / 'acme/assets/plugin.yaml'
    new_content = plugin_yaml.read_text().replace("version: '1.0.0'", "version: '1'")
    plugin_yaml.write_text(new_content)

    mocker.patch('hookman.hookman_generator.HookManGenerator._validate_package_folder', return_value=None)

    with pytest.raises(ValueError, match="Version attribute does not follow semantic version, got '1'"):
        hg.generate_plugin_package(plugin_id, plugin_dir=tmp_path / plugin_id)
Esempio n. 28
0
def test_hook_man_generator(datadir, file_regression):
    # Pass a folder
    with pytest.raises(FileNotFoundError, match=f"File not found: *"):
        HookManGenerator(hook_spec_file_path=datadir)

    # Pass a invalid hook_spec_file (without specs)
    Path(datadir / 'invalid_spec.py').touch()
    with pytest.raises(RuntimeError, match="Invalid file, specs not defined."):
        HookManGenerator(hook_spec_file_path=Path(datadir / 'invalid_spec.py'))

    hg = HookManGenerator(hook_spec_file_path=Path(datadir / 'hook_specs.py'))
    hg.generate_project_files(dst_path=datadir)

    file_regression.check((datadir / 'cpp' / 'HookCaller.hpp').read_text(), basename='HookCaller', extension='.hpp')
    file_regression.check((datadir / 'binding' / 'HookCallerPython.cpp').read_text(), basename='HookCallerPython', extension='.cpp')
Esempio n. 29
0
def test_generate_plugin_package(acme_hook_specs_file, tmpdir, mock_plugin_id_from_dll):
    hg = HookManGenerator(hook_spec_file_path=acme_hook_specs_file)
    plugin_id = 'acme'
    hg.generate_plugin_template(
        caption='acme',
        plugin_id='acme',
        author_email='acme1',
        author_name='acme2',
        dst_path=Path(tmpdir)
    )
    plugin_dir = Path(tmpdir) / 'acme'

    artifacts_dir = plugin_dir / 'artifacts'
    artifacts_dir.mkdir()
    import sys

    shared_lib_name = f"{plugin_id}.dll" if sys.platform == 'win32' else f"lib{plugin_id}.so"
    shared_lib_path = artifacts_dir / shared_lib_name
    shared_lib_path.write_text('')

    hg.generate_plugin_package(
        package_name='acme',
        plugin_dir=plugin_dir,
    )

    from hookman.plugin_config import PluginInfo
    version = PluginInfo(Path(tmpdir / 'acme/assets/plugin.yaml'), None).version

    win_plugin_name = f"{plugin_id}-{version}-win64.hmplugin"
    linux_plugin_name = f"{plugin_id}-{version}-linux64.hmplugin"
    hm_plugin_name = win_plugin_name if sys.platform == 'win32' else linux_plugin_name

    compressed_plugin = plugin_dir / hm_plugin_name
    assert compressed_plugin.exists()

    from zipfile import ZipFile
    plugin_file_zip = ZipFile(compressed_plugin)
    list_of_files = [file.filename for file in plugin_file_zip.filelist]

    assert 'assets/plugin.yaml' in list_of_files
    assert 'assets/README.md' in list_of_files
    assert f'artifacts/{shared_lib_name}' in list_of_files
Esempio n. 30
0
def test_generate_plugin_package(acme_hook_specs_file, tmpdir):
    hg = HookManGenerator(hook_spec_file_path=acme_hook_specs_file)

    hg.generate_plugin_template(plugin_name='acme',
                                shared_lib_name='acme',
                                author_email='acme1',
                                author_name='acme2',
                                dst_path=Path(tmpdir))
    plugin_dir = Path(tmpdir) / 'acme'

    artifacts_dir = plugin_dir / 'artifacts'
    artifacts_dir.mkdir()
    import sys

    if sys.platform == 'win32':
        shared_lib_name = 'acme.dll'
        hm_plugin_name = 'acme-win64.hmplugin'
    else:
        shared_lib_name = 'libacme.so'
        hm_plugin_name = 'acme-linux64.hmplugin'

    test_dll = artifacts_dir / shared_lib_name
    test_dll.write_text('')

    hg.generate_plugin_package(
        package_name='acme',
        plugin_dir=plugin_dir,
    )

    compressed_plugin = plugin_dir / hm_plugin_name
    assert compressed_plugin.exists()

    from zipfile import ZipFile
    plugin_file_zip = ZipFile(compressed_plugin)
    list_of_files = [file.filename for file in plugin_file_zip.filelist]

    assert 'assets/plugin.yaml' in list_of_files
    assert 'assets/README.md' in list_of_files
    assert f'artifacts/{shared_lib_name}' in list_of_files