mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Check for readline module instead of Windows when initializing autocomplete in install (#1104)
This commit is contained in:
parent
bade28a0b0
commit
48cde1b473
2 changed files with 24 additions and 9 deletions
|
@ -12,14 +12,9 @@ from . import __version__
|
|||
from .config import load_config
|
||||
from .config import verify_config_colors
|
||||
from .exception import UserAbort
|
||||
from .os_compat import on_windows
|
||||
from .prompt import yesno
|
||||
from .upgrade import is_old_version
|
||||
|
||||
if not on_windows:
|
||||
# readline is not included in Windows Active Python
|
||||
import readline
|
||||
|
||||
DEFAULT_CONFIG_NAME = "jrnl.yaml"
|
||||
DEFAULT_JOURNAL_NAME = "journal.txt"
|
||||
DEFAULT_JOURNAL_KEY = "default"
|
||||
|
@ -127,10 +122,7 @@ def load_or_install_jrnl():
|
|||
|
||||
|
||||
def install():
|
||||
if not on_windows:
|
||||
readline.set_completer_delims(" \t\n;")
|
||||
readline.parse_and_bind("tab: complete")
|
||||
readline.set_completer(_autocomplete_path)
|
||||
_initialize_autocomplete()
|
||||
|
||||
# Where to create the journal?
|
||||
path_query = f"Path to your journal file (leave blank for {JOURNAL_FILE_PATH}): "
|
||||
|
@ -159,6 +151,16 @@ def install():
|
|||
return default_config
|
||||
|
||||
|
||||
def _initialize_autocomplete():
|
||||
# readline is not included in Windows Active Python and perhaps some other distributions
|
||||
if sys.modules.get("readline"):
|
||||
import readline
|
||||
|
||||
readline.set_completer_delims(" \t\n;")
|
||||
readline.parse_and_bind("tab: complete")
|
||||
readline.set_completer(_autocomplete_path)
|
||||
|
||||
|
||||
def _autocomplete_path(text, state):
|
||||
expansions = glob.glob(os.path.expanduser(os.path.expandvars(text)) + "*")
|
||||
expansions = [e + "/" if os.path.isdir(e) else e for e in expansions]
|
||||
|
|
13
tests/test_install.py
Normal file
13
tests/test_install.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from unittest import mock
|
||||
import pytest
|
||||
import sys
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings(
|
||||
"ignore:.*imp module is deprecated.*"
|
||||
) # ansiwrap spits out an unrelated warning
|
||||
def test_initialize_autocomplete_runs_without_readline():
|
||||
from jrnl import install
|
||||
|
||||
with mock.patch.dict(sys.modules, {"readline": None}):
|
||||
install._initialize_autocomplete() # should not throw exception
|
Loading…
Add table
Reference in a new issue