From 8359ddafe0a6ad5bdb05c86a05a9537b33825ede Mon Sep 17 00:00:00 2001 From: David Andreoletti Date: Wed, 24 Jan 2024 07:26:35 +0800 Subject: [PATCH] fix: warn when --filter is used and asscaciated dependencies missing --- pass_import/__main__.py | 15 ++++++++++++--- setup.cfg | 7 +++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pass_import/__main__.py b/pass_import/__main__.py index 07c84ca..9006cd9 100644 --- a/pass_import/__main__.py +++ b/pass_import/__main__.py @@ -23,9 +23,6 @@ import traceback from argparse import ArgumentParser, RawDescriptionHelpFormatter -import jsonpath_ng.ext -from jsonpath_ng.exceptions import JsonPathLexerError, JsonPathParserError - from pass_import import Detecters, Managers, __version__ from pass_import.auto import AutoDetect from pass_import.core import Cap @@ -34,6 +31,13 @@ MANAGERS = Managers() +try: + import jsonpath_ng.ext + from jsonpath_ng.exceptions import JsonPathLexerError, JsonPathParserError + JSONNG = True +except ImportError: + JSONNG = False + class ArgParser(ArgumentParser): """Manages argument parsing and adds some defaults.""" @@ -437,6 +441,11 @@ def pass_filter(conf, entry): if filter_expression is None: return True + if not JSONNG: + message = ("--filter requires pass-import[filter] " + "or pass-import[all] to be installed") + raise ImportError('Missing packages. ' + message) + # Having end users write their JSONPath filter expression as if # pass-import processes/filters entries in bulk, will allow end # users filter expression to continue to work when/if bulk filter is diff --git a/setup.cfg b/setup.cfg index 6000c20..ac9671f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,7 +50,6 @@ install_requires = pyaml zxcvbn requests - jsonpath-ng [options.entry_points] console_scripts = @@ -67,9 +66,13 @@ encrypted_otp = cryptography decrypt = file-magic -all = +filter = + jsonpath-ng +all = defusedxml pykeepass secretstorage cryptography file-magic + jsonpath-ng +