Browse Source

Delay importing subprocess as much as possible, in case it is not available
(e.g. on IronPython).

Jelmer Vernooij 14 years ago
parent
commit
ab43e21ff6
2 changed files with 5 additions and 3 deletions
  1. 3 1
      dulwich/client.py
  2. 2 2
      dulwich/patch.py

+ 3 - 1
dulwich/client.py

@@ -23,7 +23,6 @@ __docformat__ = 'restructuredText'
 
 import select
 import socket
-import subprocess
 import urlparse
 
 from dulwich.errors import (
@@ -314,6 +313,7 @@ class SubprocessGitClient(GitClient):
         GitClient.__init__(self, *args, **kwargs)
 
     def _connect(self, service, path):
+        import subprocess
         argv = ['git', service, path]
         p = SubprocessWrapper(
             subprocess.Popen(argv, bufsize=0, stdin=subprocess.PIPE,
@@ -321,9 +321,11 @@ class SubprocessGitClient(GitClient):
         return Protocol(p.read, p.write,
                         report_activity=self._report_activity), p.can_read
 
+
 class SSHVendor(object):
 
     def connect_ssh(self, host, command, username=None, port=None):
+        import subprocess
         #FIXME: This has no way to deal with passwords..
         args = ['ssh', '-x']
         if port is not None:

+ 2 - 2
dulwich/patch.py

@@ -24,7 +24,6 @@ on.
 
 from difflib import SequenceMatcher
 import rfc822
-import subprocess
 import time
 
 from dulwich.objects import (
@@ -47,9 +46,10 @@ def write_commit_patch(f, commit, contents, progress, version=None):
     f.write("\n")
     f.write("---\n")
     try:
+        import subprocess
         p = subprocess.Popen(["diffstat"], stdout=subprocess.PIPE,
                              stdin=subprocess.PIPE)
-    except OSError, e:
+    except (ImportError, OSError), e:
         pass # diffstat not available?
     else:
         (diffstat, _) = p.communicate(contents)