-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a post-init modifier keyword #286
Conversation
**Related Issue(s):** - Closes stac-utils#259 **Description:** This adds a new keyword, `modifier`, to the various constructors. The motivation is described in stac-utils#259. As a brief demonstration: ```python In [1]: import planetary_computer, pystac_client In [2]: catalog = pystac_client.Client.open("https://planetarycomputer.microsoft.com/api/stac/v1", modifier=planetary_computer.sign_inplace) In [3]: item = next(catalog.get_collection("sentinel-2-l2a").get_all_items()) In [4]: item.assets["B02"].href # signed URL, notice the querystring Out[4]: 'https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/52/S/GH/2022/07/28/S2B_MSIL2A_20220728T020659_N0400_R103_T52SGH_20220729T082039.SAFE/GRANULE/L2A_T52SGH_A028157_20220728T021310/IMG_DATA/R10m/T52SGH_20220728T020659_B02_10m.tif?st=2022-07-28T16%3A03%3A54Z&se=2022-07-29T16%3A48%3A54Z...' ``` **PR Checklist:** - [x] Code is formatted - [x] Tests pass - [x] Changes are added to the [CHANGELOG](https://github.com/stac-utils/pystac-api-client/blob/main/CHANGELOG.md)
One concern I had with expecting I wonder if our calls to result = self.modifier(thing)
if result is not None:
warnings.warn("Modifier returned a value...") That'd be a "false positive" if you have a function that mutates and returns a value. But maybe that's OK? |
Codecov Report
@@ Coverage Diff @@
## main #286 +/- ##
==========================================
+ Coverage 83.54% 84.36% +0.82%
==========================================
Files 10 11 +1
Lines 717 774 +57
==========================================
+ Hits 599 653 +54
- Misses 118 121 +3
Help us with your feedback. Take ten seconds to tell us how you rate us. |
3ca725e implemented a check similar to #286 (comment). After we call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me. The only design decision I disagreed with was pystac_client._utils.no_modifier
; Optional[Callable[[Modifiable], None]]
is clearer to me. But that's a six/half-dozen decision so I'm happy with how things are as-is.
Thanks for the tests, it feels very easy to miss a branch and not pass through/modify correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops forgot that I requested changes inline 🤦🏽
@philvarner @duckontheweb I've added both of you as reviewers; not required, but if you do have a spare moment to take a look, this PR touches a lot of code and it wouldn't hurt to have a second set of eyes. |
I'm fine with this too, if you also prefer it. It saves a function call, so we might as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @TomAugspurger, I think this is going to end up being really helpful even outside of the Planetary Computer use-case.
I left one fix to remove a # type: ignore
comment in one of the tests, but other than that it looks good to me.
Co-authored-by: Jon Duckworth <duckontheweb@gmail.com>
Thanks all! |
Related Issue(s):
Description:
This adds a new keyword,
modifier
, to the various constructors. The motivation is described in #259. As a brief demonstration:This is kind of a large PR, partly from overriding the
__init__
methods so that we can set this new attribute. This also seemed to cause several issues with mypy, some of which I'm stumped by.But the core of the change is to
self.modifier(thing)
before returning anything to the user.self.modifier
to child collections / catalogs.A couple notes / collections
Catalog
andCollection
or any of thefrom_dict
/from_file
methods from pystac so those won't directly mentionmodifier
anywhere, despite being a valid keyword. I can either copy them over, override them with a short description ofmodifier
and then point to the parent, or just leave it as is.PR Checklist: