setup.py
changeset 8547 548fd7a05373
parent 8494 97184c58d0b8
child 8548 3ccbe42ff72f
equal deleted inserted replaced
8546:a33d19dcf906 8547:548fd7a05373
    24     import zlib
    24     import zlib
    25 except:
    25 except:
    26     raise SystemExit(
    26     raise SystemExit(
    27         "Couldn't import standard zlib (incomplete Python install).")
    27         "Couldn't import standard zlib (incomplete Python install).")
    28 
    28 
    29 import os, time
    29 import os, subprocess, time
    30 import shutil
    30 import shutil
    31 import tempfile
    31 import tempfile
    32 from distutils.core import setup, Extension
    32 from distutils.core import setup, Extension
    33 from distutils.dist import Distribution
    33 from distutils.dist import Distribution
    34 from distutils.command.install_data import install_data
    34 from distutils.command.install_data import install_data
    95     extra['console'] = ['hg']
    95     extra['console'] = ['hg']
    96 
    96 
    97 except ImportError:
    97 except ImportError:
    98     pass
    98     pass
    99 
    99 
   100 if os.path.exists('.hg'):
   100 if os.path.isdir('.hg'):
   101     # execute hg out of this directory with a custom environment which
   101     # execute hg out of this directory with a custom environment which
   102     # includes the pure Python modules in mercurial/pure
   102     # includes the pure Python modules in mercurial/pure
   103     pypath = os.environ.get('PYTHONPATH', '')
   103     pypath = os.environ.get('PYTHONPATH', '')
   104     purepath = os.path.join('mercurial', 'pure')
   104     purepath = os.path.join('mercurial', 'pure')
   105     os.environ['PYTHONPATH'] = os.pathsep.join(['mercurial', purepath, pypath])
   105     os.environ['PYTHONPATH'] = os.pathsep.join(['mercurial', purepath, pypath])
   106     os.environ['HGRCPATH'] = '' # do not read any config file
   106     os.environ['HGRCPATH'] = '' # do not read any config file
   107     cmd = '%s hg id -it' % sys.executable
   107     cmd = [sys.executable, 'hg', 'id', '-i', '-t']
   108     version = None
   108     version = None
   109 
   109 
   110     try:
   110     l, e = subprocess.Popen(cmd, stdout=subprocess.PIPE,
   111         l = os.popen(cmd).read().split()
   111                             stderr=subprocess.PIPE).communicate()
   112     except OSError, e:
       
   113         print "warning: could not establish Mercurial version: %s" % e
       
   114 
       
   115     os.environ['PYTHONPATH'] = pypath
   112     os.environ['PYTHONPATH'] = pypath
   116 
   113 
   117     while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
   114     if e:
   118         l.pop()
   115         sys.stderr.write('warning: could not establish Mercurial version: %s'
   119     if l:
   116                          % e)
   120         version = l[-1] # latest tag or revision number
   117     else:
   121         if version.endswith('+'):
   118         l = l.split()
   122             version += time.strftime('%Y%m%d')
   119         while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
       
   120             l.pop()
       
   121         if l:
       
   122             version = l[-1] # latest tag or revision number
       
   123             if version.endswith('+'):
       
   124                 version += time.strftime('%Y%m%d')
   123 
   125 
   124     if version:
   126     if version:
   125         f = file("mercurial/__version__.py", "w")
   127         f = file("mercurial/__version__.py", "w")
   126         f.write('# this file is autogenerated by setup.py\n')
   128         f.write('# this file is autogenerated by setup.py\n')
   127         f.write('version = "%s"\n' % version)
   129         f.write('version = "%s"\n' % version)