Browse Source

improved version number management

- current version number is now set in setup.py
- version number is stored during py_build into automatic module setup_info.py
- git infos and install date is also stored
- `grond version` now reports all details
priors
Sebastian Heimann 2 years ago
parent
commit
09740da1e3
4 changed files with 98 additions and 6 deletions
  1. +74
    -2
      setup.py
  2. +11
    -0
      src/apps/grond.py
  3. +12
    -3
      src/info.py
  4. +1
    -1
      src/version.py

+ 74
- 2
setup.py View File

@ -1,7 +1,14 @@
#!/usr/bin/env python
import time
import os.path as op
from setuptools import setup
from setuptools.command.install import install
from setuptools.command.build_py import build_py
version = '1.0.0-beta'
class CustomInstallCommand(install):
@ -9,8 +16,74 @@ class CustomInstallCommand(install):
install.run(self)
class NotInAGitRepos(Exception):
pass
class CustomBuildPyCommand(build_py):
def git_infos(self):
'''Query git about sha1 of last commit and check if there are local \
modifications.'''
from subprocess import Popen, PIPE
import re
def q(c):
return Popen(c, stdout=PIPE).communicate()[0]
if not op.exists('.git'):
raise NotInAGitRepos()
sha1 = q(['git', 'log', '--pretty=oneline', '-n1']).split()[0]
sha1 = re.sub(br'[^0-9a-f]', '', sha1)
sha1 = str(sha1.decode('ascii'))
sstatus = q(['git', 'status', '--porcelain', '-uno'])
local_modifications = bool(sstatus.strip())
return sha1, local_modifications
def make_info_module(self, packname, version):
'''Put version and revision information into file src/setup_info.py.'''
sha1, local_modifications = None, None
combi = '%s_%s' % (packname, version)
try:
sha1, local_modifications = self.git_infos()
combi += '_%s' % sha1
if local_modifications:
combi += '_modified'
except (OSError, NotInAGitRepos):
pass
datestr = time.strftime('%Y-%m-%d_%H:%M:%S')
combi += '_%s' % datestr
module_code = '''# This module is automatically created from setup.py
git_sha1 = %s
local_modifications = %s
version = %s
long_version = %s # noqa
installed_date = %s
''' % tuple([repr(x) for x in (
sha1, local_modifications, version, combi, datestr)])
outfile = self.get_module_outfile(
self.build_lib, ['grond'], 'setup_info')
dir = op.dirname(outfile)
self.mkpath(dir)
with open(outfile, 'w') as f:
f.write(module_code)
def run(self):
self.make_info_module('grond', version)
build_py.run(self)
setup(
cmdclass={
'build_py': CustomBuildPyCommand,
'install': CustomInstallCommand,
},
@ -19,7 +92,7 @@ setup(
description='A probabilistic earthquake source inversion framework. '
'Designed and crafted in Mordor.',
version='1.0',
version=version,
author='The Grond Developers',
@ -47,7 +120,6 @@ setup(
'grond.plot',
'grond.clustering',
],
python_requires='>=3.5',
entry_points={
'console_scripts': [
'grond = grond.apps.grond:main',


+ 11
- 0
src/apps/grond.py View File

@ -1276,6 +1276,9 @@ def command_version(args):
parser.add_option(
'--short', dest='short', action='store_true',
help='only print Grond\'s version number')
parser.add_option(
'--failsafe', dest='failsafe', action='store_true',
help='do not get irritated when some dependencies are missing')
parser, options, args = cl_parse('version', args, setup)
@ -1283,6 +1286,11 @@ def command_version(args):
print(grond.__version__)
return
elif not options.failsafe:
from grond import info
print(info.version_info())
return
print("grond: %s" % grond.__version__)
try:
@ -1320,6 +1328,9 @@ def command_version(args):
import sys
print('python: %s.%s.%s' % sys.version_info[:3])
if not options.failsafe:
die('fell back to failsafe version printing')
if __name__ == '__main__':
main()

+ 12
- 3
src/info.py View File

@ -1,12 +1,17 @@
from pyrocko.guts import Object, String, Dict
from pyrocko.guts import Object, String, Dict, Bool
from grond.version import __version__
from grond.setup_info import git_sha1, local_modifications, \
version, long_version, installed_date
guts_prefix = 'grond'
class VersionInfo(Object):
grond_version = String.T(yamlstyle="'")
grond_long_version = String.T(yamlstyle="'")
git_sha1 = String.T(optional=True, yamlstyle="'")
local_modifications = Bool.T(optional=True)
installed_date = String.T(optional=True, yamlstyle="'")
dependencies = Dict.T(String.T(), String.T(yamlstyle="'"))
@ -49,7 +54,11 @@ def version_info():
deps['python'] = '%s.%s.%s' % sys.version_info[:3]
vi = VersionInfo(
grond_version=__version__,
grond_version=version,
grond_long_version=long_version,
git_sha1=git_sha1,
local_modifications=local_modifications,
installed_date=installed_date,
dependencies=deps)
return vi


+ 1
- 1
src/version.py View File

@ -1 +1 @@
__version__ = '1.0.0-beta'
from grond.setup_info import version as __version__ # noqa

Loading…
Cancel
Save