Move requests import to downloads
authorGuido Günther <agx@sigxcpu.org>
Fri, 20 Feb 2015 15:58:01 +0000 (16:58 +0100)
committerGuido Günther <agx@sigxcpu.org>
Fri, 20 Feb 2015 16:02:37 +0000 (17:02 +0100)
The requests import takes ages and therefore considerably slows
down program start up.

This is very much noticeably during bash completion. Before:

$ time gbp --list-cmds >/dev/null

real 0m0.559s
user 0m0.528s
sys 0m0.028s

After:

$ time gbp --list-cmds >/dev/null

real 0m0.092s
user 0m0.088s
sys 0m0.000s

gbp/scripts/common/import_orig.py

index 54ada528baf7dd8c64c1d1ee5de6afe6e5c95aa7..d36804f3ba78b0655307fe34417900672c4763ed 100644 (file)
@@ -35,11 +35,6 @@ try:
 except ImportError:
     pass
 
-try:
-    import requests
-except ImportError:
-    requests = None
-
 def orig_needs_repack(upstream_source, options):
     """
     Determine if the upstream sources needs to be repacked
@@ -156,6 +151,11 @@ def download_orig(url):
     """
     CHUNK_SIZE=4096
 
+    try:
+        import requests
+    except ImportError:
+        requests = None
+
     if requests is None:
         raise GbpError("python-requests not installed")