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
Abstract Base Classes for index backend interface(s). #1226
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1226 +/- ##
===========================================
+ Coverage 93.75% 93.79% +0.03%
===========================================
Files 102 103 +1
Lines 10406 10597 +191
===========================================
+ Hits 9756 9939 +183
- Misses 650 658 +8
Continue to review full report at Codecov.
|
Good to see these EPs able to get some attention now. Great! |
Thanks Rob. I completely agree, that's why this is where I started! |
Also fix return type of allow_any.
This looks fine, but I'm not sure about return types being |
In general I would agree. But here I'm deliberately trying to be a bit more minimal, so as to give driver developers more flexibility in how they implement the interface. |
Honestly, I would go the other way. Force |
Yeah, I can see your point, and I probably will take this approach as I start to develop the new postgis index driver - but my approach at this stage is to avoid changing the behaviour of the existing legacy/default Postgres index driver as much as possible for as long as possible. (And certainly my intention was that this PR in particular should not change the behaviour of the legacy/default/postgres/only index driver at all.) We may well revisit this question further down the track, but I don't think this PR is right place for it. |
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.
Looks good to me 👍
-
I'm a little uneasy about leaving the old types in docstrings everywhere when they duplicate real type hints. Many of them are different to the real type hints but not any more understandable.
(I use autodoc-typehints in eodatasets' docs to try to avoid that duplication)
-
I suspect some of the methods marked as taking a "UUID" param can already accept a string too (ie, a "DSID"), but I haven't tested. It's not a high priority, but API consistency is nice.
- To bikeshed (very optional): I'm not a huge fan of the name "
DSID
", as it's a non-standard contraction, and method signatures use it alongside other UUIDs (eg: the return type) which are all technically dataset ids. I don't know what name would be better: perhapsNonstrictUUID
or something :)
""" | ||
|
||
@abstractmethod | ||
def get_all_dataset_ids(self, archived: bool) -> Iterable[str]: |
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.
I didn't notice this before, but we have one and only one method that returns dataset ids as strings instead of uuids :/
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.
Haha - that one is absolutely my fault from a previous PR - I will fix.
datacube/index/abstract.py
Outdated
""" | ||
Perform a search, returning count of results. | ||
|
||
:param dict[str,str|float|datacube.model.Range] query: |
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.
This param was wrong in the old docs. It's repeated in many other docstrings below too.
If we keep it, it should be a union, not a dict, and have the other field types in it: datetime, int.
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.
Good pickup, shall review.
Reason for this pull request
This is a first baby step towards implementing ODC-EP02, ODC-EP03 and ODC-EP04. [^1] The ODC includes some support for defining and using alternative index backends, however, only one backend implementation actually exists, and the only definition of the interface a new index backend is supposed to conform to, is the implementation of that default index backend.
This PR makes no significant code changes.
[^1] https://github.com/opendatacube/datacube-core/wiki/enhancement-proposals
Proposed changes
I have created a family of Abstract Base Classes (
abc.ABC
) for the key components of the index backend. At this stage they are simply a copy of the methods on the index backend that form the API used by the rest of the ODC. The main difference is they have been fully annotated with type hints.As work on the EP02 and EP03 continues, it is likely that these ABC interfaces will evolve. A key aim is to keep the legacy default index drive backwards compatible with its existing functionality as much as possible. This PR should not result in any functional changes. The only difference will be some internal ODC classes now have new Abstract Base Classes in their class hierarchy.
I've also added type hints to
datacube.utils.changes
- mostly for my own sanity. It's much easier to follow now, and I've fixed an historic inconsistency in the return type of theallow_any
function.Note: Some API inconsistencies have been flagged as TODO's in comments. These will be addressed in a future PR. I wanted to avoid actual API changes in the default index driver in this PR.