Skip to content

Commit 591af56

Browse files
committed
Style fixes.
1 parent 3f2f04e commit 591af56

File tree

8 files changed

+50
-56
lines changed

8 files changed

+50
-56
lines changed

Diff for: pystac/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def _stac_object_from_dict(d, href=None, root=None):
5353
# Dealing with an Item
5454
if any([k for k in d['properties'].keys() if k.startswith('eo:')]):
5555
return EOItem.from_dict(d, href=href, root=root)
56-
elif any([k for k in d['properties'].keys() if k.startswith('label:')]):
56+
elif any(
57+
[k for k in d['properties'].keys() if k.startswith('label:')]):
5758
return LabelItem.from_dict(d, href=href, root=root)
5859
else:
5960
return Item.from_dict(d, href=href, root=root)

Diff for: pystac/catalog.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import os
2-
import json
32
from copy import deepcopy
43

54
import pystac
65
from pystac import (STAC_VERSION, STACError)
76
from pystac.stac_object import STACObject
8-
from pystac.stac_io import STAC_IO
97
from pystac.link import (Link, LinkType)
108
from pystac.resolved_object_cache import ResolvedObjectCache
119
from pystac.utils import (is_absolute_href, make_absolute_href)
@@ -125,7 +123,8 @@ def add_item(self, item, title=None):
125123

126124
# Prevent typo confusion
127125
if isinstance(item, pystac.Catalog):
128-
raise STACError('Cannot add catalog as item. Use add_child instead.')
126+
raise STACError(
127+
'Cannot add catalog as item. Use add_child instead.')
129128

130129
item.set_root(self.get_root())
131130
item.set_parent(self)

Diff for: pystac/collection.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import json
21
from datetime import datetime
32
import dateutil.parser
43
from copy import (copy, deepcopy)
54

65
from pystac import STACError
76
from pystac.catalog import Catalog
8-
from pystac.link import (Link, LinkType)
9-
from pystac.stac_io import STAC_IO
10-
from pystac.utils import (make_absolute_href, is_absolute_href)
7+
from pystac.link import Link
118

129

1310
class Collection(Catalog):
@@ -209,12 +206,12 @@ def from_dict(d):
209206
# Handle pre-0.8 spatial extents
210207
spatial_extent_dict = d['spatial']
211208
if isinstance(spatial_extent_dict, list):
212-
spatial_extent_dict = { 'bbox': [spatial_extent_dict] }
209+
spatial_extent_dict = {'bbox': [spatial_extent_dict]}
213210

214211
# Handle pre-0.8 temporal extents
215212
temporal_extent_dict = d['temporal']
216213
if isinstance(temporal_extent_dict, list):
217-
temporal_extent_dict = { 'interval': [temporal_extent_dict] }
214+
temporal_extent_dict = {'interval': [temporal_extent_dict]}
218215

219216
return Extent(SpatialExtent.from_dict(spatial_extent_dict),
220217
TemporalExtent.from_dict(temporal_extent_dict))

Diff for: pystac/item.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import json
21
import os
32
from copy import copy, deepcopy
43
from collections import ChainMap
54

65
import dateutil.parser
76

87
from pystac import (STAC_VERSION, STACError)
9-
from pystac.stac_io import STAC_IO
108
from pystac.link import Link, LinkType
119
from pystac.stac_object import STACObject
1210
from pystac.utils import (is_absolute_href, make_absolute_href,
@@ -269,7 +267,8 @@ def from_dict(cls, d, href=None, root=None):
269267
# common properties to merge.
270268
collection_to_merge = None
271269
if collection_id is not None and root is not None:
272-
collection_to_merge = root._resolved_objects.get_by_id(collection_id)
270+
collection_to_merge = root._resolved_objects.get_by_id(
271+
collection_id)
273272
else:
274273
collection_link = item.get_single_link('collection')
275274
if collection_link is not None:
@@ -280,22 +279,21 @@ def from_dict(cls, d, href=None, root=None):
280279
not collection_link.is_resolved():
281280
if href is not None:
282281
collection_link = collection_link.clone()
283-
collection_link.target = make_absolute_href(collection_link.target,
284-
href)
282+
collection_link.target = make_absolute_href(
283+
collection_link.target, href)
285284
else:
286285
collection_link = None
287286

288287
if collection_link is not None:
289-
collection_to_merge = collection_link.resolve_stac_object(root=root).target
288+
collection_to_merge = collection_link.resolve_stac_object(
289+
root=root).target
290290
if item.collection_id is None:
291291
item.collection_id = collection_to_merge.id
292292

293293
if collection_to_merge is not None:
294294
if collection_to_merge.properties is not None:
295295
item.properties = dict(
296-
ChainMap(
297-
item.properties,
298-
collection_to_merge.properties))
296+
ChainMap(item.properties, collection_to_merge.properties))
299297

300298
return item
301299

Diff for: pystac/label.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
"""STAC Model classes for Label extension.
22
"""
3-
import json
43
from copy import (copy, deepcopy)
54

65
from pystac import STACError
7-
from pystac.stac_io import STAC_IO
86
from pystac.item import (Item, Asset)
97
from pystac.link import Link
10-
from pystac.utils import (is_absolute_href, make_absolute_href)
118

129

