Skip to content

Commit a8113ab

Browse files
authored
Add github action file (open-mmlab#94)
Add github action file (open-mmlab#94)
1 parent ba394b7 commit a8113ab

File tree

8 files changed

+203
-17
lines changed

8 files changed

+203
-17
lines changed

.github/workflows/build.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
env:
10+
CUDA: 10.1.105-1
11+
CUDA_SHORT: 10.1
12+
UBUNTU_VERSION: ubuntu1804
13+
FORCE_CUDA: 1
14+
strategy:
15+
matrix:
16+
python-version: [3.6, 3.7]
17+
torch: [1.3.0, 1.5.0]
18+
include:
19+
- torch: 1.3.0
20+
torchvision: 0.4.2
21+
cuda_arch: "6.0"
22+
- torch: 1.5.0
23+
torchvision: 0.6.0
24+
cuda_arch: "7.0"
25+
26+
steps:
27+
- uses: actions/checkout@v2
28+
- name: Set up Python ${{ matrix.python-version }}
29+
uses: actions/setup-python@v2
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
- name: Install CUDA
33+
run: |
34+
export INSTALLER=cuda-repo-${UBUNTU_VERSION}_${CUDA}_amd64.deb
35+
wget http://developer.download.nvidia.com/compute/cuda/repos/${UBUNTU_VERSION}/x86_64/${INSTALLER}
36+
sudo dpkg -i ${INSTALLER}
37+
wget https://developer.download.nvidia.com/compute/cuda/repos/${UBUNTU_VERSION}/x86_64/7fa2af80.pub
38+
sudo apt-key add 7fa2af80.pub
39+
sudo apt update -qq
40+
sudo apt install -y cuda-${CUDA_SHORT/./-} cuda-cufft-dev-${CUDA_SHORT/./-}
41+
sudo apt clean
42+
export CUDA_HOME=/usr/local/cuda-${CUDA_SHORT}
43+
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${CUDA_HOME}/include:${LD_LIBRARY_PATH}
44+
export PATH=${CUDA_HOME}/bin:${PATH}
45+
sudo apt-get install -y ninja-build
46+
- name: Install Pillow
47+
run: pip install Pillow==6.2.2
48+
if: ${{matrix.torchvision < 0.5}}
49+
- name: Install PyTorch
50+
run: pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}}
51+
- name: Install mmedit dependencies
52+
run: |
53+
pip install mmcv-full==latest+torch${{matrix.torch}}+cu101 -f https://openmmlab.oss-accelerate.aliyuncs.com/mmcv/dist/index.html
54+
pip install -r requirements.txt
55+
- name: Lint with flake8
56+
run: flake8 .
57+
- name: Lint with isort
58+
run: isort --recursive --check-only --diff mmedit/ tools/ tests/
59+
- name: Format with yapf
60+
run: yapf -r -d mmedit/ tools/ configs/ tests/
61+
- name: Check docstring
62+
run: interrogate -v --ignore-init-method --ignore-module --ignore-nested-functions --ignore-regex "__repr__" --fail-under 80 mmedit
63+
- name: Build and install
64+
env:
65+
CUDA_ARCH: ${{matrix.cuda_arch}}
66+
run: |
67+
rm -rf .eggs
68+
python setup.py check -m -s
69+
TORCH_CUDA_ARCH_LIST=${CUDA_ARCH} python setup.py build_ext --inplace
70+
- name: Run unittests and generate coverage report
71+
run: |
72+
coverage run --branch --source mmedit -m pytest tests/
73+
coverage xml
74+
coverage report -m
75+
- name: Upload coverage to Codecov
76+
uses: codecov/[email protected]
77+
with:
78+
file: ./coverage.xml
79+
flags: unittests
80+
env_vars: OS,PYTHON
81+
name: codecov-umbrella
82+
fail_ci_if_error: false

mmedit/models/common/linear_module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def forward(self, x, activate=True):
7272
"""Foward Function.
7373
7474
Args:
75-
x (torch.Tensor): Input tensor with shape of (n, \*, c). Same as
76-
``torch.nn.Linear``.
75+
x (torch.Tensor): Input tensor with shape of (n, \*, # noqa: W605
76+
c). Same as ``torch.nn.Linear``.
7777
activate (bool, optional): Whether to use activation layer.
7878
Defaults to True.
7979

mmedit/models/common/mask_conv_module.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ def __init__(self, *args, **kwargs):
4040

4141
self.init_weights()
4242

43-
def forward(self, x, mask=None, activate=True, norm=True,
43+
def forward(self,
44+
x,
45+
mask=None,
46+
activate=True,
47+
norm=True,
4448
return_mask=True):
4549
"""Forward function for partial conv2d.
4650

requirements.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
lmdb
2-
mmcv-full>=1.0.0
3-
scikit-image
4-
yapf
1+
-r requirements/runtime.txt
2+
-r requirements/tests.txt

requirements/runtime.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lmdb
2+
mmcv-full>=1.0.0
3+
scikit-image
4+
yapf

requirements/tests.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
codecov
2+
flake8
3+
interrogate
4+
isort==4.3.21
5+
pytest
6+
pytest-cov
7+
pytest-runner
8+
ubelt

setup.py

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import subprocess
33
import time
44
from functools import partial
5+
from setuptools import find_packages, setup
56

