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
1=== modified file 'shell.py'
2--- shell.py 2011-02-15 01:04:23 +0000
3+++ shell.py 2011-02-16 01:10:13 +0000
4@@ -18,7 +18,12 @@
5 import cmd
6 from itertools import chain
7 import os
8-import readline
9+try:
10+ import readline
11+except ImportError:
12+ _has_readline = False
13+else:
14+ _has_readline = True
15 import shlex
16 import stat
17 import string
18@@ -100,14 +105,16 @@
19 ensure_config_dir_exists()
20 self.history_file = osutils.pathjoin(config_dir(), 'shell-history')
21 whitespace = ''.join(c for c in string.whitespace if c < chr(127))
22- readline.set_completer_delims(whitespace)
23- if os.access(self.history_file, os.R_OK) and \
24- os.path.isfile(self.history_file):
25- readline.read_history_file(self.history_file)
26+ if _has_readline:
27+ readline.set_completer_delims(whitespace)
28+ if os.access(self.history_file, os.R_OK) and \
29+ os.path.isfile(self.history_file):
30+ readline.read_history_file(self.history_file)
31 self.cwd = os.getcwd()
32
33 def write_history(self):
34- readline.write_history_file(self.history_file)
35+ if _has_readline:
36+ readline.write_history_file(self.history_file)
37
38 def do_quit(self, args):
39 self.write_history()

Subscribers

People subscribed via source and target branches