Add the mvt.plugin import surface

mvt.plugin re-exports the names a plugin needs from MVT under one import
path. It holds the module base classes and Command, the alert and result
types, the database errors a module raises, the timestamp converters, the
plugin settings API, MVT's settings, get_plugin_logger() and MVT_VERSION.

The names it exports are kept working on a best-effort basis. Changes to
them are announced in the release notes. Anything else in mvt can still be
imported, and may change between releases without notice.

get_plugin_logger(__name__) returns a logger under mvt.ext for plugin code
outside a module class. Its records then reach the console and the
command.log file of a run. A file loaded with --load-module or
--load-command is named after the file.
This commit is contained in:
Donncha Ó Cearbhaill
2026-08-26 21:41:49 +02:00
parent 1b163749b2
commit da33c2fdb3
6 changed files with 195 additions and 12 deletions
+34
View File
@@ -0,0 +1,34 @@
# Mobile Verification Toolkit (MVT)
# Copyright (c) 2021-2026 The MVT Authors.
# Use of this software is governed by the MVT License 1.1 that can be found at
# https://license.mvt.re/1.1/
import mvt.plugin
from mvt.android.modules.backup.base import BackupModule
from mvt.common.config import settings
from ..plugin_fixtures import run_isolated_python
def test_the_exported_names_are_the_public_names():
public = {name for name in vars(mvt.plugin) if not name.startswith("_")}
assert public == set(mvt.plugin.__all__)
assert mvt.plugin.settings is settings
assert mvt.plugin.AndroidBackupModule is BackupModule
def test_the_surface_imports_before_anything_else_of_mvt(tmp_path):
# A plugin can import the surface as its first import of MVT. The
# subprocess gets a temporary home because importing MVT writes its
# configuration file.
result = run_isolated_python(
"from mvt.plugin import IOSExtraction, MVT_VERSION, settings\n"
"assert MVT_VERSION\n"
"assert settings.NETWORK_TIMEOUT > 0\n"
"assert IOSExtraction.__name__ == 'IOSExtraction'\n",
home=tmp_path,
)
assert result.returncode == 0, result.stderr
assert result.stderr == ""