PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/setup.py

https://bitbucket.org/tooooooby/tortoisehg
Python | 134 lines | 92 code | 18 blank | 24 comment | 16 complexity | bc8b2751bb87303c34edbc5156cc0e3d MD5 | raw file
Possible License(s): GPL-2.0
  1. # setup.py
  2. # A distutils setup script to install TortoiseHg in Windows and Posix
  3. # environments. In Windows, it will register TortoiseHG COM server.
  4. #
  5. # For Windows:
  6. # To build stand-alone package, use 'python setup.py py2exe' then use
  7. # InnoSetup to build the installer. By default, the installer will be
  8. # created as dist\Output\setup.exe.
  9. #
  10. import time
  11. import sys
  12. import os
  13. from distutils.core import setup
  14. def setup_windows():
  15. # Specific definitios for Windows NT-alike installations
  16. _scripts = []
  17. _data_files = []
  18. _packages = ['hggtk', 'hggtk.vis', 'hggtk.iniparse', 'tortoise']
  19. extra = {}
  20. hgextmods = []
  21. # ModuleFinder can't handle runtime changes to __path__,
  22. # but win32com uses them
  23. try:
  24. # if this doesn't work, try import modulefinder
  25. import py2exe.mf as modulefinder
  26. import win32com
  27. for p in win32com.__path__[1:]:
  28. modulefinder.AddPackagePath("win32com", p)
  29. for e in ["win32com.shell"]: #,"win32com.mapi"
  30. __import__(e)
  31. m = sys.modules[e]
  32. for p in m.__path__[1:]:
  33. modulefinder.AddPackagePath(e, p)
  34. except ImportError:
  35. # no build path setup, no worries.
  36. pass
  37. try: import py2exe
  38. except ImportError:
  39. if '--version' not in sys.argv:
  40. raise
  41. if 'py2exe' in sys.argv:
  42. # FIXME: quick hack to include installed hg extensions in py2exe binary
  43. import hgext
  44. hgextdir = os.path.dirname(hgext.__file__)
  45. hgextmods = set(["hgext." + os.path.splitext(f)[0]
  46. for f in os.listdir(hgextdir)])
  47. _data_files = [(root, [os.path.join(root, file_) for file_ in files])
  48. for root, dirs, files in os.walk('icons')]
  49. extra['windows'] = [
  50. {"script":"hgproc.py",
  51. "icon_resources": [(1, "icons/tortoise/hg.ico")]},
  52. {"script":"tracelog.py",
  53. "icon_resources": [(1, "icons/tortoise/python.ico")]}
  54. ]
  55. extra['com_server'] = ["tortoisehg"]
  56. extra['console'] = ["contrib/hg", "contrib/hgtk"]
  57. extra['options'] = {
  58. "py2exe" : {
  59. # Don't pull in all this MFC stuff used by the makepy UI.
  60. "excludes" : "pywin,pywin.dialogs,pywin.dialogs.list",
  61. # add library files to support PyGtk-based dialogs/windows
  62. # Note:
  63. # after py2exe build, copy GTK's etc and lib directories into
  64. # the dist directory created by py2exe.
  65. # also needed is the GTK's share/themes (as dist/share/themes),
  66. # for dialogs to display in MS-Windows XP theme.
  67. "includes" : "dbhash,pango,atk,pangocairo,cairo,gobject," + \
  68. ",".join(hgextmods),
  69. }
  70. }
  71. return _scripts, _packages, _data_files, extra
  72. def setup_posix():
  73. # Specific definitios for Posix installations
  74. _extra = {}
  75. _scripts = ['contrib/hgtk', 'hgproc.py']
  76. _packages = ['hggtk', 'hggtk.vis', 'hggtk.iniparse', 'tortoise']
  77. _data_files = [(os.path.join('share/pixmaps/tortoisehg', root),
  78. [os.path.join(root, file_) for file_ in files])
  79. for root, dirs, files in os.walk('icons')]
  80. _data_files += [('lib/nautilus/extensions-2.0/python',
  81. ['contrib/nautilus-thg.py'])]
  82. return _scripts, _packages, _data_files, _extra
  83. if os.name == "nt":
  84. (scripts, packages, data_files, extra) = setup_windows()
  85. else:
  86. (scripts, packages, data_files, extra) = setup_posix()
  87. # specify version string, otherwise 'hg identify' will be used:
  88. version = ''
  89. try:
  90. l = os.popen('hg id -it').read().split()
  91. while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
  92. l.pop()
  93. version = l and l[-1] or 'unknown' # latest tag or revision number
  94. if version.endswith('+'):
  95. version += time.strftime('%Y%m%d')
  96. except OSError:
  97. version = "unknown"
  98. f = file(os.path.join("hggtk", "__version__.py"), "w")
  99. f.write('# this file is autogenerated by setup.py\n')
  100. f.write('version = "%s"\n' % version)
  101. f.close()
  102. setup(name="tortoisehg",
  103. version=version,
  104. author='TK Soh',
  105. author_email='teekaysoh@gmail.com',
  106. url='http://bitbucket.org/tortoisehg/stable/',
  107. description='Windows shell extension for Mercurial VCS',
  108. license='GNU GPL2',
  109. scripts=scripts,
  110. packages=packages,
  111. data_files=data_files,
  112. **extra
  113. )