-
Notifications
You must be signed in to change notification settings - Fork 56
Warn about unsupported output format options #915
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |
|
|
||
| ### Added | ||
|
|
||
| - Warn when `save_result` uses output format options that are not advertised by the backend. ([#649](https://github.com/Open-EO/openeo-python-client/issues/649)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changelog has changed in the meantime, |
||
|
|
||
| ### Changed | ||
|
|
||
| ### Removed | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -856,6 +856,36 @@ def list_input_formats(self) -> dict: | |
| def list_output_formats(self) -> dict: | ||
| return self.list_file_formats().get("output", {}) | ||
|
|
||
| def _check_output_format( | ||
| self, | ||
| *, | ||
| format: str, | ||
| options: Optional[Mapping], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you mark this as optional, also give it default |
||
| ) -> None: | ||
| """Validate an output format and warn about options not advertised by the backend.""" | ||
| output_formats = self.list_output_formats() | ||
| format_name = next( | ||
| ( | ||
| name | ||
| for name in output_formats | ||
| if isinstance(name, str) and name.lower() == format.lower() | ||
| ), | ||
| None, | ||
| ) | ||
| if format_name is None: | ||
| raise ValueError(f"Invalid format {format!r}. Should be one of {set(output_formats)}") | ||
|
|
||
| format_metadata = output_formats[format_name] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simplify to something like matching = [(k, v) for (k, v) in output_formats.items() if k.lower() == format.lower()]
if len(matching) != 1:
....
[(_, format_metadata)] = matching |
||
| parameters = format_metadata.get("parameters") if isinstance(format_metadata, Mapping) else None | ||
| if options and isinstance(parameters, Mapping): | ||
| unsupported = sorted(set(options).difference(parameters)) | ||
| if unsupported: | ||
| warnings.warn( | ||
| f"Unsupported options {unsupported} for output format {format!r} " | ||
| f"(supported options: {sorted(parameters)}).", | ||
| stacklevel=3, | ||
| ) | ||
|
|
||
| list_file_types = legacy_alias( | ||
| list_output_formats, "list_file_types", since="0.4.6" | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,11 +211,15 @@ def save_result( | |
| returns a :py:class:`~openeo.rest.result.SaveResult` instance instead | ||
| of another :py:class:`~openeo.rest.vectorcube.VectorCube` instance. | ||
| """ | ||
| format = format or "GeoJSON" | ||
| if self._connection and options: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| self._connection._check_output_format(format=format, options=options) | ||
|
|
||
| pg = self._build_pgnode( | ||
| process_id="save_result", | ||
| arguments={ | ||
| "data": self, | ||
| "format": format or "GeoJSON", | ||
| "format": format, | ||
| # TODO: leave out options if unset? | ||
| "options": options or {}, | ||
| }, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.