setup.py
changeset 35229 61ff0d7d56fd
parent 35103 7ea56f5700b8
child 35246 d73ccc63b8f9
equal deleted inserted replaced
35228:04a2820f2fca 35229:61ff0d7d56fd
   133     DistutilsError,
   133     DistutilsError,
   134     DistutilsExecError,
   134     DistutilsExecError,
   135 )
   135 )
   136 from distutils.sysconfig import get_python_inc, get_config_var
   136 from distutils.sysconfig import get_python_inc, get_config_var
   137 from distutils.version import StrictVersion
   137 from distutils.version import StrictVersion
       
   138 
       
   139 def write_if_changed(path, content):
       
   140     """Write content to a file iff the content hasn't changed."""
       
   141     if os.path.exists(path):
       
   142         with open(path, 'rb') as fh:
       
   143             current = fh.read()
       
   144     else:
       
   145         current = b''
       
   146 
       
   147     if current != content:
       
   148         with open(path, 'wb') as fh:
       
   149             fh.write(content)
   138 
   150 
   139 scripts = ['hg']
   151 scripts = ['hg']
   140 if os.name == 'nt':
   152 if os.name == 'nt':
   141     # We remove hg.bat if we are able to build hg.exe.
   153     # We remove hg.bat if we are able to build hg.exe.
   142     scripts.append('contrib/win32/hg.bat')
   154     scripts.append('contrib/win32/hg.bat')
   315             version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
   327             version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
   316     else:
   328     else:
   317         version = kw.get('node', '')[:12]
   329         version = kw.get('node', '')[:12]
   318 
   330 
   319 if version:
   331 if version:
   320     with open("mercurial/__version__.py", "w") as f:
   332     versionb = version
   321         f.write('# this file is autogenerated by setup.py\n')
   333     if not isinstance(versionb, bytes):
   322         f.write('version = "%s"\n' % version)
   334         versionb = versionb.encode('ascii')
       
   335 
       
   336     write_if_changed('mercurial/__version__.py', b''.join([
       
   337         b'# this file is autogenerated by setup.py\n'
       
   338         b'version = "%s"\n' % versionb,
       
   339     ]))
   323 
   340 
   324 try:
   341 try:
   325     oldpolicy = os.environ.get('HGMODULEPOLICY', None)
   342     oldpolicy = os.environ.get('HGMODULEPOLICY', None)
   326     os.environ['HGMODULEPOLICY'] = 'py'
   343     os.environ['HGMODULEPOLICY'] = 'py'
   327     from mercurial import __version__
   344     from mercurial import __version__
   476         elif self.build_lib == '.':
   493         elif self.build_lib == '.':
   477             # in-place build should run without rebuilding C extensions
   494             # in-place build should run without rebuilding C extensions
   478             modulepolicy = 'allow'
   495             modulepolicy = 'allow'
   479         else:
   496         else:
   480             modulepolicy = 'c'
   497             modulepolicy = 'c'
   481         with open(os.path.join(basepath, '__modulepolicy__.py'), "w") as f:
   498 
   482             f.write('# this file is autogenerated by setup.py\n')
   499         content = b''.join([
   483             f.write('modulepolicy = b"%s"\n' % modulepolicy)
   500             b'# this file is autogenerated by setup.py\n',
       
   501             b'modulepolicy = b"%s"\n' % modulepolicy.encode('ascii'),
       
   502         ])
       
   503         write_if_changed(os.path.join(basepath, '__modulepolicy__.py'),
       
   504                          content)
   484 
   505 
   485         build_py.run(self)
   506         build_py.run(self)
   486 
   507 
   487 class buildhgextindex(Command):
   508 class buildhgextindex(Command):
   488     description = 'generate prebuilt index of hgext (for frozen package)'
   509     description = 'generate prebuilt index of hgext (for frozen package)'