Skip to content
Snippets Groups Projects
Commit 4c376e58 authored by Kai Chen's avatar Kai Chen
Browse files

add git hash to version info

parent 300f7157
No related branches found
No related tags found
No related merge requests found
from .version import __version__ from .version import __version__, short_version
__version__ = '0.5.0'
import os
import subprocess
import time
from setuptools import find_packages, setup from setuptools import find_packages, setup
...@@ -7,34 +10,99 @@ def readme(): ...@@ -7,34 +10,99 @@ def readme():
return content return content
MAJOR = 0
MINOR = 5
PATCH = 0
SUFFIX = ''
SHORT_VERSION = '{}.{}.{}{}'.format(MAJOR, MINOR, PATCH, SUFFIX)
version_file = 'mmdet/version.py'
def get_git_hash():
def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH', 'HOME']:
v = os.environ.get(k)
if v is not None:
env[k] = v
# LANGUAGE is used on win32
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.Popen(
cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
return out
try:
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
sha = out.strip().decode('ascii')
except OSError:
sha = 'unknown'
return sha
def get_hash():
if os.path.exists('.git'):
sha = get_git_hash()[:7]
elif os.path.exists(version_file):
try:
from mmdet.version import __version__
sha = __version__.split('+')[-1]
except ImportError:
raise ImportError('Unable to get git version')
else:
sha = 'unknown'
return sha
def write_version_py():
content = """# GENERATED VERSION FILE
# TIME: {}
__version__ = '{}'
short_version = '{}'
"""
sha = get_hash()
VERSION = SHORT_VERSION + '+' + sha
with open(version_file, 'w') as f:
f.write(content.format(time.asctime(), VERSION, SHORT_VERSION))
def get_version(): def get_version():
version_file = 'mmdet/version.py'
with open(version_file, 'r') as f: with open(version_file, 'r') as f:
exec(compile(f.read(), version_file, 'exec')) exec(compile(f.read(), version_file, 'exec'))
return locals()['__version__'] return locals()['__version__']
setup( if __name__ == '__main__':
name='mmdet', write_version_py()
version=get_version(), setup(
description='Open MMLab Detection Toolbox', name='mmdet',
long_description=readme(), version=get_version(),
keywords='computer vision, object detection', description='Open MMLab Detection Toolbox',
packages=find_packages(), long_description=readme(),
classifiers=[ keywords='computer vision, object detection',
'Development Status :: 4 - Beta', packages=find_packages(),
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', classifiers=[
'Operating System :: OS Independent', 'Development Status :: 4 - Beta',
'Programming Language :: Python :: 2', 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python :: 2.7', 'Operating System :: OS Independent',
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.4',
'Topic :: Utilities', 'Programming Language :: Python :: 3.5',
], 'Programming Language :: Python :: 3.6',
license='GPLv3', 'Topic :: Utilities',
setup_requires=['pytest-runner'], ],
tests_require=['pytest'], license='GPLv3',
install_requires=['numpy', 'matplotlib', 'six', 'terminaltables'], setup_requires=['pytest-runner'],
zip_safe=False) tests_require=['pytest'],
install_requires=['numpy', 'matplotlib', 'six', 'terminaltables'],
zip_safe=False)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment