Skip to content

Commit 71cba8a

Browse files
committed
yapf formatting
1 parent aba25aa commit 71cba8a

29 files changed

+241
-173
lines changed

pystac/asset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pystac.collection import Collection as Collection_Type
99
from pystac.item import Item as Item_Type
1010

11+
1112
class Asset:
1213
"""An object that contains a link to data associated with an Item or Collection that
1314
can be downloaded or streamed.

pystac/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def to_dict(self, include_self_link: bool = True) -> Dict[str, Any]:
545545
if not self.summaries.is_empty():
546546
d['summaries'] = self.summaries.to_dict()
547547
if any(self.assets):
548-
d['assets'] = {k: v.to_dict() for k, v in self.assets.items() }
548+
d['assets'] = {k: v.to_dict() for k, v in self.assets.items()}
549549

550550
return d
551551

pystac/errors.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class STACTypeError(Exception):
1616
"""
1717
pass
1818

19+
1920
class RequiredPropertyMissing(Exception):
2021
""" This error is raised when a required value was expected
2122
to be there but was missing or None. This will happen, for example,
@@ -31,8 +32,6 @@ class RequiredPropertyMissing(Exception):
3132
def __init__(self,
3233
obj: Union[str, Any],
3334
prop: str,
34-
msg: Optional[str] = None,
35-
*args: Any,
36-
**kwargs: Any) -> None:
35+
msg: Optional[str] = None) -> None:
3736
msg = msg or f"{repr(obj)} does not have required property {prop}"
38-
super().__init__(msg, *args, **kwargs)
37+
super().__init__(msg)

pystac/extensions/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, collection: ps.Collection) -> None:
1313
self.summaries = collection.summaries
1414

1515
def _set_summary(self, prop_key: str, v: Optional[Union[List[Any], ps.RangeSummary[Any],
16-
Dict[str, Any]]]) -> None:
16+
Dict[str, Any]]]) -> None:
1717
if v is None:
1818
self.summaries.remove(prop_key)
1919
else:
@@ -27,7 +27,7 @@ class PropertiesExtension(ABC):
2727
properties: Dict[str, Any]
2828
additional_read_properties: Optional[Iterable[Dict[str, Any]]] = None
2929

30-
def _get_property(self, prop_name: str, typ: Type[P] = Any) -> Optional[P]:
30+
def _get_property(self, prop_name: str, typ: Type[P] = Type[Any]) -> Optional[P]:
3131
result: Optional[typ] = self.properties.get(prop_name)
3232
if result is not None:
3333
return result

pystac/extensions/datacube.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def reference_system(self, v: Optional[Union[str, float, Dict[str, Any]]]) -> No
194194
self.properties[DIM_REF_SYS_PROP] = v
195195

196196

197-
198197
class TemporalDimension(Dimension):
199198
@property
200199
def extent(self) -> Optional[List[Optional[str]]]:
@@ -324,6 +323,7 @@ def ext(obj: T) -> "DatacubeExtension[T]":
324323
else:
325324
raise ExtensionException(f"Datacube extension does not apply to type {type(obj)}")
326325

326+
327327
class CollectionDatacubeExtension(DatacubeExtension[ps.Collection]):
328328
def __init__(self, collection: ps.Collection):
329329
self.collection = collection
@@ -332,6 +332,7 @@ def __init__(self, collection: ps.Collection):
332332
def __repr__(self) -> str:
333333
return '<CollectionDatacubeExtension Item id={}>'.format(self.collection.id)
334334

335+
335336
class ItemDatacubeExtension(DatacubeExtension[ps.Item]):
336337
def __init__(self, item: ps.Item):
337338
self.item = item
@@ -340,6 +341,7 @@ def __init__(self, item: ps.Item):
340341
def __repr__(self) -> str:
341342
return '<ItemDatacubeExtension Item id={}>'.format(self.item.id)
342343

344+
343345
class AssetDatacubeExtension(DatacubeExtension[ps.Asset]):
344346
def __init__(self, asset: ps.Asset):
345347
self.asset_href = asset.href
@@ -350,9 +352,12 @@ def __init__(self, asset: ps.Asset):
350352
def __repr__(self) -> str:
351353
return '<AssetDatacubeExtension Item id={}>'.format(self.asset_href)
352354

355+
353356
class DatacubeExtensionHooks(ExtensionHooks):
354357
schema_uri: str = SCHEMA_URI
355358
prev_extension_ids: Set[str] = set(['datacube'])
356-
stac_object_types: Set[ps.STACObjectType] = set([ps.STACObjectType.COLLECTION, ps.STACObjectType.ITEM])
359+
stac_object_types: Set[ps.STACObjectType] = set(
360+
[ps.STACObjectType.COLLECTION, ps.STACObjectType.ITEM])
361+
357362

358-
DATACUBE_EXTENSION_HOOKS = DatacubeExtensionHooks()
363+
DATACUBE_EXTENSION_HOOKS = DatacubeExtensionHooks()

pystac/extensions/hooks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_object_links(self, obj: "STACObject_Type") -> Optional[List[str]]:
4242
return None
4343

4444
def migrate(self, obj: Dict[str, Any], version: STACVersionID,
45-
info: STACJSONDescription) -> None:
45+
info: STACJSONDescription) -> None:
4646
"""Migrate a STAC Object in dict format from a previous version.
4747
The base implementation will update the stac_extensions to the latest
4848
schema ID. This method will only be called for STAC objects that have been
@@ -60,6 +60,7 @@ def migrate(self, obj: Dict[str, Any], version: STACVersionID,
6060
obj['stac_extensions'].append(self.schema_uri)
6161
break
6262

63+
6364
class RegisteredExtensionHooks:
6465
def __init__(self, hooks: Iterable[ExtensionHooks]):
6566
self.hooks = dict([(e.schema_uri, e) for e in hooks])
@@ -88,7 +89,7 @@ def get_extended_object_links(self, obj: "STACObject_Type") -> List[str]:
8889
return result or []
8990

9091
def migrate(self, obj: Dict[str, Any], version: STACVersionID,
91-
info: STACJSONDescription) -> None:
92+
info: STACJSONDescription) -> None:
9293
for hooks in self.hooks.values():
9394
if info.object_type in hooks._get_stac_object_types():
9495
hooks.migrate(obj, version, info)

