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

Modify codes about version info #189

Merged
merged 9 commits into from
Sep 18, 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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ venv.bak/
.mypy_cache/

# custom
mmaction/version.py
/data
.vscode
.idea
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
**Improvements**
- Support to run a demo with a video url ([#165](https://github.com/open-mmlab/mmaction2/pull/165))
- Add tutorial for adding a new learning rate updater ([#181](https://github.com/open-mmlab/mmaction2/pull/181))
- Remove git hash in `__version__` ([#189](https://github.com/open-mmlab/mmaction2/pull/189))
- Check mmcv version ([#189](https://github.com/open-mmlab/mmaction2/pull/189))

**Bug Fixes**
- Fix the bug when using OpenCV to extract only RGB frames with original shape ([#184](https://github.com/open-mmlab/mmaction2/pull/187))
Expand Down
16 changes: 10 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@
project = 'MMAction2'
copyright = '2020, OpenMMLab'
author = 'MMAction2 Authors'
version_file = '../mmaction/version.py'


def get_version():
with open(version_file, 'r') as f:
exec(compile(f.read(), version_file, 'exec'))
return locals()['__version__']


# The full version, including alpha/beta/rc tags
with open('../mmaction/VERSION', 'r') as f:
release = f.read().strip()
release = get_version()

# -- General configuration ---------------------------------------------------

Expand All @@ -48,10 +55,7 @@
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# -- Options for HTML output -------------------------------------------------
source_suffix = {
'.rst': 'restructuredtext',
'.md': 'markdown',
}
source_suffix = {'.rst': 'restructuredtext', '.md': 'markdown'}

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
Expand Down
1 change: 0 additions & 1 deletion mmaction/VERSION

This file was deleted.

10 changes: 10 additions & 0 deletions mmaction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import mmcv
from mmcv import digit_version

from .version import __version__, short_version

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']
10 changes: 9 additions & 1 deletion mmaction/utils/collect_env.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from mmcv.utils import collect_env as collect_basic_env
from mmcv.utils import get_git_hash

import mmaction

NUM_HASHES = 7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed any more



def get_short_git_hash(num_hashes=7):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this function be moved to mmcv?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do it in a separate pr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc. @hellock

return get_git_hash()[:num_hashes]


def collect_env():
env_info = collect_basic_env()
env_info['MMAction2'] = mmaction.__version__
env_info['MMAction2'] = (
mmaction.__version__ + '+' + get_short_git_hash(NUM_HASHES))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

return env_info


Expand Down
19 changes: 19 additions & 0 deletions mmaction/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Open-MMLab. All rights reserved.

__version__ = '0.6.0'
short_version = __version__


def parse_version_info(version_str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should also go to mmcv

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc. @hellock

version_info = []
for x in version_str.split('.'):
if x.isdigit():
version_info.append(int(x))
elif x.find('rc') != -1:
patch_version = x.split('rc')
version_info.append(int(patch_version[0]))
version_info.append(f'rc{patch_version[1]}')
return tuple(version_info)


version_info = parse_version_info(__version__)
72 changes: 8 additions & 64 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,13 @@
import os
import subprocess
import time
from setuptools import find_packages, setup

version_file = 'mmaction/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 mmaction.version import __version__
sha = __version__.split('+')[-1]
except ImportError:
raise ImportError('Unable to get git version')
else:
sha = 'unknown'

return sha

def readme():
with open('README.md', encoding='utf-8') as f:
content = f.read()
return content

def write_version_py():
content = """# GENERATED VERSION FILE
# TIME: {}
__version__ = '{}'
short_version = '{}'
version_info = ({})
"""
sha = get_hash()
with open('mmaction/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)
version_file = 'mmaction/version.py'


def get_version():
Expand Down Expand Up @@ -157,12 +100,13 @@ def gen_packages_items():


if __name__ == '__main__':
write_version_py()
setup(
name='mmaction2',
version=get_version(),
description='OpenMMLab Action Understanding Toolbox and Benchmark',
maintainer='MMAction Authors',
long_description=readme(),
long_description_content_type='text/markdown',
maintainer='MMAction2 Authors',
maintainer_email='openmmlab@gmail.com',
packages=find_packages(exclude=('configs', 'tools', 'demo')),
package_data={'mmaction.ops': ['*/*.so']},
Expand Down
8 changes: 0 additions & 8 deletions tests/test_version.py

This file was deleted.

5 changes: 3 additions & 2 deletions tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from mmaction.apis import train_model
from mmaction.datasets import build_dataset
from mmaction.models import build_model
from mmaction.utils import collect_env, get_root_logger
from mmaction.utils import collect_env, get_root_logger, get_short_git_hash


def parse_args():
Expand Down Expand Up @@ -135,7 +135,8 @@ def main():
# save mmaction version, config file content and class names in
# checkpoints as meta data
cfg.checkpoint_config.meta = dict(
mmaction_version=__version__, config=cfg.text)
mmaction_version=__version__ + get_short_git_hash(),
config=cfg.text)

train_model(
model,
Expand Down