Skip to content

Commit 0777b51

Browse files
authored
Add CircleCI job for python lint (#2056)
* Add CircleCI job for python lint * Break lint * Fix * Fix lint * Re-enable all tests and remove travis python lint
1 parent dcfcc86 commit 0777b51

File tree

10 files changed

+50
-21
lines changed

10 files changed

+50
-21
lines changed

.circleci/config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ jobs:
7676
python .circleci/regenerate.py
7777
git diff --exit-code || (echo ".circleci/config.yml not in sync with config.yml.in! Run .circleci/regenerate.py to update config"; exit 1)
7878
79+
80+
python_lint:
81+
docker:
82+
- image: circleci/python:3.7
83+
steps:
84+
- checkout
85+
- run:
86+
command: |
87+
pip install --user --progress-bar off flake8 typing
88+
flake8 .
89+
7990
binary_linux_wheel:
8091
<<: *binary_common
8192
docker:
@@ -509,6 +520,8 @@ workflows:
509520
name: torchvision_win_py3.6_cu101
510521
python_version: "3.6"
511522
cu_version: "cu101"
523+
- python_lint
524+
512525

513526
nightly:
514527
jobs:

.circleci/config.yml.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ jobs:
7676
python .circleci/regenerate.py
7777
git diff --exit-code || (echo ".circleci/config.yml not in sync with config.yml.in! Run .circleci/regenerate.py to update config"; exit 1)
7878

79+
80+
python_lint:
81+
docker:
82+
- image: circleci/python:3.7
83+
steps:
84+
- checkout
85+
- run:
86+
command: |
87+
pip install --user --progress-bar off flake8 typing
88+
flake8 .
89+
7990
binary_linux_wheel:
8091
<<: *binary_common
8192
docker:
@@ -311,6 +322,8 @@ workflows:
311322
name: torchvision_win_py3.6_cu101
312323
python_version: "3.6"
313324
cu_version: "cu101"
325+
- python_lint
326+
314327

315328
nightly:
316329
{%- endif %}

.travis.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ matrix:
1515
before_install: skip
1616
install: skip
1717
script: ./travis-scripts/run-clang-format/run-clang-format.py -r torchvision/csrc
18-
- env: LINT_CHECK
19-
python: "3.6"
20-
install: pip install flake8 typing
21-
script: flake8 .circleci
22-
after_success: []
2318
- python: "3.6"
2419
env: IMAGE_BACKEND=Pillow-SIMD
2520
- python: "3.6"

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ def get_extensions():
9595
includes="torchvision/csrc/cuda/*",
9696
show_detailed=True,
9797
is_pytorch_extension=True,
98-
)
98+
)
9999
source_cuda = glob.glob(os.path.join(extensions_dir, 'hip', '*.hip'))
100-
## Copy over additional files
100+
# Copy over additional files
101101
shutil.copy("torchvision/csrc/cuda/cuda_helpers.h", "torchvision/csrc/hip/cuda_helpers.h")
102102
shutil.copy("torchvision/csrc/cuda/vision_cuda.h", "torchvision/csrc/hip/vision_cuda.h")
103103

@@ -122,7 +122,8 @@ def get_extensions():
122122
define_macros = []
123123

124124
extra_compile_args = {}
125-
if (torch.cuda.is_available() and ((CUDA_HOME is not None) or is_rocm_pytorch)) or os.getenv('FORCE_CUDA', '0') == '1':
125+
if (torch.cuda.is_available() and ((CUDA_HOME is not None) or is_rocm_pytorch)) \
126+
or os.getenv('FORCE_CUDA', '0') == '1':
126127
extension = CUDAExtension
127128
sources += source_cuda
128129
if not is_rocm_pytorch:

test/fakedata_generation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,14 @@ def _make_mat(file):
253253

254254
yield root
255255

256+
256257
@contextlib.contextmanager
257258
def voc_root():
258259
with get_tmp_dir() as tmp_dir:
259260
voc_dir = os.path.join(tmp_dir, 'VOCdevkit',
260-
'VOC2012','ImageSets','Main')
261+
'VOC2012', 'ImageSets', 'Main')
261262
os.makedirs(voc_dir)
262-
train_file = os.path.join(voc_dir,'train.txt')
263+
train_file = os.path.join(voc_dir, 'train.txt')
263264
with open(train_file, 'w') as f:
264265
f.write('test')
265266

test/test_onnx.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,14 @@ def test_heatmaps_to_keypoints(self):
415415