pystac/extensions/item_assets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def get_schema_uri(cls) -> str:
106106
def ext(cls, collection: ps.Collection) -> "ItemAssetsExtension":
107107
return cls(collection)
108108

109+
109110
class ItemAssetsExtensionHooks(ExtensionHooks):
110111
schema_uri: str = SCHEMA_URI
111112
prev_extension_ids: Set[str] = set(['asset', 'item-assets'])
@@ -122,4 +123,5 @@ def migrate(self, obj: Dict[str, Any], version: STACVersionID,
122123

123124
super().migrate(obj, version, info)
124125

125-
ITEM_ASSETS_EXTENSION_HOOKS = ItemAssetsExtensionHooks()
126+
127+
ITEM_ASSETS_EXTENSION_HOOKS = ItemAssetsExtensionHooks()

pystac/extensions/pointcloud.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,4 +522,5 @@ class PointcloudExtensionHooks(ExtensionHooks):
522522
prev_extension_ids: Set[str] = set(['pointcloud'])
523523
stac_object_types: Set[ps.STACObjectType] = set([ps.STACObjectType.ITEM])
524524

525-
POINTCLOUD_EXTENSION_HOOKS = PointcloudExtensionHooks()
525+
526+
POINTCLOUD_EXTENSION_HOOKS = PointcloudExtensionHooks()

pystac/extensions/projection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ def bbox(self) -> Optional[List[float]]:
175175
def bbox(self, v: Optional[List[float]]) -> None:
176176
self._set_property(BBOX_PROP, v)
177177

178-
179178
@property
180179
def centroid(self) -> Optional[Dict[str, float]]:
181180
"""Get or sets coordinates representing the centroid of the item in the asset data CRS.
@@ -248,6 +247,7 @@ def ext(obj: T) -> "ProjectionExtension[T]":
248247
else:
249248
raise ExtensionException(f"File extension does not apply to type {type(obj)}")
250249

250+
251251
class ItemProjectionExtension(ProjectionExtension[ps.Item]):
252252
def __init__(self, item: ps.Item):
253253
self.item = item
@@ -267,10 +267,11 @@ def __init__(self, asset: ps.Asset):
267267
def __repr__(self) -> str:
268268
return '<AssetProjectionExtension Asset href={}>'.format(self.asset_href)
269269

270+
270271
class ProjectionExtensionHooks(ExtensionHooks):
271272
schema_uri: str = SCHEMA_URI
272273
prev_extension_ids: Set[str] = set(['proj', 'projection'])
273274
stac_object_types: Set[ps.STACObjectType] = set([ps.STACObjectType.ITEM])
274275

275276

276-
PROJECTION_EXTENSION_HOOKS = ProjectionExtensionHooks()
277+
PROJECTION_EXTENSION_HOOKS = ProjectionExtensionHooks()

pystac/item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ def to_dict(self, include_self_link: bool = True) -> Dict[str, Any]:
811811
if not include_self_link:
812812
links = [x for x in links if x.rel != 'self']
813813

814-
assets = {k: v.to_dict() for k, v in self.assets.items() }
814+
assets = {k: v.to_dict() for k, v in self.assets.items()}
815815

816816
if self.datetime is not None:
817817
self.properties['datetime'] = datetime_to_str(self.datetime)

pystac/serialization/identify.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ def identify_stac_object(json_dict: Dict[str, Any]) -> STACJSONDescription:
356356
# code translates the short name IDs used pre-1.0.0-RC1 to the
357357
# relevant extension schema uri identifier.
358358

359-
360359
if not version_range.is_single_version():
361360
# Final Checks
362361

pystac/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,12 @@ def get_opt(option: Optional[T]) -> T:
232232
raise ValueError("Cannot get value from None")
233233
return option
234234

235+
235236
def get_required(option: Optional[T], obj: Union[str, Any], prop: str) -> T:
236237
""" Retrieves an optional value that comes from a required property.
237238
If the option is None, throws an RequiredPropertyError with
238239
the given obj and property
239240
"""
240241
if option is None:
241242
raise RequiredPropertyMissing(obj, prop)
242-
return option
243+
return option

tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import sys
33

4+
45
def setup_logging(level: int) -> None:
56
for package in ["pystac", "tests"]:
67
logger = logging.getLogger(package)
@@ -13,4 +14,5 @@ def setup_logging(level: int) -> None:
1314
ch.setFormatter(formatter)
1415
logger.addHandler(ch)
1516

17+
1618
setup_logging(logging.INFO)

tests/data-files/change_stac_version.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
TARGET_VERSION = ps.get_stac_version()
1313

14+
1415
def migrate(path: str) -> None:
1516
try:
1617
with open(path) as f:
@@ -23,19 +24,16 @@ def migrate(path: str) -> None:
2324
cur_ver = stac_json['stac_version']
2425
#if not cur_ver == TARGET_VERSION:
2526
if True:
26-
print(' - Migrating {} from {} to {}...'.format(
27-
path, cur_ver, TARGET_VERSION))
27+
print(' - Migrating {} from {} to {}...'.format(path, cur_ver, TARGET_VERSION))
2828
obj = ps.read_dict(stac_json, href=path)
2929
migrated = obj.to_dict(include_self_link=False)
3030
with open(path, 'w') as f:
31-
json.dump(migrated, f, indent=2)
31+
json.dump(migrated, f, indent=2)
3232

3333

3434
if __name__ == '__main__':
3535
parser = argparse.ArgumentParser(description='Process some integers.')
36-
parser.add_argument('--file',
37-
metavar='FILE',
38-
help='Only migrate this specific file.')
36+
parser.add_argument('--file', metavar='FILE', help='Only migrate this specific file.')
3937

4038
args = parser.parse_args()
4139

@@ -59,4 +57,4 @@ def migrate(path: str) -> None:
5957
for fname in files:
6058
if fname.endswith('.json'):
6159
path = os.path.join(root, fname)
62-
migrate(path)
60+
migrate(path)

tests/extensions/test_custom.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from pystac.extensions.base import ExtensionManagementMixin, PropertiesExtension, SummariesExtension
1111
from pystac.extensions.hooks import ExtensionHooks
1212

13-
1413
T = TypeVar('T', ps.Catalog, ps.Collection, ps.Item, ps.Asset)
1514

1615
SCHEMA_URI = "https://example.com/v2.0/custom-schema.json"
@@ -95,6 +94,7 @@ def __init__(self, asset: ps.Asset) -> None:
9594
self.additional_read_properties = [asset.owner.extra_fields]
9695
super().__init__(None)
9796

97+
9898
class SummariesCustomExtension(SummariesExtension):
9999
@property
100100
def test_prop(self) -> Optional[RangeSummary[str]]:
@@ -114,7 +114,8 @@ class CustomExtensionHooks(ExtensionHooks):
114114
def get_object_links(self, obj: ps.STACObject) -> Optional[List[str]]:
115115
return [TEST_LINK_REL]
116116

117-
def migrate(self, obj: Dict[str, Any], version: STACVersionID, info: STACJSONDescription) -> None:
117+
def migrate(self, obj: Dict[str, Any], version: STACVersionID,
118+
info: STACJSONDescription) -> None:
118119
if version < "1.0.0-rc2" and info.object_type == ps.STACObjectType.ITEM:
119120
if 'test:old-prop-name' in obj['properties']:
120121
obj['properties'][TEST_PROP] = obj['properties']['test:old-prop-name']
@@ -131,4 +132,4 @@ def tearDown(self) -> None:
131132
# TODO: Test custom extensions and extension hooks
132133

133134
def test_migrates(self):
134-
pass
135+
pass

tests/extensions/test_file.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def test_asset_checksum(self):
3939
asset = item.assets["thumbnail"]
4040

4141
# Get
42-
self.assertEqual("90e40210f52acd32b09769d3b1871b420789456c", FileExtension.ext(asset).checksum)
42+
self.assertEqual("90e40210f52acd32b09769d3b1871b420789456c",
43+
FileExtension.ext(asset).checksum)
4344

4445
# Set
4546
new_checksum = "90e40210163700a8a6501eccd00b6d3b44ddaed0"
@@ -80,4 +81,5 @@ def test_migrates_old_checksum(self):
8081

8182
self.assertTrue(FileExtension.has_extension(item))
8283
self.assertEqual(
83-
FileExtension.ext(item.assets['noises']).checksum, "90e40210a30d1711e81a4b11ef67b28744321659")
84+
FileExtension.ext(item.assets['noises']).checksum,
85+
"90e40210a30d1711e81a4b11ef67b28744321659")

tests/extensions/test_pointcloud.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ def test_apply(self):
2626
self.assertFalse(PointcloudExtension.has_extension(item))
2727

2828
PointcloudExtension.add_to(item)
29-
PointcloudExtension.ext(item).apply(1000, 'lidar', 'laszip',
30-
[PointcloudSchema({
31-
'name': 'X',
32-
'size': 8,
33-
'type': 'floating'
34-
})])
29+
PointcloudExtension.ext(item).apply(
30+
1000, 'lidar', 'laszip',
31+
[PointcloudSchema({
32+
'name': 'X',
33+
'size': 8,
34+
'type': 'floating'
35+
})])
3536
self.assertTrue(PointcloudExtension.has_extension(item))
3637

3738
def test_validate_pointcloud(self):
@@ -57,8 +58,8 @@ def test_count(self):
5758
# Ensure setting bad count fails validation
5859

5960
with self.assertRaises(ps.STACValidationError):
60-
PointcloudExtension.ext(pc_item).count = 'not_an_int' # type:ignore
61-
pc_item.validate()
61+
PointcloudExtension.ext(pc_item).count = 'not_an_int' # type:ignore
62+
pc_item.validate()
6263

6364
def test_type(self):
6465
pc_item = ps.Item.from_file(self.example_uri)

0 commit comments

Comments
 (0)