Skip to content

Commit

Permalink
Fix for flake8 and add flake8 test
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Mar 31, 2018
1 parent 3453477 commit 6bbcee4
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ install:
- pip install .

before_script:
- pip install -q pytest
- pip install -q hacking pytest

script:
- flake8 .
- pytest -v tests
- labelme --help
- (cd examples/single_image && rm -rf apc2016_obj3_json && labelme_json_to_dataset apc2016_obj3.json && python load_label_png.py && git checkout -- .)
Expand Down
7 changes: 0 additions & 7 deletions examples/instance_segmentation/labelme2voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@

import argparse
import glob
import io
import json
import os
import os.path as osp

import matplotlib
matplotlib.use('Agg')

import matplotlib.pyplot as plt
import numpy as np
import PIL.Image
import PIL.ImagePalette

import labelme
from labelme.utils import label2rgb
from labelme.utils import label_colormap


def main():
Expand Down
7 changes: 0 additions & 7 deletions examples/semantic_segmentation/labelme2voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@

import argparse
import glob
import io
import json
import os
import os.path as osp

import matplotlib
matplotlib.use('Agg')

import matplotlib.pyplot as plt
import numpy as np
import PIL.Image
import PIL.ImagePalette

import labelme
from labelme.utils import label2rgb
from labelme.utils import label_colormap


def main():
Expand Down
2 changes: 2 additions & 0 deletions labelme/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# flake8: noqa

from labelme import utils
2 changes: 1 addition & 1 deletion labelme/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
# flake8: noqa
# -*- coding: utf8 -*-
#
# Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
Expand Down
1 change: 1 addition & 0 deletions labelme/canvas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
#
# Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
#
Expand Down
2 changes: 1 addition & 1 deletion labelme/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
# flake8: noqa

from . import draw_json
from . import json_to_dataset
Expand Down
1 change: 0 additions & 1 deletion labelme/cli/json_to_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os.path as osp
import warnings

import numpy as np
import PIL.Image
import yaml

Expand Down
2 changes: 1 addition & 1 deletion labelme/cli/on_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def labelme_on_docker(in_file, out_file):
try:
json.load(open(out_file))
return out_file
except Exception as e:
except Exception:
if open(out_file).read() == '':
os.remove(out_file)
raise RuntimeError('Annotation is cancelled.')
Expand Down
1 change: 1 addition & 0 deletions labelme/colorDialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
#
# Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
#
Expand Down
1 change: 1 addition & 0 deletions labelme/labelDialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
#
# Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
#
Expand Down
16 changes: 10 additions & 6 deletions labelme/labelFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with Labelme. If not, see <http://www.gnu.org/licenses/>.
#

from base64 import b64encode, b64decode
import base64
import json
import os.path
import sys
Expand All @@ -29,7 +29,9 @@
class LabelFileError(Exception):
pass


class LabelFile(object):

suffix = '.json'

def __init__(self, filename=None):
Expand All @@ -45,7 +47,7 @@ def load(self, filename):
with open(filename, 'rb' if PY2 else 'r') as f:
data = json.load(f)
if data['imageData'] is not None:
imageData = b64decode(data['imageData'])
imageData = base64.b64decode(data['imageData'])
else:
# relative path from label file to relative path from cwd
imagePath = os.path.join(os.path.dirname(filename),
Expand All @@ -54,8 +56,10 @@ def load(self, filename):
imageData = f.read()
lineColor = data['lineColor']
fillColor = data['fillColor']
shapes = ((s['label'], s['points'], s['line_color'], s['fill_color'])\
for s in data['shapes'])
shapes = (
(s['label'], s['points'], s['line_color'], s['fill_color'])
for s in data['shapes']
)
# Only replace data after everything is loaded.
self.shapes = shapes
self.imagePath = data['imagePath']
Expand All @@ -67,9 +71,9 @@ def load(self, filename):
raise LabelFileError(e)

def save(self, filename, shapes, imagePath, imageData=None,
lineColor=None, fillColor=None):
lineColor=None, fillColor=None):
if imageData is not None:
imageData = b64encode(imageData).decode('utf-8')
imageData = base64.b64encode(imageData).decode('utf-8')
data = dict(
shapes=shapes,
lineColor=lineColor,
Expand Down
1 change: 1 addition & 0 deletions labelme/lib.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
#
# Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
#
Expand Down
2 changes: 1 addition & 1 deletion labelme/shape.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
# flake8: noqa
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
Expand Down
1 change: 1 addition & 0 deletions labelme/toolBar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
#
# Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
#
Expand Down
1 change: 1 addition & 0 deletions labelme/zoomWidget.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
#
# Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
#
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[flake8]
exclude = .anaconda3/*,.anaconda2/*,labelme/*
exclude = .anaconda3/*,.anaconda2/*,labelme/resources.py

0 comments on commit 6bbcee4

Please sign in to comment.