diff --git a/.gitignore b/.gitignore index 722a50e523..4eba3d0d8e 100644 --- a/.gitignore +++ b/.gitignore @@ -132,3 +132,4 @@ work_dirs/ # avoid soft links created by MIM mmaction/configs/* mmaction/tools/* +mmaction/.mim diff --git a/MANIFEST.in b/MANIFEST.in index 3dbdf42ba6..258c4e016b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ -include mmaction/model-index.yml -recursive-include mmaction/configs *.py *.yml -recursive-include mmaction/tools *.sh *.py +include mmaction/.mim/model-index.yml +recursive-include mmaction/.mim/configs *.py *.yml +recursive-include mmaction/.mim/tools *.sh *.py diff --git a/README.md b/README.md index 9443603366..31fa544e4e 100644 --- a/README.md +++ b/README.md @@ -257,6 +257,7 @@ We wish that the toolbox and benchmark could serve the growing research communit ## Projects in OpenMMLab - [MMCV](https://github.com/open-mmlab/mmcv): OpenMMLab foundational library for computer vision. +- [MIM](https://github.com/open-mmlab/mim): MIM Installs OpenMMLab Packages. - [MMClassification](https://github.com/open-mmlab/mmclassification): OpenMMLab image classification toolbox and benchmark. - [MMDetection](https://github.com/open-mmlab/mmdetection): OpenMMLab detection toolbox and benchmark. - [MMDetection3D](https://github.com/open-mmlab/mmdetection3d): OpenMMLab's next-generation platform for general 3D object detection. diff --git a/README_zh-CN.md b/README_zh-CN.md index ac7a5c1107..d39bbac68a 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -227,6 +227,7 @@ MMAction2 是一款由不同学校和公司共同贡献的开源项目。我们 ## OpenMMLab 的其他项目 - [MMCV](https://github.com/open-mmlab/mmcv): OpenMMLab 计算机视觉基础库 +- [MIM](https://github.com/open-mmlab/mim): MIM 是 OpenMMlab 项目、算法、模型的统一入口 - [MMClassification](https://github.com/open-mmlab/mmclassification): OpenMMLab 图像分类工具箱与测试基准 - [MMDetection](https://github.com/open-mmlab/mmdetection): OpenMMLab 检测工具箱与测试基准 - [MMDetection3D](https://github.com/open-mmlab/mmdetection3d): OpenMMLab 新一代通用3D目标检测平台 diff --git a/setup.py b/setup.py index 6477cb0454..f23072f05f 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,8 @@ +import os +import os.path as osp +import shutil +import sys +import warnings from setuptools import find_packages, setup @@ -94,7 +99,56 @@ def gen_packages_items(): return packages +def add_mim_extention(): + """Add extra files that are required to support MIM into the package. + + These files will be added by creating a symlink to the originals if the + package is installed in `editable` mode (e.g. pip install -e .), or by + copying from the originals otherwise. + """ + + # parse installment mode + if 'develop' in sys.argv: + # installed by `pip install -e .` + mode = 'symlink' + elif 'sdist' in sys.argv or 'bdist_wheel' in sys.argv: + # installed by `pip install .` + # or create source distribution by `python setup.py sdist` + mode = 'copy' + else: + return + + filenames = ['tools', 'configs', 'model-index.yml'] + repo_path = osp.dirname(__file__) + mim_path = osp.join(repo_path, 'mmaction', '.mim') + os.makedirs(mim_path, exist_ok=True) + + for filename in filenames: + if osp.exists(filename): + src_path = osp.join(repo_path, filename) + tar_path = osp.join(mim_path, filename) + + if osp.isfile(tar_path) or osp.islink(tar_path): + os.remove(tar_path) + elif osp.isdir(tar_path): + shutil.rmtree(tar_path) + + if mode == 'symlink': + src_relpath = osp.relpath(src_path, osp.dirname(tar_path)) + os.symlink(src_relpath, tar_path) + elif mode == 'copy': + if osp.isfile(src_path): + shutil.copyfile(src_path, tar_path) + elif osp.isdir(src_path): + shutil.copytree(src_path, tar_path) + else: + warnings.warn(f'Cannot copy file {src_path}.') + else: + raise ValueError(f'Invalid mode {mode}') + + if __name__ == '__main__': + add_mim_extention() setup( name='mmaction2', version=get_version(),