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

[Enhance] Support for installing minimal runtime dependencies #1362

Merged
merged 13 commits into from
Oct 8, 2023
Merged
31 changes: 31 additions & 0 deletions .circleci/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@ jobs:
name: Run unit tests
command: pytest tests/test_config tests/test_registry tests/test_fileio tests/test_logging tests/test_utils --ignore=tests/test_utils/test_dl_utils

build_lite:
parameters:
# The python version must match available image tags in
# https://circleci.com/developer/images/image/cimg/python
python:
type: string
default: "3.7.4"
docker:
- image: cimg/python:<< parameters.python >>
resource_class: large
steps:
- checkout
- run:
name: Upgrade pip
command: |
pip install pip --upgrade
pip --version
- run:
name: Build MMEngine from source
command: MMENGINE_LITE=1 pip install -e . -v
- run:
name: Install unit tests dependencies
command: pip install -r requirements/tests.txt
- run:
name: Run unit tests
command: pytest tests/test_config tests/test_registry tests/test_logging tests/test_utils --ignore=tests/test_utils/test_dl_utils

build_cpu:
parameters:
# The python version must match available image tags in
Expand Down Expand Up @@ -217,6 +244,10 @@ workflows:
branches:
ignore:
- main
- build_lite:
name: build lite
requires:
- lint
- build_without_torch:
name: build without torch
requires:
Expand Down
9 changes: 9 additions & 0 deletions docs/en/get_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@

## Install MMEngine

:::{note}
If you only want to use the fileio, registry, and config modules in MMEngine, you can set the `MMENGINE_LITE` environment variable, which will only install the few third-party library dependencies that are necessary (e.g., it will not install opencv, matplotlib):

```bash
MMENGINE_LITE=1 pip install mmengine
```

:::

### Install with mim

[mim](https://github.com/open-mmlab/mim) is a package management tool for OpenMMLab projects, which can be used to install the OpenMMLab project easily.
Expand Down
9 changes: 9 additions & 0 deletions docs/zh_cn/get_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@

## 安装 MMEngine

:::{note}
如果你只想使用 MMEngine 中的 fileio、registry 和 config 模块,你可以设置 `MMENGINE_LITE` 环境变量,它只会安装必须的几个第三方库依赖(例如不会安装 opencv、matplotlib):

```bash
MMENGINE_LITE=1 pip install mmengine
```

:::

### 使用 mim 安装

[mim](https://github.com/open-mmlab/mim) 是 OpenMMLab 项目的包管理工具,使用它可以很方便地安装 OpenMMLab 项目。
Expand Down
7 changes: 7 additions & 0 deletions requirements/runtime_lite.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
addict
numpy
pyyaml
regex;sys_platform=='win32'
rich
termcolor
yapf
32 changes: 18 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
from setuptools import find_packages, setup # type: ignore

Expand Down Expand Up @@ -106,20 +107,23 @@ def gen_packages_items():
return packages


install_requires = parse_requirements()
try:
# OpenCV installed via conda.
import cv2 # NOQA: F401
major, minor, *rest = cv2.__version__.split('.')
if int(major) < 3:
raise RuntimeError(
f'OpenCV >=3 is required but {cv2.__version__} is installed')
except ImportError:
# If first not installed install second package
CHOOSE_INSTALL_REQUIRES = [('opencv-python-headless>=3',
'opencv-python>=3')]
for main, secondary in CHOOSE_INSTALL_REQUIRES:
install_requires.append(choose_requirement(main, secondary))
if int(os.getenv('MMENGINE_LITE', '0')) == 1:
install_requires = parse_requirements('requirements/runtime_lite.txt')
else:
install_requires = parse_requirements()
try:
# OpenCV installed via conda.
import cv2 # NOQA: F401
major, minor, *rest = cv2.__version__.split('.')
if int(major) < 3:
raise RuntimeError(
f'OpenCV >=3 is required but {cv2.__version__} is installed')
except ImportError:
# If first not installed install second package
CHOOSE_INSTALL_REQUIRES = [('opencv-python-headless>=3',
'opencv-python>=3')]
for main, secondary in CHOOSE_INSTALL_REQUIRES:
install_requires.append(choose_requirement(main, secondary))

setup(
name='mmengine',
Expand Down