[tor-commits] [nyx/master] Adjust shebang line of installed nyx script

atagar at torproject.org atagar at torproject.org
Tue Jun 9 16:40:35 UTC 2015


commit 8e050ea63ac3e7a69422352c78568d64d55cc517
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Jun 9 09:35:08 2015 -0700

    Adjust shebang line of installed nyx script
    
    Very good point from Yawning that we should adjust our shebang line to match
    the interpreter that's installing us...
    
      https://trac.torproject.org/projects/tor/ticket/16317
    
    This is based on the copy_scripts() method of...
    
      distutils/command/build_scripts.py
---
 setup.py |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index b07995f..d780228 100644
--- a/setup.py
+++ b/setup.py
@@ -6,6 +6,7 @@ import gzip
 import os
 import shutil
 import stat
+import sysconfig
 
 import nyx
 
@@ -57,9 +58,22 @@ class NyxInstaller(install):
     # Install our bin script. We do this ourselves rather than with the setup()
     # method's scripts argument because we want to call the script 'nyx' rather
     # than 'run_nyx'.
+    #
+    # If using setuptools this would be better replaced with its entry_points.
 
     self.mkpath(os.path.dirname(dest))
-    shutil.copyfile(source, dest)
+
+    with open(source, 'rb') as source_file:
+      with open(dest, 'wb') as dest_file:
+        orig_shebang = source_file.readline()
+
+        python_cmd = 'python%s%s' % (sysconfig.get_config_var('VERSION'), sysconfig.get_config_var('EXE'))
+        new_shebang = '#!%s\n' % os.path.join(sysconfig.get_config_var('BINDIR'), python_cmd)
+
+        log.info("adjusting bin script's shebang line '%s' -> '%s'" % (orig_shebang.strip(), new_shebang.strip()))
+        dest_file.write(new_shebang)
+        dest_file.write(source_file.read())
+
     mode = ((os.stat(dest)[stat.ST_MODE]) | 0o555) & 0o7777
     os.chmod(dest, mode)
     log.info("installed bin script to '%s'" % dest)





More information about the tor-commits mailing list