Merge lp:~gz/bzrtools/shell_without_readline_719075 into lp:bzrtools

Proposed by Martin Packman
Status: Merged
Merged at revision: 764
Proposed branch: lp:~gz/bzrtools/shell_without_readline_719075
Merge into: lp:bzrtools
Diff against target: 39 lines (+13/-6)
1 file modified
shell.py (+13/-6)
To merge this branch: bzr merge lp:~gz/bzrtools/shell_without_readline_719075
Reviewer Review Type Date Requested Status
Aaron Bentley Needs Fixing
Review via email: mp+49744@code.launchpad.net

Description of the change

Allows the readline import to fail in bzrtools.shell and modifies PromptCmd to tolerate the absence of the readline module. The autocompletion is explictly disabled if this is the case, it would work anyway, but it saves cmd.Cmd repeatedly trying and failing to import readline.

The test is a little black magic, but I think it should be reliable, and function on all platforms to ensure this doesn't accidentally regress.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

Making readline optional is fine, but please retain PEP8 import ordering-- readline should still be imported between os and shlex, not as if it was a third-party library.

I don't understand why you're explicitly disabling autocompletion. On platforms without readline, it won't work, but I don't think that incurs overhead.

Your test is broken. It passes (on Ubuntu Maverick) even if I revert the changes to shell.py. I believe it is sensitive to differences in python path.

I don't think it's sensible to test interactive functionality using a blackbox test. Tests are not required for "shell". Actually, all of bzrtools is a bit lax.

review: Needs Fixing
758. By Martin Packman

Remove test as it can't fail reliably cross platform

759. By Martin Packman

Address review comments from Aaron Bentley

Revision history for this message
Martin Packman (gz) wrote :

> Making readline optional is fine, but please retain PEP8 import ordering--
> readline should still be imported between os and shlex, not as if it was a
> third-party library.

Okay, seemed a bit odd to mix plain imports with try/except.

> I don't understand why you're explicitly disabling autocompletion. On
> platforms without readline, it won't work, but I don't think that incurs
> overhead.

You're right. It's mostly documentary. Changed.

> Your test is broken. It passes (on Ubuntu Maverick) even if I revert the
> changes to shell.py. I believe it is sensitive to differences in python path.
>
> I don't think it's sensible to test interactive functionality using a blackbox
> test. Tests are not required for "shell". Actually, all of bzrtools is a bit
> lax.

Thanks for double checking that. Had forgotten some of the intricacies of sys.path wrt interactive mode vs running a script and platform/version differences.

I don't like that shell isn't really tested, but have removed that attempt as I'm not sure even messing with PYTHONPATH would be enough given setuptools and other complications.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'shell.py'
--- shell.py 2011-02-15 01:04:23 +0000
+++ shell.py 2011-02-16 01:10:13 +0000
@@ -18,7 +18,12 @@
18import cmd18import cmd
19from itertools import chain19from itertools import chain
20import os20import os
21import readline21try:
22 import readline
23except ImportError:
24 _has_readline = False
25else:
26 _has_readline = True
22import shlex27import shlex
23import stat28import stat
24import string29import string
@@ -100,14 +105,16 @@
100 ensure_config_dir_exists()105 ensure_config_dir_exists()
101 self.history_file = osutils.pathjoin(config_dir(), 'shell-history')106 self.history_file = osutils.pathjoin(config_dir(), 'shell-history')
102 whitespace = ''.join(c for c in string.whitespace if c < chr(127))107 whitespace = ''.join(c for c in string.whitespace if c < chr(127))
103 readline.set_completer_delims(whitespace)108 if _has_readline:
104 if os.access(self.history_file, os.R_OK) and \109 readline.set_completer_delims(whitespace)
105 os.path.isfile(self.history_file):110 if os.access(self.history_file, os.R_OK) and \
106 readline.read_history_file(self.history_file)111 os.path.isfile(self.history_file):
112 readline.read_history_file(self.history_file)
107 self.cwd = os.getcwd()113 self.cwd = os.getcwd()
108114
109 def write_history(self):115 def write_history(self):
110 readline.write_history_file(self.history_file)116 if _has_readline:
117 readline.write_history_file(self.history_file)
111118
112 def do_quit(self, args):119 def do_quit(self, args):
113 self.write_history()120 self.write_history()

Subscribers

People subscribed via source and target branches