Markus Armbruster <arm...@redhat.com> writes: > Daniel P. Berrangé <berra...@redhat.com> writes: > >> The 'qapi.backend.QAPIBackend' class defines an API contract for code >> generators. The current generator is put into a new class >> 'qapi.backend.QAPICBackend' and made to be the default impl. >> >> A custom generator can be requested using the '-k' arg which takes a > > Missed an instance of -k. Can fix this myself. > >> fully qualified python class name >> >> qapi-gen.py -B the.python.module.QAPIMyBackend >> >> This allows out of tree code to use the QAPI generator infrastructure >> to create new language bindings for QAPI schemas. This has the caveat >> that the QAPI generator APIs are not guaranteed stable, so consumers >> of this feature may have to update their code to be compatible with >> future QEMU releases. >> >> Signed-off-by: Daniel P. Berrangé <berra...@redhat.com>
[...] >> diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py >> index 324081b9fc..8a8b1e0121 100644 >> --- a/scripts/qapi/main.py >> +++ b/scripts/qapi/main.py [...] >> @@ -29,32 +25,37 @@ def invalid_prefix_char(prefix: str) -> Optional[str]: >> return None >> >> >> -def generate(schema_file: str, >> - output_dir: str, >> - prefix: str, >> - unmask: bool = False, >> - builtins: bool = False, >> - gen_tracing: bool = False) -> None: >> - """ >> - Generate C code for the given schema into the target directory. >> +def create_backend(path: str) -> QAPIBackend: >> + if path is None: >> + return QAPICBackend() >> >> - :param schema_file: The primary QAPI schema file. >> - :param output_dir: The output directory to store generated code. >> - :param prefix: Optional C-code prefix for symbol names. >> - :param unmask: Expose non-ABI names through introspection? >> - :param builtins: Generate code for built-in types? >> + if "." not in path: >> + print(f"Missing qualified module path in '{path}'", file=sys.stderr) >> + sys.exit(1) >> >> - :raise QAPIError: On failures. >> - """ >> - assert invalid_prefix_char(prefix) is None >> + module_path, _, class_name = path.rpartition('.') > > I'd like to tweak this to > > module_path, dot, class_name = path.rpartition('.') > if not dot: > print(f"argument of -B must be of the form MODULE.CLASS", > file=sys.stderr) This bothers flake8: scripts/qapi/main.py:34:15: F541 f-string is missing placeholders I'll make it a plain string instead. > sys.exit(1) > [...]