[tor-commits] [stem/master] tor-prompt requires the readline module

atagar at torproject.org atagar at torproject.org
Sun Jan 5 21:39:28 UTC 2020


commit fb35e3f68477611b39729125e0ae0b3d6d6cfe82
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Jan 3 14:13:22 2020 -0800

    tor-prompt requires the readline module
    
    When compiling Python ourselves several modules (most notably compression) are
    unavailable by default. Turns out readline is one of those, so we cannot assume
    it is always present...
    
      ======================================================================
      ERROR: test_running_command
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/home/atagar/Desktop/stem/stem/util/system.py", line 1329, in call
          raise OSError('%s returned exit status %i' % (command, exit_status))
      OSError: ['/home/atagar/Python-3.7.0/python', '/home/atagar/Desktop/stem/tor-prompt', '--interface', 1111, '--run', 'GETINFO config-file'] returned exit status 1
    
      During handling of the above exception, another exception occurred:
    
      Traceback (most recent call last):
        File "/home/atagar/Desktop/stem/test/require.py", line 58, in wrapped
          return func(self, *args, **kwargs)
        File "/home/atagar/Desktop/stem/test/integ/interpreter.py", line 36, in test_running_command
          self.assertEqual(expected, _run_prompt('--run', 'GETINFO config-file'))
        File "/home/atagar/Desktop/stem/test/integ/interpreter.py", line 20, in _run_prompt
          return stem.util.system.call([sys.executable, PROMPT_CMD, '--interface', test.runner.CONTROL_PORT] + list(args))
        File "/home/atagar/Desktop/stem/stem/util/system.py", line 1348, in call
          raise CallError(str(exc), ' '.join(command_list), exit_status, runtime, stdout, stderr)
      stem.util.system.CallError: ['/home/atagar/Python-3.7.0/python', '/home/atagar/Desktop/stem/tor-prompt', '--interface', 1111, '--run', 'GETINFO config-file'] returned exit status 1
    
      ======================================================================
      ERROR: test_running_file
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/home/atagar/Desktop/stem/stem/util/system.py", line 1329, in call
          raise OSError('%s returned exit status %i' % (command, exit_status))
      OSError: ['/home/atagar/Python-3.7.0/python', '/home/atagar/Desktop/stem/tor-prompt', '--interface', 1111, '--run', '/tmp/test_commands.wmb8rcb8'] returned exit status 1
    
      During handling of the above exception, another exception occurred:
    
      Traceback (most recent call last):
        File "/home/atagar/Desktop/stem/test/require.py", line 58, in wrapped
          return func(self, *args, **kwargs)
        File "/home/atagar/Desktop/stem/test/integ/interpreter.py", line 56, in test_running_file
          self.assertEqual(expected, _run_prompt('--run', tmp.name))
        File "/home/atagar/Desktop/stem/test/integ/interpreter.py", line 20, in _run_prompt
          return stem.util.system.call([sys.executable, PROMPT_CMD, '--interface', test.runner.CONTROL_PORT] + list(args))
        File "/home/atagar/Desktop/stem/stem/util/system.py", line 1348, in call
          raise CallError(str(exc), ' '.join(command_list), exit_status, runtime, stdout, stderr)
      stem.util.system.CallError: ['/home/atagar/Python-3.7.0/python', '/home/atagar/Desktop/stem/tor-prompt', '--interface', 1111, '--run', '/tmp/test_commands.wmb8rcb8'] returned exit status 1
---
 stem/interpreter/__init__.py |  6 +++++-
 test/integ/interpreter.py    | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/stem/interpreter/__init__.py b/stem/interpreter/__init__.py
index bd623120..30af3f62 100644
--- a/stem/interpreter/__init__.py
+++ b/stem/interpreter/__init__.py
@@ -44,7 +44,11 @@ def msg(message, config, **attr):
 
 
 def main():
-  import readline
+  try:
+    import readline
+  except ImportError:
+    print('tor-prompt requires the readline module')
+    sys.exit(1)
 
   import stem.interpreter.arguments
   import stem.interpreter.autocomplete
diff --git a/test/integ/interpreter.py b/test/integ/interpreter.py
index e3664d87..65d03fd3 100644
--- a/test/integ/interpreter.py
+++ b/test/integ/interpreter.py
@@ -12,6 +12,14 @@ 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')
 
 
@@ -31,6 +39,9 @@ class TestInterpreter(unittest.TestCase):
     if test.runner.Torrc.PASSWORD in test.runner.get_runner().get_options():
       self.skipTest('password auth unsupported')
       return
+    elif not READLINE_AVAILABLE:
+      self.skipTest('readline unavailable')
+      return
 
     expected = ['250-config-file=%s' % test.runner.get_runner().get_torrc_path(), '250 OK']
     self.assertEqual(expected, _run_prompt('--run', 'GETINFO config-file'))
@@ -40,6 +51,9 @@ class TestInterpreter(unittest.TestCase):
     if test.runner.Torrc.PASSWORD in test.runner.get_runner().get_options():
       self.skipTest('password auth unsupported')
       return
+    elif not READLINE_AVAILABLE:
+      self.skipTest('readline unavailable')
+      return
 
     expected = [
       '250-config-file=%s' % test.runner.get_runner().get_torrc_path(),





More information about the tor-commits mailing list