Skip to content
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

Configurable warnings #480

Merged
merged 43 commits into from
May 4, 2023
Merged

Configurable warnings #480

merged 43 commits into from
May 4, 2023

Conversation

jsignell
Copy link
Member

@jsignell jsignell commented Apr 14, 2023

Related Issue(s):

Description:

If the main use for the configurable option is this warnings config, then it might make sense to use the capability of the warnings library itself. I think the main benefit of this approach is that it is a lot easier to read the code and similarly (but importantly) the traceback is clearer.

I made two helper context managers strict and ignore. But I am happy to make more or fewer if people think they are nice.

EDIT: I also made a bunch of helpers for managing conformsTo I tried to make these match the style of pystac

Examples:

In [1]: from pystac_client import Client
   ...: 
   ...: client = Client.open("https://earth-search.aws.element84.com/v0")
<ipython-input-1-5ae65ebe7f0c>:3: NoConformsTo: Server does not advertise any conformance classes.
  client = Client.open("https://earth-search.aws.element84.com/v0")

In [2]: next(client.get_collections())
<ipython-input-2-fa7810f417c5>:1: FallbackToPystac: Falling back to pystac. This might be slow.
  next(client.get_collections())
Out[2]: <CollectionClient id=sentinel-s2-l2a>

In [3]: client.add_conforms_to("collections")

In [4]: next(client.get_collections())
/home/jsignell/pystac-client/pystac_client/client.py:583: MissingLink: No link with rel='data' could be found on this Client.
  href = StacApiIO._get_href(self, "data", data_link, "collections")
Out[4]: <CollectionClient id=sentinel-s2-l2a>
In [1]: import warnings
   ...: 
   ...: from pystac_client import Client
   ...: from pystac_client.warnings import FallbackToPystac
   ...: 
   ...: warnings.filterwarnings('error', category=FallbackToPystac)
   ...: 
   ...: STAC_URL = 'https://cmr.earthdata.nasa.gov/stac'
   ...: catalog = Client.open(f'{STAC_URL}/OB_DAAC')
   ...: 
   ...: for c in catalog.get_collections():
   ...:     print(c)
   ...: 
