setup.py
changeset 27269 bdcbec65750b
parent 27268 ed1660ce99d9
child 27348 83a8219fb790
equal deleted inserted replaced
27268:ed1660ce99d9 27269:bdcbec65750b
   477                                    ('install_lib', 'install_lib'))
   477                                    ('install_lib', 'install_lib'))
   478 
   478 
   479     def run(self):
   479     def run(self):
   480         install_scripts.run(self)
   480         install_scripts.run(self)
   481 
   481 
       
   482         # It only makes sense to replace @LIBDIR@ with the install path if
       
   483         # the install path is known. For wheels, the logic below calculates
       
   484         # the libdir to be "../..". This is because the internal layout of a
       
   485         # wheel archive looks like:
       
   486         #
       
   487         #   mercurial-3.6.1.data/scripts/hg
       
   488         #   mercurial/__init__.py
       
   489         #
       
   490         # When installing wheels, the subdirectories of the "<pkg>.data"
       
   491         # directory are translated to system local paths and files therein
       
   492         # are copied in place. The mercurial/* files are installed into the
       
   493         # site-packages directory. However, the site-packages directory
       
   494         # isn't known until wheel install time. This means we have no clue
       
   495         # at wheel generation time what the installed site-packages directory
       
   496         # will be. And, wheels don't appear to provide the ability to register
       
   497         # custom code to run during wheel installation. This all means that
       
   498         # we can't reliably set the libdir in wheels: the default behavior
       
   499         # of looking in sys.path must do.
       
   500 
   482         if (os.path.splitdrive(self.install_dir)[0] !=
   501         if (os.path.splitdrive(self.install_dir)[0] !=
   483             os.path.splitdrive(self.install_lib)[0]):
   502             os.path.splitdrive(self.install_lib)[0]):
   484             # can't make relative paths from one drive to another, so use an
   503             # can't make relative paths from one drive to another, so use an
   485             # absolute path instead
   504             # absolute path instead
   486             libdir = self.install_lib
   505             libdir = self.install_lib
   496             data = fp.read()
   515             data = fp.read()
   497             fp.close()
   516             fp.close()
   498 
   517 
   499             # skip binary files
   518             # skip binary files
   500             if b('\0') in data:
   519             if b('\0') in data:
       
   520                 continue
       
   521 
       
   522             # During local installs, the shebang will be rewritten to the final
       
   523             # install path. During wheel packaging, the shebang has a special
       
   524             # value.
       
   525             if data.startswith(b'#!python'):
       
   526                 log.info('not rewriting @LIBDIR@ in %s because install path '
       
   527                          'not known' % outfile)
   501                 continue
   528                 continue
   502 
   529 
   503             data = data.replace(b('@LIBDIR@'), libdir.encode(libdir_escape))
   530             data = data.replace(b('@LIBDIR@'), libdir.encode(libdir_escape))
   504             fp = open(outfile, 'wb')
   531             fp = open(outfile, 'wb')
   505             fp.write(data)
   532             fp.write(data)