mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Plugin list on Diagnostic (#1282)
* CLI: Unhide "diagnostic" commandline option * Display loaded plugins under "--diagnostic" rather than "--version" * Align plugin names on diagnostic * Store plugin module paths as variables * Don't display full plugin module paths for built in and "regular" contributed plugins * Make flake8 happy * Adjust new plugin imports
This commit is contained in:
parent
79c37401c4
commit
80a1eeff42
5 changed files with 80 additions and 33 deletions
|
@ -78,7 +78,7 @@ def parse_args(args=[]):
|
||||||
action="store_const",
|
action="store_const",
|
||||||
const=preconfig_diagnostic,
|
const=preconfig_diagnostic,
|
||||||
dest="preconfig_cmd",
|
dest="preconfig_cmd",
|
||||||
help=argparse.SUPPRESS,
|
help="Print active plugins",
|
||||||
)
|
)
|
||||||
standalone.add_argument(
|
standalone.add_argument(
|
||||||
"--list",
|
"--list",
|
||||||
|
|
|
@ -11,12 +11,30 @@ run.
|
||||||
Also, please note that all (non-builtin) imports should be scoped to each function to
|
Also, please note that all (non-builtin) imports should be scoped to each function to
|
||||||
avoid any possible overhead for these standalone commands.
|
avoid any possible overhead for these standalone commands.
|
||||||
"""
|
"""
|
||||||
|
from itertools import chain
|
||||||
import platform
|
import platform
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def remove_prefix(main_string, prefix):
|
||||||
|
# replace with built-in string function in Python 3.9+
|
||||||
|
pattern = rf"^{prefix}"
|
||||||
|
return re.sub(pattern, "", main_string)
|
||||||
|
|
||||||
|
|
||||||
def preconfig_diagnostic(_):
|
def preconfig_diagnostic(_):
|
||||||
from jrnl import __version__
|
from jrnl import __version__
|
||||||
|
from jrnl.plugins.collector import (
|
||||||
|
IMPORT_FORMATS,
|
||||||
|
EXPORT_FORMATS,
|
||||||
|
INTERNAL_EXPORTER_CLASS_PATH,
|
||||||
|
INTERNAL_IMPORTER_CLASS_PATH,
|
||||||
|
EXTERNAL_EXPORTER_CLASS_PATH,
|
||||||
|
EXTERNAL_IMPORTER_CLASS_PATH,
|
||||||
|
get_exporter,
|
||||||
|
get_importer,
|
||||||
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"jrnl: {__version__}\n"
|
f"jrnl: {__version__}\n"
|
||||||
|
@ -24,15 +42,54 @@ def preconfig_diagnostic(_):
|
||||||
f"OS: {platform.system()} {platform.release()}"
|
f"OS: {platform.system()} {platform.release()}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
plugin_name_length = max(
|
||||||
|
[len(str(x)) for x in chain(IMPORT_FORMATS, EXPORT_FORMATS)]
|
||||||
|
)
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("Active Plugins:")
|
||||||
|
print(" Importers:")
|
||||||
|
for importer in IMPORT_FORMATS:
|
||||||
|
importer_class = get_importer(importer)
|
||||||
|
print(f" {importer:{plugin_name_length}} : ", end="")
|
||||||
|
if importer_class().class_path().startswith(INTERNAL_IMPORTER_CLASS_PATH):
|
||||||
|
version_str = remove_prefix(
|
||||||
|
importer_class().class_path(), INTERNAL_IMPORTER_CLASS_PATH
|
||||||
|
)
|
||||||
|
version_str = remove_prefix(version_str, ".")
|
||||||
|
print(f"{version_str} (internal)")
|
||||||
|
elif importer_class().class_path().startswith(EXTERNAL_IMPORTER_CLASS_PATH):
|
||||||
|
version_str = remove_prefix(
|
||||||
|
importer_class().class_path(), EXTERNAL_IMPORTER_CLASS_PATH
|
||||||
|
)
|
||||||
|
version_str = remove_prefix(version_str, ".")
|
||||||
|
print(f"{version_str} {importer_class.version}")
|
||||||
|
else:
|
||||||
|
print(f"{importer_class.version} from ", end="")
|
||||||
|
print(f"{importer_class().class_path()}")
|
||||||
|
print(" Exporters:")
|
||||||
|
for exporter in EXPORT_FORMATS:
|
||||||
|
exporter_class = get_exporter(exporter)
|
||||||
|
print(f" {exporter:{plugin_name_length}} : ", end="")
|
||||||
|
if exporter_class().class_path().startswith(INTERNAL_EXPORTER_CLASS_PATH):
|
||||||
|
version_str = remove_prefix(
|
||||||
|
exporter_class().class_path(), INTERNAL_EXPORTER_CLASS_PATH
|
||||||
|
)
|
||||||
|
version_str = remove_prefix(version_str, ".")
|
||||||
|
print(f"{version_str} (internal)")
|
||||||
|
elif exporter_class().class_path().startswith(EXTERNAL_EXPORTER_CLASS_PATH):
|
||||||
|
version_str = remove_prefix(
|
||||||
|
exporter_class().class_path(), EXTERNAL_EXPORTER_CLASS_PATH
|
||||||
|
)
|
||||||
|
version_str = remove_prefix(version_str, ".")
|
||||||
|
print(f"{version_str} {exporter_class.version}")
|
||||||
|
else:
|
||||||
|
print(f"{exporter_class.version} from ", end="")
|
||||||
|
print(f"{exporter_class().class_path()}")
|
||||||
|
|
||||||
|
|
||||||
def preconfig_version(_):
|
def preconfig_version(_):
|
||||||
from jrnl import __version__
|
from jrnl import __version__
|
||||||
from jrnl.plugins.collector import (
|
|
||||||
IMPORT_FORMATS,
|
|
||||||
EXPORT_FORMATS,
|
|
||||||
get_exporter,
|
|
||||||
get_importer,
|
|
||||||
)
|
|
||||||
|
|
||||||
version_str = f"""jrnl version {__version__}
|
version_str = f"""jrnl version {__version__}
|
||||||
|
|
||||||
|
@ -42,22 +99,6 @@ This is free software, and you are welcome to redistribute it under certain
|
||||||
conditions; for details, see: https://www.gnu.org/licenses/gpl-3.0.html"""
|
conditions; for details, see: https://www.gnu.org/licenses/gpl-3.0.html"""
|
||||||
|
|
||||||
print(version_str)
|
print(version_str)
|
||||||
print()
|
|
||||||
print("Active Plugins:")
|
|
||||||
print(" Importers:")
|
|
||||||
for importer in IMPORT_FORMATS:
|
|
||||||
importer_class = get_importer(importer)
|
|
||||||
print(
|
|
||||||
f" {importer} : {importer_class.version} from",
|
|
||||||
f"{importer_class().class_path()}",
|
|
||||||
)
|
|
||||||
print(" Exporters:")
|
|
||||||
for exporter in EXPORT_FORMATS:
|
|
||||||
exporter_class = get_exporter(exporter)
|
|
||||||
# print(f" {exporter} : {exporter_class.version} from {exporter_class().class_path()}")
|
|
||||||
print(f" {exporter} : ", end="")
|
|
||||||
print(f"{exporter_class.version} from ", end="")
|
|
||||||
print(f"{exporter_class().class_path()}")
|
|
||||||
|
|
||||||
|
|
||||||
def postconfig_list(config, **kwargs):
|
def postconfig_list(config, **kwargs):
|
||||||
|
|
|
@ -21,30 +21,36 @@ i.e. it is the collection of code that allows plugins to deal with themselves.
|
||||||
import importlib
|
import importlib
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
|
||||||
import jrnl.contrib.exporter
|
INTERNAL_EXPORTER_CLASS_PATH = "jrnl.plugins.exporter"
|
||||||
import jrnl.contrib.importer
|
INTERNAL_IMPORTER_CLASS_PATH = "jrnl.plugins.importer"
|
||||||
import jrnl.plugins.exporter
|
EXTERNAL_EXPORTER_CLASS_PATH = "jrnl.contrib.exporter"
|
||||||
import jrnl.plugins.importer
|
EXTERNAL_IMPORTER_CLASS_PATH = "jrnl.contrib.importer"
|
||||||
|
|
||||||
|
__internal_exporter_class = importlib.import_module(INTERNAL_EXPORTER_CLASS_PATH)
|
||||||
|
__internal_importer_class = importlib.import_module(INTERNAL_IMPORTER_CLASS_PATH)
|
||||||
|
__external_exporter_class = importlib.import_module(EXTERNAL_EXPORTER_CLASS_PATH)
|
||||||
|
__external_importer_class = importlib.import_module(EXTERNAL_IMPORTER_CLASS_PATH)
|
||||||
|
|
||||||
|
|
||||||
__exporters_builtin = list(
|
__exporters_builtin = list(
|
||||||
pkgutil.iter_modules(
|
pkgutil.iter_modules(
|
||||||
jrnl.plugins.exporter.__path__, jrnl.plugins.exporter.__name__ + "."
|
__internal_exporter_class.__path__, __internal_exporter_class.__name__ + "."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
__exporters_contrib = list(
|
__exporters_contrib = list(
|
||||||
pkgutil.iter_modules(
|
pkgutil.iter_modules(
|
||||||
jrnl.contrib.exporter.__path__, jrnl.contrib.exporter.__name__ + "."
|
__external_exporter_class.__path__, __external_exporter_class.__name__ + "."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
__importers_builtin = list(
|
__importers_builtin = list(
|
||||||
pkgutil.iter_modules(
|
pkgutil.iter_modules(
|
||||||
jrnl.plugins.importer.__path__, jrnl.plugins.importer.__name__ + "."
|
__internal_importer_class.__path__, __internal_importer_class.__name__ + "."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
__importers_contrib = list(
|
__importers_contrib = list(
|
||||||
pkgutil.iter_modules(
|
pkgutil.iter_modules(
|
||||||
jrnl.contrib.importer.__path__, jrnl.contrib.importer.__name__ + "."
|
__external_importer_class.__path__, __external_importer_class.__name__ + "."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ from jrnl.plugins.exporter import json as json_exporter
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from jrnl.contrib.exporter import testing as testing_exporter
|
from jrnl.contrib.exporter import testing as testing_exporter
|
||||||
except:
|
except ImportError:
|
||||||
testing_exporter = None
|
testing_exporter = None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jrnl.exception import JrnlError
|
from jrnl.exception import JrnlError
|
||||||
from jrnl.plugins.fancy_exporter import check_provided_linewrap_viability
|
from jrnl.plugins.util import check_provided_linewrap_viability
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
|
Loading…
Add table
Reference in a new issue