416416
assert torch.all(out2[0].eq(out_trace2[0]))
417417
assert torch.all(out2[1].eq(out_trace2[1]))
418-
418+
419419
@unittest.skip("Disable test until export of interpolate script module to ONNX is fixed")
420420
def test_keypoint_rcnn(self):
421421
class KeyPointRCNN(torch.nn.Module):
422422
def __init__(self):
423423
super(KeyPointRCNN, self).__init__()
424-
self.model = models.detection.keypoint_rcnn.keypointrcnn_resnet50_fpn(pretrained=True, min_size=200, max_size=300)
424+
self.model = models.detection.keypoint_rcnn.keypointrcnn_resnet50_fpn(
425+
pretrained=True, min_size=200, max_size=300)
425426

426427
def forward(self, images):
427428
output = self.model(images)

test/test_transforms.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def test_randomperspective_fill(self):
202202
startpoints, endpoints = transforms.RandomPerspective.get_params(width, height, 0.5)
203203
tr_img = F.perspective(img_conv, startpoints, endpoints, fill=fill)
204204
pixel = tr_img.getpixel((0, 0))
205-
205+
206206
if not isinstance(pixel, tuple):
207207
pixel = (pixel,)
208208
self.assertTupleEqual(pixel, tuple([fill] * num_bands))
@@ -896,7 +896,6 @@ def test_normalize_3d_tensor(self):
896896
assert_array_almost_equal(target, result1.numpy())
897897
assert_array_almost_equal(target, result2.numpy())
898898

899-
900899
def test_adjust_brightness(self):
901900
x_shape = [2, 2, 3]
902901
x_data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1]

torchvision/models/detection/transform.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,11 @@ def __repr__(self):
192192

193193
def resize_keypoints(keypoints, original_size, new_size):
194194
# type: (Tensor, List[int], List[int])
195-
ratios = [torch.tensor(s, dtype=torch.float32, device=keypoints.device) / torch.tensor(s_orig, dtype=torch.float32, device=keypoints.device)
196-
for s, s_orig in zip(new_size, original_size)]
195+
ratios = [
196+
torch.tensor(s, dtype=torch.float32, device=keypoints.device) /
197+
torch.tensor(s_orig, dtype=torch.float32, device=keypoints.device)
198+
for s, s_orig in zip(new_size, original_size)
199+
]
197200
ratio_h, ratio_w = ratios
198201
resized_data = keypoints.clone()
199202
if torch._C._get_tracing_state():
@@ -208,8 +211,11 @@ def resize_keypoints(keypoints, original_size, new_size):
208211

209212
def resize_boxes(boxes, original_size, new_size):
210213
# type: (Tensor, List[int], List[int])
211-
ratios = [torch.tensor(s, dtype=torch.float32, device=boxes.device) / torch.tensor(s_orig, dtype=torch.float32, device=boxes.device)
212-
for s, s_orig in zip(new_size, original_size)]
214+
ratios = [
215+
torch.tensor(s, dtype=torch.float32, device=boxes.device) /
216+
torch.tensor(s_orig, dtype=torch.float32, device=boxes.device)
217+
for s, s_orig in zip(new_size, original_size)
218+
]
213219
ratio_height, ratio_width = ratios
214220
xmin, ymin, xmax, ymax = boxes.unbind(1)
215221

torchvision/ops/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _check_size_scale_factor(dim, size, scale_factor):
7676
raise ValueError("either size or scale_factor should be defined")
7777
if size is not None and scale_factor is not None:
7878
raise ValueError("only one of size or scale_factor should be defined")
79-
if scale_factor is not None:
79+
if scale_factor is not None:
8080
if isinstance(scale_factor, (list, tuple)):
8181
if len(scale_factor) != dim:
8282
raise ValueError(

torchvision/transforms/functional.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def normalize(tensor, mean, std, inplace=False):
188188
"""
189189
if not torch.is_tensor(tensor):
190190
raise TypeError('tensor should be a torch tensor. Got {}.'.format(type(tensor)))
191-
191+
192192
if tensor.ndimension() != 3:
193193
raise ValueError('Expected tensor to be a tensor image of size (C, H, W). Got tensor.size() = '
194194
'{}.'.format(tensor.size()))
@@ -424,7 +424,7 @@ def _parse_fill(fill, img, min_pil_version):
424424
image. If int or float, the value is used for all bands respectively.
425425
Defaults to 0 for all bands.
426426
img (PIL Image): Image to be filled.
427-
min_pil_version (str): The minimum PILLOW version for when the ``fillcolor`` option
427+
min_pil_version (str): The minimum PILLOW version for when the ``fillcolor`` option
428428
was first introduced in the calling function. (e.g. rotate->5.2.0, perspective->5.0.0)
429429
430430
Returns:

0 commit comments

Comments
 (0)