Loaders¶
Module: polygraphy.backend.common
- class BytesFromPath(path)[source]¶
Bases:
BaseLoaderFunctor that can load a file in binary mode (‘rb’).
Loads a file in binary mode (‘rb’).
- Parameters:
path (str) – The file path.
- __call__(*args, **kwargs)¶
Invokes the loader by forwarding arguments to
call_impl.Note:
call_implshould not be called directly - use this function instead.
- bytes_from_path(path)¶
Immediately evaluated functional variant of
BytesFromPath.Loads a file in binary mode (‘rb’).
- Parameters:
path (str) – The file path.
- Returns:
The contents of the file.
- Return type:
bytes
- class SaveBytes(obj, path)[source]¶
Bases:
BaseLoaderFunctor that can save bytes to a file.
Saves bytes to a file.
- Parameters:
obj (Union[bytes, Callable() -> bytes]) – The bytes to save or a callable that returns them.
path (str) – The file path.
- __call__(*args, **kwargs)¶
Invokes the loader by forwarding arguments to
call_impl.Note:
call_implshould not be called directly - use this function instead.
- save_bytes(obj, path)¶
Immediately evaluated functional variant of
SaveBytes.Saves bytes to a file.
- Parameters:
obj (Union[bytes, Callable() -> bytes]) – The bytes to save or a callable that returns them.
path (str) – The file path.
- Returns:
The bytes saved.
- Return type:
bytes
- class InvokeFromScript(path, name)[source]¶
Bases:
BaseLoaderFunctor that invokes a function (or functor) from a Python script.
Invokes the specified function from the specified Python script.
The imported symbol is instantiated with no arguments if it is a class, so it may be a plain function, a functor instance, or a functor class (e.g. a
BaseCompareFuncsubclass). Calling this functor invokes the loaded object, and attribute access is forwarded to it (so, for example, a loadedBaseCompareFuncexposes itsthresholds_formethod).If you intend to use the imported object more than once, you should import it using
polygraphy.mod.import_from_scriptinstead, since it is re-imported on each use here.- Parameters:
path (str) – The path to the Python script. The path must include a ‘.py’ extension.
name (str) – The name of the function (or functor) to import and invoke.
- call_impl(*args, **kwargs)[source]¶
- Returns:
The return value of the imported function (or functor).
- Return type:
object
- __call__(*args, **kwargs)¶
Invokes the loader by forwarding arguments to
call_impl.Note:
call_implshould not be called directly - use this function instead.
- invoke_from_script(path, name, *args, **kwargs)¶
Immediately evaluated functional variant of
InvokeFromScript.Invokes the specified function from the specified Python script.
The imported symbol is instantiated with no arguments if it is a class, so it may be a plain function, a functor instance, or a functor class (e.g. a
BaseCompareFuncsubclass). Calling this functor invokes the loaded object, and attribute access is forwarded to it (so, for example, a loadedBaseCompareFuncexposes itsthresholds_formethod).If you intend to use the imported object more than once, you should import it using
polygraphy.mod.import_from_scriptinstead, since it is re-imported on each use here.- Parameters:
path (str) – The path to the Python script. The path must include a ‘.py’ extension.
name (str) – The name of the function (or functor) to import and invoke.
- Returns:
The return value of the imported function (or functor).
- Return type:
object