[tor-commits] [stem/master] Only requre readline for interactive interpreter

atagar at torproject.org atagar at torproject.org
Fri Jul 24 23:32:52 UTC 2020


commit 9e68863c6a70eef4e70571d334f2ab61e5049526
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Jul 23 15:53:05 2020 -0700

    Only requre readline for interactive interpreter
    
    For reasons I don't grok python 3.7's readline module segfaults whenever I use
    it, so I've been unable to run our tor-prompt tests.
    
    We only need readline for an interactive interpreter so narrowing it to that
    scope so I can once again run its other tests.
---
 stem/interpreter/__init__.py | 13 ++++++-------
 test/integ/interpreter.py    | 12 ------------
 2 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/stem/interpreter/__init__.py b/stem/interpreter/__init__.py
index 872e7f6f..6666dc89 100644
--- a/stem/interpreter/__init__.py
+++ b/stem/interpreter/__init__.py
@@ -43,12 +43,6 @@ def msg(message: str, config: 'stem.util.conf.Config', **attr: str) -> str:
 
 
 def main() -> None:
-  try:
-    import readline
-  except ImportError:
-    print('tor-prompt requires the readline module')
-    sys.exit(1)
-
   import stem.interpreter.arguments
   import stem.interpreter.autocomplete
   import stem.interpreter.commands
@@ -148,8 +142,13 @@ def main() -> None:
       except IOError as exc:
         print(format(msg('msg.unable_to_read_file', path = args.run_path, error = exc), *ERROR_OUTPUT))
         sys.exit(1)
-
     else:
+      try:
+        import readline
+      except ImportError:
+        print('tor-prompt requires the readline module')
+        sys.exit(1)
+
       autocompleter = stem.interpreter.autocomplete.Autocompleter(controller)
       readline.parse_and_bind('tab: complete')
       readline.set_completer(autocompleter.complete)
diff --git a/test/integ/interpreter.py b/test/integ/interpreter.py
index 32c52c28..492f2c9c 100644
--- a/test/integ/interpreter.py
+++ b/test/integ/interpreter.py
@@ -12,14 +12,6 @@ import test
 import test.require
 import test.runner
 
-try:
-  # when compiled ourselves the readline module might be unavailable
-
-  import readline
-  READLINE_AVAILABLE = True
-except ImportError:
-  READLINE_AVAILABLE = False
-
 PROMPT_CMD = os.path.join(test.STEM_BASE, 'tor-prompt')
 
 
@@ -38,8 +30,6 @@ class TestInterpreter(unittest.TestCase):
 
     if test.runner.Torrc.PASSWORD in test.runner.get_runner().get_options():
       self.skipTest('password auth unsupported')
-    elif not READLINE_AVAILABLE:
-      self.skipTest('readline unavailable')
 
     expected = ['250-config-file=%s' % test.runner.get_runner().get_torrc_path(), '250 OK']
     self.assertEqual(expected, _run_prompt('--run', 'GETINFO config-file'))
@@ -48,8 +38,6 @@ class TestInterpreter(unittest.TestCase):
   def test_running_file(self):
     if test.runner.Torrc.PASSWORD in test.runner.get_runner().get_options():
       self.skipTest('password auth unsupported')
-    elif not READLINE_AVAILABLE:
-      self.skipTest('readline unavailable')
 
     expected = [
       '250-config-file=%s' % test.runner.get_runner().get_torrc_path(),





More information about the tor-commits mailing list