setup.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/usr/bin/env python
  2. import time
  3. import os.path as op
  4. from setuptools import setup
  5. from setuptools.command.install import install
  6. from setuptools.command.build_py import build_py
  7. version = '1.3.1'
  8. class CustomInstallCommand(install):
  9. def run(self):
  10. install.run(self)
  11. class NotInAGitRepos(Exception):
  12. pass
  13. class CustomBuildPyCommand(build_py):
  14. def git_infos(self):
  15. '''Query git about sha1 of last commit and check if there are local \
  16. modifications.'''
  17. from subprocess import Popen, PIPE
  18. import re
  19. def q(c):
  20. return Popen(c, stdout=PIPE).communicate()[0]
  21. if not op.exists('.git'):
  22. raise NotInAGitRepos()
  23. sha1 = q(['git', 'log', '--pretty=oneline', '-n1']).split()[0]
  24. sha1 = re.sub(br'[^0-9a-f]', '', sha1)
  25. sha1 = str(sha1.decode('ascii'))
  26. sstatus = q(['git', 'status', '--porcelain', '-uno'])
  27. local_modifications = bool(sstatus.strip())
  28. return sha1, local_modifications
  29. def make_info_module(self, packname, version):
  30. '''Put version and revision information into file src/setup_info.py.'''
  31. sha1, local_modifications = None, None
  32. combi = '%s_%s' % (packname, version)
  33. try:
  34. sha1, local_modifications = self.git_infos()
  35. combi += '_%s' % sha1
  36. if local_modifications:
  37. combi += '_modified'
  38. except (OSError, NotInAGitRepos):
  39. pass
  40. datestr = time.strftime('%Y-%m-%d_%H:%M:%S')
  41. combi += '_%s' % datestr
  42. module_code = '''# This module is automatically created from setup.py
  43. git_sha1 = %s
  44. local_modifications = %s
  45. version = %s
  46. long_version = %s # noqa
  47. installed_date = %s
  48. ''' % tuple([repr(x) for x in (
  49. sha1, local_modifications, version, combi, datestr)])
  50. outfile = self.get_module_outfile(
  51. self.build_lib, ['grond'], 'setup_info')
  52. dir = op.dirname(outfile)
  53. self.mkpath(dir)
  54. with open(outfile, 'w') as f:
  55. f.write(module_code)
  56. def run(self):
  57. self.make_info_module('grond', version)
  58. build_py.run(self)
  59. setup(
  60. cmdclass={
  61. 'build_py': CustomBuildPyCommand,
  62. 'install': CustomInstallCommand,
  63. },
  64. name='grond',
  65. description='A probabilistic earthquake source inversion framework. '
  66. 'Designed and crafted in Mordor.',
  67. version=version,
  68. author='The Grond Developers',
  69. author_email='info@pyrocko.org',
  70. packages=[
  71. 'grond',
  72. 'grond.apps',
  73. 'grond.targets',
  74. 'grond.targets.waveform',
  75. 'grond.targets.waveform_phase_ratio',
  76. 'grond.targets.waveform_oac',
  77. 'grond.targets.satellite',
  78. 'grond.targets.gnss_campaign',
  79. 'grond.problems',
  80. 'grond.problems.cmt',
  81. 'grond.problems.double_dc',
  82. 'grond.problems.rectangular',
  83. 'grond.problems.volume_point',
  84. 'grond.problems.vlvd',
  85. 'grond.optimisers',
  86. 'grond.optimisers.highscore',
  87. 'grond.analysers',
  88. 'grond.analysers.noise_analyser',
  89. 'grond.analysers.target_balancing',
  90. 'grond.report',
  91. 'grond.plot',
  92. 'grond.clustering',
  93. ],
  94. entry_points={
  95. 'console_scripts': [
  96. 'grond = grond.apps.grond:main',
  97. ]
  98. },
  99. package_dir={'grond': 'src'},
  100. package_data={
  101. 'grond': [
  102. 'report/app/*.html',
  103. 'report/app/favicon.png',
  104. 'report/app/templates/*.html',
  105. 'report/app/css/*.css',
  106. 'report/app/js/*.js',
  107. 'data/snippets/*.gronf',
  108. 'data/snippets/*.md',
  109. 'data/examples/*/*.*',
  110. 'data/examples/*/*/*.*',
  111. 'data/examples/*/*/grondown',
  112. ]},
  113. data_files=[],
  114. license='GPLv3',
  115. classifiers=[
  116. 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
  117. 'Development Status :: 5 - Production/Stable',
  118. 'Intended Audience :: Science/Research',
  119. 'Programming Language :: Python :: 2.7',
  120. 'Programming Language :: Python :: 3',
  121. 'Programming Language :: Python :: Implementation :: CPython',
  122. 'Operating System :: POSIX',
  123. 'Operating System :: MacOS',
  124. 'Topic :: Scientific/Engineering',
  125. 'Topic :: Scientific/Engineering :: Physics',
  126. 'Topic :: Scientific/Engineering :: Visualization',
  127. 'Topic :: Scientific/Engineering :: Information Analysis',
  128. 'Topic :: Software Development :: Libraries :: Application Frameworks',
  129. ],
  130. keywords=[
  131. 'seismology, waveform analysis, earthquake modelling, geophysics,'
  132. ' geophysical inversion'],
  133. )