Skip to content

Commit

Permalink
fix: warn when --filter is used and asscaciated dependencies missing
Browse files Browse the repository at this point in the history
  • Loading branch information
davidandreoletti authored and roddhjav committed Jan 24, 2024
1 parent 4854d10 commit 8359dda
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
15 changes: 12 additions & 3 deletions pass_import/__main__.py
Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions setup.cfg
Expand Up @@ -50,7 +50,6 @@ install_requires =
pyaml
zxcvbn
requests
jsonpath-ng

[options.entry_points]
console_scripts =
Expand All @@ -67,9 +66,13 @@ encrypted_otp =
cryptography
decrypt =
file-magic
all =
filter =
jsonpath-ng
all =
defusedxml
pykeepass
secretstorage
cryptography
file-magic
jsonpath-ng

0 comments on commit 8359dda

Please sign in to comment.