Skip to content

Commit 3ca97a7

Browse files
committed
Merge branch 'develop' of github.com:stac-utils/pystac into remove_link_type
2 parents 1494587 + 5a492ca commit 3ca97a7

23 files changed

+671
-128
lines changed

.codespellignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
filetest

.github/pull_request_template.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**Related Issue(s):** #
2+
3+
4+
**Description:**
5+
6+
7+
**PR Checklist:**
8+
9+
- [ ] Code is formatted (run `scripts/format`)
10+
- [ ] Tests pass (run `scripts/test`)
11+
- [ ] This PR maintains or improves overall codebase code coverage.
12+
- [ ] Changes are added to the [CHANGELOG](https://github.com/stac-utils/pystac/blob/develop/CHANGELOG.md). See [the docs](https://pystac.readthedocs.io/en/latest/contributing.html#changelog) for information about adding to the changelog.

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
# Changelog
22

3-
## [unreleased]
3+
## unreleased
4+
5+
### Added
6+
7+
### Fixed
8+
9+
- Fixed error when accessing the statistics attribute of the pointcloud extension when no statistics were defined ([#282](https://github.com/stac-utils/pystac/pull/282))
10+
11+
### Changed
12+
13+
### Removed
14+
15+
## [v0.5.5]
16+
17+
### Added
18+
19+
- Added support for STAC file extension ([#270](https://github.com/stac-utils/pystac/pull/270))
420

521
### Fixed
622

@@ -10,6 +26,7 @@
1026
### Changed
1127

1228
- Subclass relevant classes from `enum.Enum`. This allows iterating over the class' contents. The `__str__` method is overwritten so this should not break backwards compatibility. ([#261](https://github.com/stac-utils/pystac/pull/261))
29+
- Extract method to correctly handle setting properties in Item/Asset for ItemExtensions ([#272](https://github.com/stac-utils/pystac/pull/272))
1330

1431
## [v0.5.4]
1532

docs/contributing.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,19 @@ To format code:
5757
> yapf -ipr tests
5858
5959
You can also run the ``./scripts/test`` script to check flake8 and yapf.
60+
61+
CHANGELOG
62+
^^^^^^^^^
63+
64+
PySTAC maintains a `changelog <https://github.com/stac-utils/pystac/blob/develop/CHANGELOG.md>`_
65+
to track changes between releases. All PRs should make a changelog entry unless
66+
the change is trivial (e.g. fixing typos) or is entirely invisible to users who may
67+
be upgrading versions (e.g. an improvement to the CI system).
68+
69+
For changelog entries, please link to the PR of that change. This needs to happen in a few steps:
70+
71+
- Make a PR to PySTAC with your changes
72+
- Record the link to the PR
73+
- Push an additional commit to your branch with the changelog entry with the link to the PR.
74+
75+
For more information on changelogs and how to write a good entry, see `keep a changelog <https://keepachangelog.com/en/1.0.0/>`_

pystac/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class STACError(Exception):
4141
import pystac.extensions.timestamps
4242
import pystac.extensions.version
4343
import pystac.extensions.view
44+
import pystac.extensions.file
4445

4546
STAC_EXTENSIONS = extensions.base.RegisteredSTACExtensions([
4647
extensions.eo.EO_EXTENSION_DEFINITION, extensions.label.LABEL_EXTENSION_DEFINITION,
@@ -49,7 +50,8 @@ class STACError(Exception):
4950
extensions.sat.SAT_EXTENSION_DEFINITION, extensions.scientific.SCIENTIFIC_EXTENSION_DEFINITION,
5051
extensions.single_file_stac.SFS_EXTENSION_DEFINITION,
5152
extensions.timestamps.TIMESTAMPS_EXTENSION_DEFINITION,
52-
extensions.version.VERSION_EXTENSION_DEFINITION, extensions.view.VIEW_EXTENSION_DEFINITION
53+
extensions.version.VERSION_EXTENSION_DEFINITION, extensions.view.VIEW_EXTENSION_DEFINITION,
54+
extensions.file.FILE_EXTENSION_DEFINITION
5355
])
5456

5557

pystac/catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def to_dict(self, include_self_link=True):
381381
if self.title is not None:
382382
d['title'] = self.title
383383

384-
return deepcopy(d)
384+
return d
385385

386386
def clone(self):
387387
clone = Catalog(id=self.id,

pystac/collection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def to_dict(self, include_self_link=True):
107107
if self.summaries is not None:
108108
d['summaries'] = self.summaries
109109

110-
return deepcopy(d)
110+
return d
111111

112112
def clone(self):
113113
clone = Collection(id=self.id,
@@ -213,7 +213,7 @@ def to_dict(self):
213213
"""
214214
d = {'spatial': self.spatial.to_dict(), 'temporal': self.temporal.to_dict()}
215215

216-
return deepcopy(d)
216+
return d
217217

218218
def clone(self):
219219
"""Clones this object.
@@ -315,7 +315,7 @@ def to_dict(self):
315315
dict: A serializion of the SpatialExtent that can be written out as JSON.
316316
"""
317317
d = {'bbox': self.bboxes}
318-
return deepcopy(d)
318+
return d
319319

320320
def clone(self):
321321
"""Clones this object.
@@ -418,7 +418,7 @@ def to_dict(self):
418418
encoded_intervals.append([start, end])
419419

420420
d = {'interval': encoded_intervals}
421-
return deepcopy(d)
421+
return d
422422

423423
def clone(self):
424424
"""Clones this object.
@@ -505,7 +505,7 @@ def to_dict(self):
505505
if self.url is not None:
506506
d['url'] = self.url
507507

508-
return deepcopy(d)
508+
return d
509509

510510
@staticmethod
511511
def from_dict(d):

pystac/extensions/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ def __str__(self):
2929
TIMESTAMPS = 'timestamps'
3030
VERSION = 'version'
3131
VIEW = 'view'
32+
FILE = 'file'

pystac/extensions/base.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,30 @@ def enable_extension(cls, stac_object):
121121
"""
122122
pass
123123

124+
def _set_property(self, key, value, asset):
125+
'''
126+
Set an Item or an Asset property.
127+
128+
If an Asset is supplied, sets the property on the Asset.
129+
Otherwise sets the Item's value.
130+
131+
If the passed value to set is None, the property key is removed from
132+
the dictionary of properties.
133+
134+
It's recommended to use this method from extensions, instead of implementing
135+
the logic for that in the corresponding subclasses.
136+
137+
Args:
138+
key (str): The name of the property
139+
value (Object): the value to set
140+
asset: The Asset to modify. If None, the property will be set in the Item
141+
'''
142+
target = self.item.properties if asset is None else asset.properties
143+
if value is None:
144+
target.pop(key, None)
145+
else:
146+
target[key] = value
147+
124148

125149
class RegisteredSTACExtensions:
126150
def __init__(self, extension_definitions):

pystac/extensions/eo.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ def set_bands(self, bands, asset=None):
8585
Otherwise sets the Item's value.
8686
"""
8787
band_dicts = [b.to_dict() for b in bands]
88-
if asset is not None:
89-
asset.properties['eo:bands'] = band_dicts
90-
else:
91-
self.item.properties['eo:bands'] = band_dicts
88+
self._set_property('eo:bands', band_dicts, asset)
9289

9390
@property
9491
def cloud_cover(self):
@@ -124,10 +121,7 @@ def set_cloud_cover(self, cloud_cover, asset=None):
124121
If an Asset is supplied, sets the property on the Asset.
125122
Otherwise sets the Item's value.
126123
"""
127-
if asset is None:
128-
self.item.properties['eo:cloud_cover'] = cloud_cover
129-
else:
130-
asset.properties['eo:cloud_cover'] = cloud_cover
124+
self._set_property('eo:cloud_cover', cloud_cover, asset)
131125

132126
def __repr__(self):
133127
return '<EOItemExt Item id={}>'.format(self.item.id)

0 commit comments

Comments
 (0)