Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified version files. #135

Merged
merged 5 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------

Expand Down
1 change: 0 additions & 1 deletion mmpose/VERSION

This file was deleted.

14 changes: 12 additions & 2 deletions mmpose/__init__.py
Original file line number Diff line number Diff line change
@@ -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']
7 changes: 6 additions & 1 deletion mmpose/utils/collect_env.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
7 changes: 7 additions & 0 deletions mmpose/version.py
Original file line number Diff line number Diff line change
@@ -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__)
2 changes: 1 addition & 1 deletion requirements/readthedocs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mmcv
mmcv>=1.1.1
torch
torchvision
2 changes: 1 addition & 1 deletion requirements/runtime.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
json_tricks
matplotlib
mmcv
mmcv>=1.1.1
munkres
numpy
opencv-python
Expand Down
66 changes: 1 addition & 65 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import os
import subprocess
import time
from setuptools import find_packages, setup


Expand All @@ -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'))
Expand Down Expand Up @@ -164,14 +100,14 @@ def gen_packages_items():


if __name__ == '__main__':
write_version_py()
setup(
name='mmpose',
version=get_version(),
description='OpenMMLab Pose Estimation Toolbox and Benchmark.',
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=[
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
2 changes: 1 addition & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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(
Expand Down