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()
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))
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()
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')
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
def test_hook_man_generator(datadir): # 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) obtained_hook_caller_file = datadir / 'cpp' / 'HookCaller.hpp' expected_hook_caller_file = datadir / 'ExpectedHookCaller.hpp' obtained_hook_caller_python_file = datadir / 'binding' / 'HookCallerPython.cpp' expected_hook_caller_python_file = datadir / 'ExpectedHookCallerPython.cpp' assert obtained_hook_caller_file.read_text( ) == expected_hook_caller_file.read_text() assert obtained_hook_caller_python_file.read_text( ) == expected_hook_caller_python_file.read_text()