add mim support (#394)

pull/395/head^2
Tong Gao 2021-08-04 14:21:41 +08:00 committed by GitHub
parent 68ec3f5519
commit 72a5c31577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 3 deletions

1
.gitignore vendored
View File

@ -137,5 +137,6 @@ log.txt
workspace.code-workspace
results
mmocr/core/font.TTF
mmocr/.mim
workdirs/
.history/

View File

@ -1,4 +1,4 @@
include requirements/*.txt
include mmocr/model-index.yml
recursive-include mmocr/configs *.py *.yml
recursive-include mmocr/tools *.sh *.py
include mmocr/.mim/model-index.yml
recursive-include mmocr/.mim/configs *.py *.yml
recursive-include mmocr/.mim/tools *.sh *.py

View File

@ -128,6 +128,7 @@ We hope the toolbox and benchmark could serve the growing research community by
## 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.

View File

@ -127,6 +127,7 @@ MMOCR 是一款由来自不同高校和企业的研发人员共同参与贡献
- [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目标检测平台

View File

@ -1,5 +1,8 @@
import os
import os.path as osp
import shutil
import sys
import warnings
from setuptools import find_packages, setup
@ -13,6 +16,54 @@ version_file = 'mmocr/version.py'
is_windows = sys.platform == 'win32'
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, 'mmocr', '.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}')
def get_version():
with open(version_file, 'r') as f:
exec(compile(f.read(), version_file, 'exec'))
@ -99,6 +150,7 @@ def parse_requirements(fname='requirements.txt', with_version=True):
if __name__ == '__main__':
add_mim_extention()
library_dirs = [
lp for lp in os.environ.get('LD_LIBRARY_PATH', '').split(':')
if len(lp) > 1