pyaud¶
Framework for writing Python package audits.
-
pyaud.pyaud(module: str, audit: list[str] | None =
None, exclude: str | None =None, fix: bool =False, no_cache: bool =False) int[source]¶ Module entry point.
Parse commandline arguments and run the selected choice from the dictionary of functions which matches the key.
pyaud.exceptions¶
Exceptions for use within the module.
All exceptions made public for if they need to be reraised or excepted.
Exceptions are already built into the architecture but can be used in new plugins as well.
- exception pyaud.exceptions.NameConflictError(plugin: str, name: str)[source]¶
Bases:
ExceptionRaise if adding plugin whose name is not unique.
pyaud.messages¶
pyaud.plugins¶
Main module used for public API.
- class pyaud.plugins.Action(name: str)[source]¶
Bases:
PluginBlueprint for writing generic plugins.
Called within context of defined environment variables. If no environment variables are defined nothing will change.
- class pyaud.plugins.Audit(name: str)[source]¶
Bases:
PluginBlueprint for writing audit-only plugins.
Audit will be called from here.
Run within context of defined environment variables. If no environment variables are defined nothing will change.
- Raises:¶
CalledProcessError – Will always be raised if something fails that is not to do with the audit condition. Will be excepted and reraised as
AuditErrorif the audit fails.AuditError – Raised from
CalledProcessErrorif audit fails.
- Returns:¶
If any error has not been raised for any reason int object must be returned, from subprocess or written, to notify call whether process has succeeded or failed. No value will actually return from __call__ as it will be passed to the decorator.
- class pyaud.plugins.BaseFix(name: str)[source]¶
Bases:
AuditBlueprint for writing audit and fix plugins.
Audit will be called from here.
Called within context of defined environment variables. If no environment variables are defined nothing will change.
If audit fails and the
-f/--fixflag is passed to the commandline thefixmethod will be called within theCalledProcessErrortry-except block.If
-f/--fixand the audit fails the user is running the audit only and will raise anAuditError.- Raises:¶
CalledProcessError – Will always be raised if something fails that is not to do with the audit condition. Will be excepted and reraised as
AuditErrorif the audit fails and-f/--fixis not passed to the commandline.AuditError – Raised from
CalledProcessErrorif audit fails and-f/--fixflag if not passed to the commandline.
- Returns:¶
If any error has not been raised for any reason int object must be returned, from subprocess or written, to notify call whether process has succeeded or failed. No value will actually return from __call__ as it will be passed to the decorator.
- abstract audit(*args: str, **kwargs: Any) int[source]¶
All audit logic to be written within this method.
- Parameters:¶
- Returns:¶
If any error has not been raised for any reason int object must be returned, from subprocess or written, to notify __call__ whether process has succeeded or failed. If non-zero exist is returned and
-f/--fixhas been passed to the commandline run thefixmethod, otherwise raiseAuditError.
- class pyaud.plugins.BasePlugin[source]¶
Bases:
ABCBase type for all plugins.
-
cache =
False¶ If set to True then indexed files will be monitored for change.
-
cache_all =
False¶ Only matters if
cacheis set to True. If False (default) then audit will cache on a file-by-file basis. If True, then no changes can be made to any file for a cache-hit to be valid.
-
cache_file : str | _Path | None =
None¶ set a single cache file for plugin subclass.
-
cache =
- class pyaud.plugins.Fix(name: str)[source]¶
Bases:
BaseFixBlueprint for writing audit and fix plugins for single files.
Announce file status.
- Raises:¶
CalledProcessError – Will always be raised if something fails that is not to do with the audit condition. Will be excepted and reraised as
AuditErrorif the audit fails and-f/--fixis not passed to the commandline.AuditError – Raised from
CalledProcessErrorif audit fails and-f/--fixflag if not passed to the commandline.
- Returns:¶
If any error has not been raised for any reason int object must be returned, from subprocess or written, to notify call whether process has succeeded or failed. No value will actually return from __call__ as it will be passed to the decorator.
- abstract audit(*args: str, **kwargs: Any) int[source]¶
All audit logic to be written within this method.
- Parameters:¶
- Returns:¶
If any error has not been raised for any reason int object must be returned, from subprocess or written, to notify __call__ whether process has succeeded or failed. If non-zero exist is returned and
-f/--fixhas been passed to the commandline run thefixmethod, otherwise raiseAuditError.
- class pyaud.plugins.FixAll(name: str)[source]¶
Bases:
BaseFixBlueprint for writing audit and fix plugins for Python files.
Announce Python file status.
- Raises:¶
CalledProcessError – Will always be raised if something fails that is not to do with the audit condition. Will be excepted and reraised as
AuditErrorif the audit fails and-f/--fixis not passed to the commandline.AuditError – Raised from
CalledProcessErrorif audit fails and-f/--fixflag if not passed to the commandline.
- Returns:¶
If any error has not been raised for any reason int object must be returned, from subprocess or written, to notify call whether process has succeeded or failed. No value will actually return from __call__ as it will be passed to the decorator.
- abstract audit(*args: str, **kwargs: Any) int[source]¶
All audit logic to be written within this method.
- Parameters:¶
- Returns:¶
If any error has not been raised for any reason int object must be returned, from subprocess or written, to notify __call__ whether process has succeeded or failed. If non-zero exist is returned and
-f/--fixhas been passed to the commandline run thefixmethod, otherwise raiseAuditError.
- class pyaud.plugins.Parametrize(name: str)[source]¶
Bases:
PluginDefine a list of strings to call multiple plugins.
- Raises:¶
CalledProcessError – Will always be raised if something fails that is not to do with the called plugin’s condition. Will be excepted and reraised as
AuditErrorif the called plugin fails and the called plugin does not specify afixmethod or the-f/--fixflag is not passed to the commandline.AuditError – Raised from
CalledProcessErrorif called plugin fails and nofixmethod is specified or the-f/--fixflag is not passed to the commandline.
- class pyaud.plugins.Plugin(name: str)[source]¶
Bases:
BasePluginBase class of all plugins.
Raises
TypeErrorif registered directly.Contains the name attribute assigned upon registration.
Subprocesses are stored in the
subprocessdict object- property name : str¶
Name of the plugin.
- class pyaud.plugins.Plugins[source]¶
Bases:
Dict[str,Plugin]Holds registered plugins.
Instantiate plugin on running __setitem__.
- Raises:¶
NameConflictError – If name of registered plugin is not unique.
TypeError – If non plugin type registered.
- pyaud.plugins.mapping() dict[str, Plugin][source]¶
Get dict of named keys and their corresponding plugin values.
- Returns:¶
Mapping of plugins and their unique names.