Merge pull request #2767 from reuben/readable_repr_bindings

Add a better __repr__ for Metadata objects in Python bindings
This commit is contained in:
Reuben Morais 2020-02-18 13:28:57 +01:00 committed by GitHub
commit 44ff4c54b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -46,6 +46,23 @@ import_array();
}
%}
%extend struct MetadataItem {
%pythoncode %{
def __repr__(self):
return 'MetadataItem(character=\'{}\', timestep={}, start_time={})'.format(self.character, self.timestep, self.start_time)
%}
}
%extend struct Metadata {
%pythoncode %{
def __repr__(self):
items_repr = ', \n'.join(' ' + repr(i) for i in self.items)
return 'Metadata(confidence={}, items=[\n{}\n])'.format(self.confidence, items_repr)
%}
}
%ignore Metadata::num_items;
%extend struct Metadata {
~Metadata() {
DS_FreeMetadata($self);

View File

@ -64,7 +64,7 @@ def main():
include_dirs=[numpy_include, '../'],
library_dirs=list(map(lambda x: x.strip(), lib_dirs_split(os.getenv('MODEL_LDFLAGS', '')))),
libraries=list(map(lambda x: x.strip(), libs_split(os.getenv('MODEL_LIBS', '')))),
swig_opts=['-c++', '-keyword', '-builtin'])
swig_opts=['-c++', '-keyword'])
setup(name=project_name,
description='A library for running inference on a DeepSpeech model',