1310
class LabelType:
@@ -178,7 +175,6 @@ def get_sources(self):
178175
"""
179176
return self.get_stac_objects('source')
180177

181-
182178
def add_labels(self, href, title=None, media_type=None, properties=None):
183179
"""Adds a label asset to this LabelItem.
184180
@@ -192,11 +188,12 @@ def add_labels(self, href, title=None, media_type=None, properties=None):
192188
object JSON.
193189
"""
194190

195-
self.add_asset("labels",
196-
Asset(href=href,
197-
title=title,
198-
media_type=media_type,
199-
properties=properties))
191+
self.add_asset(
192+
"labels",
193+
Asset(href=href,
194+
title=title,
195+
media_type=media_type,
196+
properties=properties))
200197

201198
def add_geojson_labels(self, href, title=None, properties=None):
202199
"""Adds a GeoJSON label asset to this LabelItem.

Diff for: pystac/stac_object.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ def fully_resolve(self):
321321
link_rels = set(self._object_links())
322322
for link in self.links:
323323
if link.rel == 'root':
324-
if not link.is_resolved() and not link.target == self.get_self_href():
324+
if not link.is_resolved(
325+
) and not link.target == self.get_self_href():
325326
link.resolve_stac_object()
326327
link.target.fully_resolve()
327328
if link.rel in link_rels:
@@ -411,7 +412,6 @@ def from_file(cls, href):
411412
o.set_root(o, link_type=root_link.link_type)
412413
return o
413414

414-
415415
@classmethod
416416
@abstractmethod
417417
def from_dict(cls, d, href=None, root=None):

Diff for: tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Set the STAC_IO read method to read HTTP.
88
# Skip SSL Certification because it fails on some machines.
99

10+
1011
def unsafe_read_https_method(uri):
1112
parsed = urlparse(uri)
1213
if parsed.scheme == 'https':

Diff for: tests/test_catalog.py

+27-26
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def item_mapper(item):
8282
os.path.join(tmp_dir, 'cat', 'catalog.json'))
8383
result_items = result_cat.get_all_items()
8484

85-
self.assertEqual(len(list(catalog_items)) * 2, len(list(result_items)))
85+
self.assertEqual(
86+
len(list(catalog_items)) * 2, len(list(result_items)))
8687

8788
ones, twos = 0, 0
8889
for item in result_items:
@@ -109,7 +110,8 @@ def test_map_items_multiple_2(self):
109110
properties={})
110111
item1.add_asset('ortho', Asset(href='/some/ortho.tif'))
111112
catalog.add_item(item1)
112-
kitten = Catalog(id='test-kitten', description='A cuter version of catalog')
113+
kitten = Catalog(id='test-kitten',
114+
description='A cuter version of catalog')
113115
catalog.add_child(kitten)
114116
item2 = Item(id='item2',
115117
geometry=RANDOM_GEOM,
@@ -129,24 +131,23 @@ def create_label_item(item):
129131
img_href = item.assets['ortho'].href
130132
label_href = '{}.geojson'.format(os.path.splitext(img_href)[0])
131133
label_item = LabelItem(id='Labels',
132-
geometry=item.geometry,
133-
bbox=item.bbox,
134-
datetime=datetime.utcnow(),
135-
properties={},
136-
label_description='labels',
137-
label_type='vector',
138-
label_properties='label',
139-
label_classes=[
140-
LabelClasses(classes=['one', 'two'],
141-
name='label')
142-
],
143-
label_tasks=['classification'])
134+
geometry=item.geometry,
135+
bbox=item.bbox,
136+
datetime=datetime.utcnow(),
137+
properties={},
138+
label_description='labels',
139+
label_type='vector',
140+
label_properties='label',
141+
label_classes=[
142+
LabelClasses(classes=['one', 'two'],
143+
name='label')
144+
],
145+
label_tasks=['classification'])
144146
label_item.add_source(item, assets=['ortho'])
145147
label_item.add_geojson_labels(label_href)
146148

147149
return [item, label_item]
148150

149-
150151
c = catalog.map_items(modify_item_title)
151152
c = c.map_items(create_label_item)
152153
new_catalog = c
@@ -340,29 +341,29 @@ def test_set_hrefs_manually(self):
340341

341342
# Set each item's HREF based on it's datetime
342343
for item in items:
343-
item_href = '{}/{}-{}/{}.json'.format(root_dir,
344-
item.datetime.year,
345-
item.datetime.month,
346-
item.id)
344+
item_href = '{}/{}-{}/{}.json'.format(
345+
root_dir, item.datetime.year, item.datetime.month,
346+
item.id)
347347
item.set_self_href(item_href)
348348

349349
catalog.save(catalog_type=CatalogType.SELF_CONTAINED)
350350

351-
read_catalog = Catalog.from_file(os.path.join(tmp_dir, 'catalog.json'))
351+
read_catalog = Catalog.from_file(
352+
os.path.join(tmp_dir, 'catalog.json'))
352353

353354
for root, _, items in read_catalog.walk():
354355
parent = root.get_parent()
355356
if parent is None:
356-
self.assertEqual(root.get_self_href(), os.path.join(tmp_dir, 'catalog.json'))
357+
self.assertEqual(root.get_self_href(),
358+
os.path.join(tmp_dir, 'catalog.json'))
357359
else:
358360
d = os.path.dirname(parent.get_self_href())
359-
self.assertEqual(root.get_self_href(), os.path.join(d,
360-
root.id,
361-
root.DEFAULT_FILE_NAME))
361+
self.assertEqual(
362+
root.get_self_href(),
363+
os.path.join(d, root.id, root.DEFAULT_FILE_NAME))
362364
for item in items:
363365
end = '{}-{}/{}.json'.format(item.datetime.year,
364-
item.datetime.month,
365-
item.id)
366+
item.datetime.month, item.id)
366367
self.assertTrue(item.get_self_href().endswith(end))
367368

368369

0 commit comments

Comments
 (0)