67
import torch
7-
from setuptools import find_packages, setup
88

99

1010
def _get_extension():
@@ -94,20 +94,94 @@ def get_version():
9494
return locals()['__version__']
9595

9696

97-
def get_requirements(filename='requirements.txt'):
98-
here = os.path.dirname(os.path.realpath(__file__))
99-
with open(os.path.join(here, filename), 'r') as f:
100-
requires = [line.replace('\n', '') for line in f.readlines()]
101-
return requires
97+
def parse_requirements(fname='requirements.txt', with_version=True):
98+
"""Parse the package dependencies listed in a requirements file but strips
99+
specific versioning information.
100+
101+
Args:
102+
fname (str): path to requirements file
103+
with_version (bool, default=False): if True include version specs
104+
105+
Returns:
106+
List[str]: list of requirements items
107+
108+
CommandLine:
109+
python -c "import setup; print(setup.parse_requirements())"
110+
"""
111+
import sys
112+
from os.path import exists
113+
import re
114+
require_fpath = fname
115+
116+
def parse_line(line):
117+
"""Parse information from a line in a requirements text file."""
118+
if line.startswith('-r '):
119+
# Allow specifying requirements in other files
120+
target = line.split(' ')[1]
121+
for info in parse_require_file(target):
122+
yield info
123+
else:
124+
info = {'line': line}
125+
if line.startswith('-e '):
126+
info['package'] = line.split('#egg=')[1]
127+
else:
128+
# Remove versioning from the package
129+
pat = '(' + '|'.join(['>=', '==', '>']) + ')'
130+
parts = re.split(pat, line, maxsplit=1)
131+
parts = [p.strip() for p in parts]
132+
133+
info['package'] = parts[0]
134+
if len(parts) > 1:
135+
op, rest = parts[1:]
136+
if ';' in rest:
137+
# Handle platform specific dependencies
138+
# http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies
139+
version, platform_deps = map(str.strip,
140+
rest.split(';'))
141+
info['platform_deps'] = platform_deps
142+
else:
143+
version = rest # NOQA
144+
info['version'] = (op, version)
145+
yield info
146+
147+
def parse_require_file(fpath):
148+
with open(fpath, 'r') as f:
149+
for line in f.readlines():
150+
line = line.strip()
151+
if line and not line.startswith('#'):
152+
for info in parse_line(line):
153+
yield info
154+
155+
def gen_packages_items():
156+
if exists(require_fpath):
157+
for info in parse_require_file(require_fpath):
158+
parts = [info['package']]
159+
if with_version and 'version' in info:
160+
parts.extend(info['version'])
161+
if not sys.version.startswith('3.4'):
162+
# apparently package_deps are broken in 3.4
163+
platform_deps = info.get('platform_deps')
164+
if platform_deps is not None:
165+
parts.append(';' + platform_deps)
166+
item = ''.join(parts)
167+
yield item
168+
169+
packages = list(gen_packages_items())
170+
return packages
102171

103172

104173
if __name__ == '__main__':
105174
write_version_py()
106175
setup(
107176
name='mmedit',
108177
version=get_version(),
109-
description='Image and Video Editing Toolbox',
178+
description='Open MMLab Image and Video Editing Toolbox and Benchmark',
110179
long_description=readme(),
180+
maintainer='OpenMMLab',
181+
maintainer_email='[email protected]',
182+
keywords='computer vision, inpainting, matting, '
183+
'super-resolution, generation',
184+
url='https://github.com/open-mmlab/mmediting',
111185
packages=find_packages(exclude=('configs', 'tools', 'demo')),
112186
classifiers=[
113187
'Development Status :: 4 - Beta',
@@ -119,7 +193,11 @@ def get_requirements(filename='requirements.txt'):
119193
],
120194
license='Apache License 2.0',
121195
setup_requires=['pytest-runner'],
122-
tests_require=['pytest'],
123-
install_requires=get_requirements(),
196+
tests_require=parse_requirements('requirements/tests.txt'),
197+
install_requires=parse_requirements('requirements/runtime.txt'),
198+
extras_require={
199+
'all': parse_requirements('requirements.txt'),
200+
'tests': parse_requirements('requirements/tests.txt'),
201+
},
124202
cmdclass={'build_ext': BuildExtension},
125203
zip_safe=False)

tests/test_datasets.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os.path as osp
22
from pathlib import Path
3-
from unittest.mock import mock_open, patch
3+
from unittest.mock import patch
44

55
import numpy as np
66
import pytest
@@ -13,6 +13,18 @@
1313
from torch.utils.data import Dataset
1414

1515

16+
def mock_open(*args, **kargs):
17+
"""unittest.mock_open wrapper.
18+
19+
unittest.mock_open doesn't support iteration. Wrap it to fix this bug.
20+
Reference: https://stackoverflow.com/a/41656192
21+
"""
22+
import unittest
23+
f_open = unittest.mock.mock_open(*args, **kargs)
24+
f_open.return_value.__iter__ = lambda self: iter(self.readline, '')
25+
return f_open
26+
27+
1628
def check_keys_contain(result_keys, target_keys):
1729
"""Check if all elements in target_keys is in result_keys."""
1830
return set(target_keys).issubset(set(result_keys))

0 commit comments

Comments
 (0)