-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Faster Python imports with prepackaged algo metadata
Instead of using an environmental variable ESSENTIA_PYTHON_NODOC, prepare the metadata at the build stage. Load on import.
- Loading branch information
Showing
4 changed files
with
87 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from json import dump | ||
from os.path import join | ||
import essentia | ||
from ._essentia import Algorithm, StreamingAlgorithm, keys, skeys | ||
|
||
|
||
def _metadata_standard(): | ||
meta = {} | ||
for name in keys(): | ||
essentia.log.debug(essentia.EPython, 'Loading __doc__ and __struct__ metadata for essentia.standard class: %s' % name) | ||
_algoInstance = Algorithm(name) | ||
meta[name] = {} | ||
meta[name]['__doc__'] = _algoInstance.getDoc() | ||
meta[name]['__struct__'] = _algoInstance.getStruct() | ||
del _algoInstance | ||
return meta | ||
|
||
|
||
def _metadata_streaming(): | ||
meta = {} | ||
for name in skeys(): | ||
essentia.log.debug(essentia.EPython, 'Loading __doc__ and __struct__ metadata for essentia.streaming class: %s' % name) | ||
_algoInstance = StreamingAlgorithm(name) | ||
meta[name] = {} | ||
meta[name]['__doc__'] = _algoInstance.getDoc() | ||
meta[name]['__struct__'] = _algoInstance.getStruct() | ||
del _algoInstance | ||
return meta | ||
|
||
|
||
def _extract_metadata(filedir): | ||
""" Loads algorithms' metadata (__doc__ and __struct__) from the C extension | ||
and stores it to files in a filedir""" | ||
dump(_metadata_standard(), open(join(filedir, 'standard.meta.json'), 'w')) | ||
dump(_metadata_streaming(), open(join(filedir, 'streaming.meta.json'), 'w')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters