Skip to content

Commit 8359dda

Browse files
davidandreolettiroddhjav
authored andcommitted
fix: warn when --filter is used and asscaciated dependencies missing
1 parent 4854d10 commit 8359dda

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

pass_import/__main__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
import traceback
2424
from argparse import ArgumentParser, RawDescriptionHelpFormatter
2525

26-
import jsonpath_ng.ext
27-
from jsonpath_ng.exceptions import JsonPathLexerError, JsonPathParserError
28-
2926
from pass_import import Detecters, Managers, __version__
3027
from pass_import.auto import AutoDetect
3128
from pass_import.core import Cap
@@ -34,6 +31,13 @@
3431

3532
MANAGERS = Managers()
3633

34+
try:
35+
import jsonpath_ng.ext
36+
from jsonpath_ng.exceptions import JsonPathLexerError, JsonPathParserError
37+
JSONNG = True
38+
except ImportError:
39+
JSONNG = False
40+
3741

3842
class ArgParser(ArgumentParser):
3943
"""Manages argument parsing and adds some defaults."""
@@ -437,6 +441,11 @@ def pass_filter(conf, entry):
437441
if filter_expression is None:
438442
return True
439443

444+
if not JSONNG:
445+
message = ("--filter requires pass-import[filter] "
446+
"or pass-import[all] to be installed")
447+
raise ImportError('Missing packages. ' + message)
448+
440449
# Having end users write their JSONPath filter expression as if
441450
# pass-import processes/filters entries in bulk, will allow end
442451
# users filter expression to continue to work when/if bulk filter is

setup.cfg

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ install_requires =
5050
pyaml
5151
zxcvbn
5252
requests
53-
jsonpath-ng
5453

5554
[options.entry_points]
5655
console_scripts =
@@ -67,9 +66,13 @@ encrypted_otp =
6766
cryptography
6867
decrypt =
6968
file-magic
70-
all =
69+
filter =
70+
jsonpath-ng
71+
all =
7172
defusedxml
7273
pykeepass
7374
secretstorage
7475
cryptography
7576
file-magic
77+
jsonpath-ng
78+

0 commit comments

Comments
 (0)