diff --git a/docs/conf.py b/docs/conf.py index 6c199bcda5..ac2423cf6e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -23,8 +23,16 @@ author = 'MMPose Authors' # The full version, including alpha/beta/rc tags -with open('../mmpose/VERSION', 'r') as f: - release = f.read().strip() +version_file = '../mmpose/version.py' + + +def get_version(): + with open(version_file, 'r') as f: + exec(compile(f.read(), version_file, 'exec')) + return locals()['__version__'] + + +release = get_version() # -- General configuration --------------------------------------------------- diff --git a/mmpose/VERSION b/mmpose/VERSION deleted file mode 100644 index a918a2aa18..0000000000 --- a/mmpose/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.6.0 diff --git a/mmpose/__init__.py b/mmpose/__init__.py index 1c4f7e8fcc..933963b7fe 100644 --- a/mmpose/__init__.py +++ b/mmpose/__init__.py @@ -1,3 +1,13 @@ -from .version import __version__, short_version +import mmcv +from mmcv import digit_version -__all__ = ['__version__', 'short_version'] +from .version import __version__, short_version, version_info + +mmcv_minimum_version = '1.1.1' +mmcv_version = digit_version(mmcv.__version__) + +assert digit_version(mmcv_minimum_version) <= mmcv_version, \ + f'MMCV=={mmcv.__version__} is used but incompatible. ' \ + f'Please install mmcv>={mmcv_minimum_version}.' + +__all__ = ['__version__', 'short_version', 'version_info'] diff --git a/mmpose/utils/collect_env.py b/mmpose/utils/collect_env.py index ebb418eb3b..54f99fb0bd 100644 --- a/mmpose/utils/collect_env.py +++ b/mmpose/utils/collect_env.py @@ -1,11 +1,16 @@ from mmcv.utils import collect_env as collect_basic_env +from mmcv.utils import get_git_hash import mmpose +def get_short_git_hash(num_hashes=7): + return get_git_hash()[:num_hashes] + + def collect_env(): env_info = collect_basic_env() - env_info['MMPose'] = mmpose.__version__ + env_info['MMPose'] = (mmpose.__version__ + '+' + get_short_git_hash()) return env_info diff --git a/mmpose/version.py b/mmpose/version.py new file mode 100644 index 0000000000..b2be22b6d3 --- /dev/null +++ b/mmpose/version.py @@ -0,0 +1,7 @@ +# Copyright (c) Open-MMLab. All rights reserved. +from mmcv import parse_version_info + +__version__ = '0.6.0' +short_version = __version__ + +version_info = parse_version_info(__version__) diff --git a/requirements/readthedocs.txt b/requirements/readthedocs.txt index 0542bfce6d..00d77ea23d 100644 --- a/requirements/readthedocs.txt +++ b/requirements/readthedocs.txt @@ -1,3 +1,3 @@ -mmcv +mmcv>=1.1.1 torch torchvision diff --git a/requirements/runtime.txt b/requirements/runtime.txt index 61ecaffa2d..f8a54b18af 100644 --- a/requirements/runtime.txt +++ b/requirements/runtime.txt @@ -1,6 +1,6 @@ json_tricks matplotlib -mmcv +mmcv>=1.1.1 munkres numpy opencv-python diff --git a/setup.py b/setup.py index e7f022655c..e891c203f5 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,3 @@ -import os -import subprocess -import time from setuptools import find_packages, setup @@ -13,67 +10,6 @@ def readme(): version_file = 'mmpose/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 mmpose.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 = '{}' -version_info = ({}) -""" - sha = get_hash() - with open('mmpose/VERSION', 'r') as f: - SHORT_VERSION = f.read().strip() - VERSION_INFO = ', '.join( - [x if x.isdigit() else f'"{x}"' for x in SHORT_VERSION.split('.')]) - VERSION = SHORT_VERSION + '+' + sha - - version_file_str = content.format(time.asctime(), VERSION, SHORT_VERSION, - VERSION_INFO) - with open(version_file, 'w') as f: - f.write(version_file_str) - - def get_version(): with open(version_file, 'r') as f: exec(compile(f.read(), version_file, 'exec')) @@ -164,7 +100,6 @@ def gen_packages_items(): if __name__ == '__main__': - write_version_py() setup( name='mmpose', version=get_version(), @@ -172,6 +107,7 @@ def gen_packages_items(): maintainer='MMPose Authors', maintainer_email='openmmlab@gmail.com', long_description=readme(), + long_description_content_type='text/markdown', packages=find_packages(exclude=('configs', 'tools', 'demo')), package_data={'mmpose.ops': ['*/*.so']}, classifiers=[ diff --git a/tests/test_utils.py b/tests/test_utils.py index 6713c58d6a..7057dbedb0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -9,9 +9,9 @@ def test_collect_env(): env_info = collect_env() - assert env_info['PyTorch'] == torch.__version__ assert env_info['TorchVision'] == torchvision.__version__ assert env_info['OpenCV'] == cv2.__version__ assert env_info['MMCV'] == mmcv.__version__ - assert env_info['MMPose'] == mmpose.__version__ + assert '+' in env_info['MMPose'] + assert mmpose.__version__ in env_info['MMPose'] diff --git a/tests/test_version.py b/tests/test_version.py index 95fb2c362d..28dcdcaddd 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -5,4 +5,4 @@ def test_version(): version = mmpose.__version__ assert isinstance(version, str) assert isinstance(mmpose.short_version, str) - assert mmpose.short_version in version and '+' in version + assert mmpose.short_version in version diff --git a/tools/train.py b/tools/train.py index 40f8b01d2a..7b9fcc4912 100644 --- a/tools/train.py +++ b/tools/train.py @@ -13,7 +13,7 @@ from mmpose.apis import train_model from mmpose.datasets import build_dataset from mmpose.models import build_posenet -from mmpose.utils import collect_env, get_root_logger +from mmpose.utils import collect_env, get_root_logger, get_short_git_hash def parse_args(): @@ -138,7 +138,7 @@ def main(): # save mmpose version, config file content # checkpoints as meta data cfg.checkpoint_config.meta = dict( - mmpose_version=__version__, + mmpose_version=__version__ + get_short_git_hash(), config=cfg.pretty_text, ) train_model(