/home/jsignell/pystac-client/pystac_client/client.py:367: DoesNotConformTo: Server does not conform to COLLECTIONS or FEATURES
  warnings.warn(
---------------------------------------------------------------------------
FallbackToPystac                          Traceback (most recent call last)
Cell In[1], line 11
      8 STAC_URL = 'https://cmr.earthdata.nasa.gov/stac'
      9 catalog = Client.open(f'{STAC_URL}/OB_DAAC')
---> 11 for c in catalog.get_collections():
     12     print(c)

File ~/pystac-client/pystac_client/client.py:371, in Client.get_collections(self)
    366 if self.has_conforms_to():
    367     warnings.warn(
    368         DOES_NOT_CONFORM_TO("COLLECTIONS or FEATURES"),
    369         category=DoesNotConformTo,
    370     )
--> 371 warnings.warn(FALLBACK_MSG, category=FallbackToPystac)
    372 for collection in super().get_collections():
    373     call_modifier(self.modifier, collection)

FallbackToPystac: Falling back to pystac. This might be slow.

In [2]: catalog.add_conforms_to("COLLECTIONS")

In [3]: for c in catalog.get_collections():
   ...:     print(c)
   ...: 
/home/jsignell/pystac-client/pystac_client/stac_api_io.py:269: MissingLink: No link with rel='data' could be found on this Client.
  warnings.warn(
<CollectionClient id=Turbid9.v0>
<CollectionClient id=GreenBay.v0>
<CollectionClient id=Catlin_Arctic_Survey.v0>
<CollectionClient id=chesapeake_val_2013.v0>
<CollectionClient id=lake_erie_aug_2014.v0>
<CollectionClient id=MURI_Camouflage.v0>
<CollectionClient id=MURI_HI.v0>
<CollectionClient id=AAOT.v0>
<CollectionClient id=ACIDD.v0>
<CollectionClient id=Active_Fluorescence_2001.v0>
<CollectionClient id=OCTS_L3b_CHL.v2014>
<CollectionClient id=OCTS_L3m_CHL.v2014>
<CollectionClient id=OCTS_L1.v1>
<CollectionClient id=OCTS_L3b_KD.v2014>
<CollectionClient id=OCTS_L3m_KD.v2014>
<CollectionClient id=OCTS_L3b_IOP.v2014>
...

PR Checklist:

  • Code is formatted
  • Tests pass
  • Docs are updated
  • Changes are added to the CHANGELOG
  • (once approved) Add a note to the milestone description that we'll be doing a pre-release of this version to trial-run these changes

@codecov-commenter
Copy link

codecov-commenter commented Apr 14, 2023

Codecov Report

Patch coverage: 84.91% and project coverage change: +1.11 🎉

Comparison is base (02db5c3) 87.38% compared to head (8031adc) 88.49%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #480      +/-   ##
==========================================
+ Coverage   87.38%   88.49%   +1.11%     
==========================================
  Files          12       13       +1     
  Lines         864      965     +101     
==========================================
+ Hits          755      854      +99     
- Misses        109      111       +2     
Impacted Files Coverage Δ
pystac_client/item_search.py 94.19% <66.66%> (+0.64%) ⬆️
pystac_client/cli.py 69.56% <72.22%> (+3.15%) ⬆️
pystac_client/collection_client.py 84.61% <84.09%> (-2.49%) ⬇️
pystac_client/warnings.py 86.20% <86.20%> (ø)
pystac_client/conformance.py 89.65% <88.46%> (-10.35%) ⬇️
pystac_client/client.py 92.24% <91.66%> (+10.28%) ⬆️
pystac_client/mixins.py 94.28% <94.44%> (+2.28%) ⬆️
pystac_client/stac_api_io.py 90.99% <100.00%> (-0.21%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

pystac_client/client.py Outdated Show resolved Hide resolved
@gadomski gadomski self-requested a review April 17, 2023 18:35
@gadomski gadomski added the enhancement New feature or request label Apr 17, 2023
@gadomski gadomski added this to the 0.7.0 milestone Apr 17, 2023
pystac_client/client.py Outdated Show resolved Hide resolved
pystac_client/client.py Outdated Show resolved Hide resolved
pystac_client/client.py Outdated Show resolved Hide resolved
pystac_client/stac_api_io.py Outdated Show resolved Hide resolved
pystac_client/warnings.py Outdated Show resolved Hide resolved
pystac_client/warnings.py Outdated Show resolved Hide resolved
pystac_client/warnings.py Outdated Show resolved Hide resolved
pystac_client/warnings.py Outdated Show resolved Hide resolved
@jsignell jsignell mentioned this pull request Apr 17, 2023
3 tasks
jsignell and others added 2 commits April 17, 2023 16:56
Co-authored-by: Pete Gadomski <pete.gadomski@gmail.com>
@jsignell
Copy link
Member Author

jsignell commented May 2, 2023

How are you feeling about this @gadomski?

@gadomski gadomski self-requested a review May 2, 2023 15:42
@gadomski
Copy link
Member

gadomski commented May 2, 2023

How are you feeling about this @gadomski?

I'll take another look through today (or maybe tomorrow).

@jsignell
Copy link
Member Author

jsignell commented May 2, 2023

How are you feeling about this @gadomski?

I'll take another look through today (or maybe tomorrow).

Yeah no rush at all. Let me know if you think more docs/tests are needed

Copy link
Member

@gadomski gadomski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the CLI, I would expect warnings to be printed to stdout unless explicitly ignored? E.g. this should print a warning:

# I would expect a warning printed to stderr here, but we don't get one
$ stac-client collections https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/catalog.json
-- 8< --

# This works as expected
$ stac-client collections https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/catalog.json --error no-conforms-to
Server does not advertise any conformance classes.

pystac_client/conformance.py Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
@jsignell
Copy link
Member Author

jsignell commented May 4, 2023

$ stac-client collections https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/catalog.json

That is so wierd. It removed the logger.captureWarnings(True) line and it seems to work better. No idea why it sometimes outputs though or how to test for it. Thanks for pointing that out.

@gadomski
Copy link
Member

gadomski commented May 4, 2023

If we want to get this moving in spite of #509, I'd be ok with a ceil on the urllib3 version with a comment to remove after the next vcrpy release that includes kevin1024/vcrpy#688 (comment).

EDIT: we can ceil only in our optional dependences (dev) so we don't break any releases, IMO.

@jsignell
Copy link
Member Author

jsignell commented May 4, 2023

we can ceil only in our optional dependences (dev) so we don't break any releases, IMO.

These are still part of the release in my mind. I'd much rather not have the ceiling anywhere in a release.

@gadomski
Copy link
Member

gadomski commented May 4, 2023

These are still part of the release in my mind. I'd much rather not have the ceiling anywhere in a release.

Is this because, after release, you can still

pip install pystac_client[dev]

thereby pulling in the urllib3 ceiling? Makes sense, good point. Thanks for straightening me out.

@jsignell
Copy link
Member Author

jsignell commented May 4, 2023

Re this checkbox:

(once approved) Add a note to the milestone description that we'll be doing a pre-release of this version to trial-run these changes

Is that in the changelog or the github milestone?

@jsignell
Copy link
Member Author

jsignell commented May 4, 2023

I decided github milestone, and added a comment there.

@jsignell jsignell requested a review from gadomski May 4, 2023 15:31
@jsignell
Copy link
Member Author

jsignell commented May 4, 2023

Note: the docs test failure is expected and matches main 😿

@gadomski
Copy link
Member

gadomski commented May 4, 2023

Note: the docs test failure is expected and matches main 😿

Horray, its intermittent 😿 and fixed now 😑. Maybe has something to do with the potential release of the PC today?

Copy link
Member

@gadomski gadomski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great:

$ stac-client collections https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/catalog.json 
/Users/gadomski/Code/stac-utils/pystac-client/pystac_client/client.py:192: NoConformsTo: Server does not advertise any conformance classes.
  warnings.warn(NoConformsTo())
/Users/gadomski/Code/stac-utils/pystac-client/pystac_client/client.py:399: FallbackToPystac: Falling back to pystac. This might be slow.
  self._warn_about_fallback("COLLECTIONS", "FEATURES")
-- 8< --

Thanks for all the iterations, this is awesome!

@gadomski gadomski merged commit 6c4af70 into stac-utils:main May 4, 2023
@jsignell jsignell deleted the warnings branch May 4, 2023 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with get_collections
3 participants