Przeglądaj źródła

Fix for flake8 and add flake8 test

Kentaro Wada 7 lat temu
rodzic
commit
6bbcee40c3

+ 2 - 1
.travis.yml

@@ -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 -- .)

+ 0 - 7
examples/instance_segmentation/labelme2voc.py

@@ -4,22 +4,15 @@ from __future__ import print_function
 
 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():

+ 0 - 7
examples/semantic_segmentation/labelme2voc.py

@@ -4,22 +4,15 @@ from __future__ import print_function
 
 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():

+ 2 - 0
labelme/__init__.py

@@ -1 +1,3 @@
+# flake8: noqa
+
 from labelme import utils

+ 1 - 1
labelme/app.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+# flake8: noqa
 # -*- coding: utf8 -*-
 #
 # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.

+ 1 - 0
labelme/canvas.py

@@ -1,3 +1,4 @@
+# flake8: noqa
 #
 # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
 #

+ 1 - 1
labelme/cli/__init__.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+# flake8: noqa
 
 from . import draw_json
 from . import json_to_dataset

+ 0 - 1
labelme/cli/json_to_dataset.py

@@ -4,7 +4,6 @@ import os
 import os.path as osp
 import warnings
 
-import numpy as np
 import PIL.Image
 import yaml
 

+ 1 - 1
labelme/cli/on_docker.py

@@ -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.')

+ 1 - 0
labelme/colorDialog.py

@@ -1,3 +1,4 @@
+# flake8: noqa
 #
 # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
 #

+ 1 - 0
labelme/labelDialog.py

@@ -1,3 +1,4 @@
+# flake8: noqa
 #
 # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
 #

+ 10 - 6
labelme/labelFile.py

@@ -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
@@ -29,7 +29,9 @@ PY2 = sys.version_info[0] == 2
 class LabelFileError(Exception):
     pass
 
+
 class LabelFile(object):
+
     suffix = '.json'
 
     def __init__(self, filename=None):
@@ -45,7 +47,7 @@ class LabelFile(object):
             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),
@@ -54,8 +56,10 @@ class LabelFile(object):
                         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']
@@ -67,9 +71,9 @@ class LabelFile(object):
             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,

+ 1 - 0
labelme/lib.py

@@ -1,3 +1,4 @@
+# flake8: noqa
 #
 # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
 #

+ 1 - 1
labelme/shape.py

@@ -1,4 +1,4 @@
-#!/usr/bin/python
+# flake8: noqa
 # -*- coding: utf-8 -*-
 #
 # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.

+ 1 - 0
labelme/toolBar.py

@@ -1,3 +1,4 @@
+# flake8: noqa
 #
 # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
 #

+ 1 - 0
labelme/zoomWidget.py

@@ -1,3 +1,4 @@
+# flake8: noqa
 #
 # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
 #

+ 1 - 1
setup.cfg

@@ -1,2 +1,2 @@
 [flake8]
-exclude = .anaconda3/*,.anaconda2/*,labelme/*
+exclude = .anaconda3/*,.anaconda2/*,labelme/resources.py