Merge lp:~jelmer/bzr/no-termios into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merged at revision: 6380
Proposed branch: lp:~jelmer/bzr/no-termios
Merge into: lp:bzr
Diff against target: 40 lines (+7/-3)
2 files modified
bzrlib/osutils.py (+3/-3)
bzrlib/tests/test_import_tariff.py (+4/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/no-termios
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Review via email: mp+86166@code.launchpad.net

Commit message

Avoid always importing termios and tty in bzrlib.osutils.

Description of the change

Lazily import tty and termios if we don't have to.

We only seem to use getchar() to get user input ("y", "n"), so it seems
reasonable to me to have a local import here. We could also make it
use lazy_import.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Worth not importing these straight off.

The way imports are delayed in osutils is so inconsistent. This method is fine as we're not worried about getchar overhead, putting them in lazy import at the top may be slightly better, but less clear.

Arguably these functions should be made private, on trunk this needs to go through ui._ChooseUI or we break non-terminal interactions.

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/osutils.py'
2--- bzrlib/osutils.py 2011-12-14 19:31:25 +0000
3+++ bzrlib/osutils.py 2011-12-18 15:58:24 +0000
4@@ -2325,13 +2325,13 @@
5
6
7 if sys.platform == "win32":
8- import msvcrt
9 def getchar():
10+ import msvcrt
11 return msvcrt.getch()
12 else:
13- import tty
14- import termios
15 def getchar():
16+ import tty
17+ import termios
18 fd = sys.stdin.fileno()
19 settings = termios.tcgetattr(fd)
20 try:
21
22=== modified file 'bzrlib/tests/test_import_tariff.py'
23--- bzrlib/tests/test_import_tariff.py 2011-12-12 11:23:28 +0000
24+++ bzrlib/tests/test_import_tariff.py 2011-12-18 15:58:24 +0000
25@@ -193,6 +193,8 @@
26 'smtplib',
27 'tarfile',
28 'tempfile',
29+ 'termios',
30+ 'tty',
31 ] + old_format_modules)
32 # TODO: similar test for repository-only operations, checking we avoid
33 # loading wt-specific stuff
34@@ -262,4 +264,6 @@
35 'smtplib',
36 'tarfile',
37 'tempfile',
38+ 'termios',
39+ 'tty',
40 ] + old_format_modules)