chiark / gitweb /
Allow StGIT to be installed in a local directory
[stgit] / stg
diff --git a/stg b/stg
index ca9307e1d1e4bf3e83eafaa87ace266a09db30d1..5ec2c22b0579d1bc939fe9c6739c2682f836606c 100755 (executable)
--- a/stg
+++ b/stg
@@ -20,6 +20,22 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
+import sys, os
+
+# Try to detect where it is run from and set prefix and the search path.
+# It is assumed that the user installed StGIT using the --prefix= option
+prefix, bin = os.path.split(sys.path[0])
+
+if bin == 'bin' and prefix != sys.prefix:
+    sys.prefix = prefix
+    sys.exec_prefix = prefix
+
+    major, minor = sys.version_info[0:2]
+    sys.path += [os.path.join(prefix, 'lib', 'python'),
+                 os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)),
+                 os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor),
+                              'site-packages')]
+
 from stgit.main import main
 
 main()