8.5.1.5. pymodaq_utils.plugin_tools.rules module
Static rules to guide the development of a PyMoDAQ instrument plugin (pymodaq_plugins_*).
The rules read the source files of a plugin package (pyproject.toml, python modules): nothing is imported, so
they also work when the instrument SDK or other dependencies are not installed. Each rule produces
Finding objects with a stable code, a severity, a location and a hint about how to fix it.
Severities:
error: the plugin will not work or will not be seen by PyMoDAQwarning: deprecated or suspicious, should be fixedtodo: the plugin is not finished (leftover of the template: TODO comments, placeholders,NotImplementedError)
They are used by pymodaq_utils.plugin_tools.checks but can be called directly:
from pymodaq_utils.plugin_tools.rules import check_package_sources
for finding in check_package_sources('pymodaq_plugins_xxxx'):
print(finding)
Added in version 5.3.1.
- class pymodaq_utils.plugin_tools.rules.Finding(code, severity, message, hint='', path=None, line=None, column=None)[source]
Bases:
objectOne thing found by a rule
- Variables:
- Attributes:
- column
- line
- location
- path
Methods
format([color])Text of the finding, with colors for a terminal if
color
- class pymodaq_utils.plugin_tools.rules.Severity(*values)[source]
-
- ERROR = 'error'
- TODO = 'todo'
- WARNING = 'warning'
- pymodaq_utils.plugin_tools.rules.check_extension_source(path)[source]
Rules on a module of the
extensionsfolder of a plugin package, without importing itPMQ330:
EXTENSION_NAMEorCLASS_NAMEmissing in a module defining an extension: the Dashboard does not list itPMQ331:
CLASS_NAMEis not the name of a class of the modulePMQ332: the class does not derive from
CustomExt(CustomApphas no access to the Dashboard)PMQ333: import from a module of pymodaq that only remains as a deprecated shim
PMQ334: deprecated hooks
setup_docks/setup_menuPMQ335: the extension creates its own ExperimentManager or StateManager
PMQ336: the
__init__does not take theparentanddashboardarguments given by the DashboardPMQ337: the
__init__of a class deriving fromCustomExtnever callsself.setup_ui()PMQ338: a class deriving directly from
CustomExthas no_quit_funguard, or one that never returns TruePMQ339: the extension class overrides
quit_funinstead of_quit_fun
- pymodaq_utils.plugin_tools.rules.check_extensions(root)[source]
The rules on every module of the
extensionsfolder of the package
- pymodaq_utils.plugin_tools.rules.check_file_names(root)[source]
Python files whose name is not a valid module name: they cannot be imported and should not be shipped
- pymodaq_utils.plugin_tools.rules.check_leftovers(package, root, project=None)[source]
Template leftovers: TODO comments, placeholders,
NotImplementedError, example modules
- pymodaq_utils.plugin_tools.rules.check_os_classifiers(package_folder, project)[source]
PMQ320: the
Operating Systemclassifiers of the pyproject.toml do not match thesupported_platformsdeclared by the instrument plugins
- pymodaq_utils.plugin_tools.rules.check_package_sources(package)[source]
All the static rules on an installed (or editable) plugin package: packaging, leftovers and plugin classes
- pymodaq_utils.plugin_tools.rules.check_plugin_source(path, kind, class_name, static_fallback=False)[source]
Rules on the source of a plugin module, without importing it
- Parameters:
path (
Path) – the python filekind (
str) – ‘move’ or the dimensionality of a viewer (‘0D’, ‘1D’, ‘2D’, ‘ND’)class_name (
str) – name of the plugin class that is expected in the modulestatic_fallback (
bool) – if True also apply the rules that duplicate the checks done on the imported class (use it when the module cannot be imported because of a missing dependency)
- Return type:
- pymodaq_utils.plugin_tools.rules.check_pyproject(package, project)[source]
Rules on the
pyproject.tomland the layout of the project
- pymodaq_utils.plugin_tools.rules.check_python_code(root)[source]
Rules on all the python files of the package (plugins and hardware wrappers)
PMQ315: invalid escape sequence in a string (
"C:\Program Files"): a warning of python since 3.6, aSyntaxWarningsince 3.12, that will be an errorPMQ317: code that only works on Windows and is executed when the module is imported (
windll,winreg, path with a drive letter): the plugin cannot be imported, nor listed, on the other systems. Not reported in the modules that only the instruments declaringsupported_platforms = ('win32',)use
- pymodaq_utils.plugin_tools.rules.colorize(text, style, enabled=True)[source]
Wrap a text in the ANSI escape codes of a style (bold, dim, red, green, yellow, cyan) if enabled
- Return type:
- pymodaq_utils.plugin_tools.rules.is_valid_unit(unit)[source]
Whether a unit is known from pint (with the units of PyMoDAQ if pymodaq_data is installed)
- Return type:
- pymodaq_utils.plugin_tools.rules.package_root(package)[source]
Folder of the python package, found without importing it
- pymodaq_utils.plugin_tools.rules.project_root(package)[source]
Folder holding the pyproject.toml of the plugin: only exists for a source tree or an editable install
- pymodaq_utils.plugin_tools.rules.syntax_error_finding(code, path, error)[source]
Finding with the location (line and column) and the offending line of a syntax error
- Return type:
- pymodaq_utils.plugin_tools.rules.use_color(mode='auto', stream=None)[source]
Whether to color the output: mode is ‘always’, ‘never’ or ‘auto’
autocolors if the stream (stdout by default) is a terminal and the NO_COLOR environment variable is not set, or if FORCE_COLOR is set (see https://no-color.org).- Return type: