Skip to content

Commit 63f3f2d

Browse files
committed
Flake8
1 parent a6d2b96 commit 63f3f2d

File tree

11 files changed

+55
-22
lines changed

11 files changed

+55
-22
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ xmltodict = "*"
2020
check-manifest = "*"
2121
mypy = "*"
2222
docutils = "*"
23+
"flake8" = "*"
2324

2425
[requires]
2526
python_version = "3.6"

Pipfile.lock

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

labelbox/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Exception classes for the labelbox python package.
33
"""
44

5+
56
class UnknownFormatError(Exception):
67
"""Exception raised for unknown label_format"""
78

labelbox/exporters/coco_exporter.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def from_json(labeled_data, coco_output, label_format='WKT'):
4444
with open(coco_output, 'w+') as file_handle:
4545
file_handle.write(json.dumps(coco))
4646

47+
4748
def make_coco_metadata(project_name, created_by):
4849
"Initializes COCO export data structure."
4950
coco = {
@@ -65,6 +66,7 @@ def make_coco_metadata(project_name, created_by):
6566

6667
return coco
6768

69+
6870
def _add_label(coco, image, labels, label_format):
6971
"Incrementally updates COCO export data structure with a new label."
7072
response = requests.get(image['coco_url'], stream=True)
@@ -114,23 +116,24 @@ def _add_label(coco, image, labels, label_format):
114116

115117
coco['annotations'].append(annotation)
116118

119+
117120
def _get_polygons(label_format, label_data):
118121
"Converts segmentation `label: String!` into polygons"
119122
if label_format == 'WKT':
120-
if isinstance(label_data, list): # V3
123+
if isinstance(label_data, list): # V3
121124
polygons = map(lambda x: wkt.loads(x['geometry']), label_data)
122-
else: # V2
125+
else: # V2
123126
polygons = wkt.loads(label_data)
124127
elif label_format == 'XY':
125128
polygons = []
126129
for xy_list in label_data:
127-
if 'geometry' in xy_list: # V3
130+
if 'geometry' in xy_list: # V3
128131
xy_list = xy_list['geometry']
129132

130133
# V2 and V3
131134
assert isinstance(xy_list, list), \
132-
'Expected list in "geometry" key but got {}'.format(xy_list)
133-
else: # V2, or non-list
135+
'Expected list in "geometry" key but got {}'.format(xy_list)
136+
else: # V2, or non-list
134137
if not isinstance(xy_list, list) or not xy_list or 'x' not in xy_list[0]:
135138
# skip non xy lists
136139
continue

labelbox/exporters/voc_exporter.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def from_json(labeled_data, annotations_output_dir, images_output_dir,
5353
logging.exception('Failed to fetch image from %s', data['Labeled Data'])
5454
continue
5555

56+
5657
def _write_label(
5758
data, label_format, images_output_dir, annotations_output_dir):
5859
"Writes a Pascal VOC formatted image and label pair to disk."
@@ -94,16 +95,16 @@ def _write_label(
9495

9596
def _add_pascal_object_from_wkt(xml_writer, img_height, wkt_data, label):
9697
polygons = []
97-
if isinstance(wkt_data, list): # V3+
98+
if isinstance(wkt_data, list): # V3+
9899
polygons = map(lambda x: wkt.loads(x['geometry']), wkt_data)
99-
else: # V2
100+
else: # V2
100101
polygons = wkt.loads(wkt_data)
101102

102103
for point in polygons:
103104
xy_coords = []
104105
for x_val, y_val in point.exterior.coords:
105106
xy_coords.extend([x_val, img_height - y_val])
106-
# remove last polygon if it is identical to first point
107+
# remove last polygon if it is identical to first point
107108
if xy_coords[-2:] == xy_coords[:2]:
108109
xy_coords = xy_coords[:-2]
109110
xml_writer.add_object(name=label, xy_coords=xy_coords)
@@ -112,9 +113,9 @@ def _add_pascal_object_from_wkt(xml_writer, img_height, wkt_data, label):
112113

113114
def _add_pascal_object_from_xy(xml_writer, img_height, polygons, label):
114115
for polygon in polygons:
115-
if 'geometry' in polygon: # V3
116+
if 'geometry' in polygon: # V3
116117
polygon = polygon['geometry']
117-
assert isinstance(polygon, list) # V2 and V3
118+
assert isinstance(polygon, list) # V2 and V3
118119

119120
xy_coords = []
120121
for point in polygon:

labelbox/predictions/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import collections
55

66
import rasterio.features
7-
from simplification.cutil import simplify_coords # pylint: disable=no-name-in-module
7+
from simplification.cutil import simplify_coords # pylint: disable=no-name-in-module
88

99

1010
def vectorize_to_v4_label(segmentation_map, legend, epsilon=None):
@@ -33,7 +33,7 @@ class names.
3333
in image-segmentation v4 frontend after calling `json.dumps`.
3434
"""
3535
assert len(segmentation_map.shape) == 2, \
36-
'Segmentation maps must be numpy arrays with shape (width, height)'
36+
'Segmentation maps must be numpy arrays with shape (width, height)'
3737
label = collections.defaultdict(lambda: [])
3838
for polygon, pixel_value in rasterio.features.shapes(segmentation_map):
3939
pixel_value = int(pixel_value)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ source_dir = docs
8282
build_dir = docs/_build
8383

8484
[flake8]
85-
# Some sane defaults for the code style checker flake8
85+
max-line-length = 120
8686
exclude =
8787
.tox
8888
build

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from setuptools import setup
22

3+
# configured in setup.cfg
34
setup()

tests/test_exporters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import labelbox.exporters.coco_exporter as lb2co
77
import labelbox.exporters.voc_exporter as lb2pa
88

9+
910
class TestCocoExporter(object):
1011
def test_labelbox_1(self, tmpfile, datadir):
1112
labeled_data = datadir.join('labelbox_1.json')
@@ -40,6 +41,7 @@ def test_empty_skipped(self, tmpfile, datadir):
4041
labeled_data = datadir.join('empty_skipped.json')
4142
lb2co.from_json(labeled_data=labeled_data, coco_output=tmpfile)
4243

44+
4345
class TestVocExporter(object):
4446
def test_wkt_1(self, tmpdir, datadir):
4547
labeled_data = datadir.join('labelbox_1.json')

tests/test_predictions.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44
import labelbox.predictions as lbpreds
55

6+
67
def test_vectorize_to_v4_label():
7-
segmentation_map = np.zeros((256,256), dtype=np.int32)
8-
segmentation_map[:32,:32] = 1 # top left corner
9-
segmentation_map[32:128,:32] = 2 # strip from top left to top middle
10-
segmentation_map[:64,-32:] = 3 # left half of bottom
11-
segmentation_map[-64:,-32:] = 3 # right half of bottom
8+
segmentation_map = np.zeros((256, 256), dtype=np.int32)
9+
segmentation_map[:32, :32] = 1 # top left corner
10+
segmentation_map[32:128, :32] = 2 # strip from top left to top middle
11+
segmentation_map[:64, -32:] = 3 # left half of bottom
12+
segmentation_map[-64:, -32:] = 3 # right half of bottom
1213

1314
legend = {
1415
1: 'TL',
@@ -23,7 +24,7 @@ def test_vectorize_to_v4_label():
2324
assert set(legend.values()).issuperset(label.keys())
2425

2526
# contains top left, and has (0,0)
26-
assert any(map(lambda x: x['geometry'][0] == {'x':0, 'y':0}, label['TL']))
27+
assert any(map(lambda x: x['geometry'][0] == {'x': 0, 'y': 0}, label['TL']))
2728
assert len(label['TL']) == 1
2829

2930
# two regions, bottom left and bottom right
@@ -32,8 +33,8 @@ def test_vectorize_to_v4_label():
3233
# does not contain unannotated class
3334
assert 'NO_LABELS' not in label.keys()
3435

36+
3537
def test_vectorize_simplify():
36-
# Using Ramer–Douglas–Peucker
3738
coords = [
3839
(0.0, 0.0),
3940
(5.0, 4.0),

0 commit comments

Comments
 (0)