Skip to content

Commit 1cd9b1d

Browse files
committed
Synchronize docs between DataCube, VectorCube, ...
use tests to enforce keeping docs in sync related to #402/#720/#725
1 parent 0fa49c3 commit 1cd9b1d

File tree

8 files changed

+258
-107
lines changed

8 files changed

+258
-107
lines changed

openeo/internal/documentation.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import collections
66
import inspect
7+
import re
78
import textwrap
89
from functools import partial
9-
from typing import Callable, Optional, Tuple, TypeVar
10+
from typing import Callable, Dict, Optional, Tuple, TypeVar, Union
1011

1112
# TODO: give this a proper public API?
1213
_process_registry = collections.defaultdict(list)
@@ -58,3 +59,39 @@ def decorate(f: Callable) -> Callable:
5859
return f
5960

6061
return decorate
62+
63+
64+
def _get_doc(obj: Union[str, Callable]) -> str:
65+
"""
66+
Get docstring of a method or function.
67+
"""
68+
if isinstance(obj, str):
69+
doc = obj
70+
else:
71+
doc = obj.__doc__
72+
return textwrap.dedent(doc)
73+
74+
75+
def extract_params(doc: Union[str, Callable]) -> Dict[str, str]:
76+
"""
77+
Extract parameters (``:param name:`` format) from a docstring.
78+
"""
79+
doc = _get_doc(doc)
80+
params_regex = re.compile(r"^:param\s+(?P<param>\w+)\s*:(?P<doc>.*(\n +.*)*)", re.MULTILINE)
81+
return {m.group("param"): m.group("doc").strip() for m in params_regex.finditer(doc)}
82+
83+
84+
def assert_same_param_docs(doc_a: Union[str, Callable], doc_b: Union[str, Callable], only_intersection: bool = False):
85+
"""
86+
Compare parameters (``:param name:`` format) from two docstrings.
87+
"""
88+
# TODO: option to also check order?
89+
params_a = extract_params(doc_a)
90+
params_b = extract_params(doc_b)
91+
92+
if only_intersection:
93+
intersection = set(params_a.keys()).intersection(params_b.keys())
94+
params_a = {k: v for k, v in params_a.items() if k in intersection}
95+
params_b = {k: v for k, v in params_b.items() if k in intersection}
96+
97+
assert params_a == params_b

openeo/rest/datacube.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,7 @@ def save_result(
23382338
Materialize the processed data to the given file format.
23392339
23402340
:param format: an output format supported by the backend.
2341-
:param options: file format options
2341+
:param options: (optional) file format options
23422342
23432343
.. versionchanged:: 0.39.0
23442344
returns a :py:class:`~openeo.rest.result.SaveResult` instance instead
@@ -2389,14 +2389,14 @@ def download(
23892389
If outputfile is provided, the result is stored on disk locally, otherwise, a bytes object is returned.
23902390
The bytes object can be passed on to a suitable decoder for decoding.
23912391
2392-
:param outputfile: Optional, output path to download to.
2393-
:param format: Optional, an output format supported by the backend.
2394-
:param options: Optional, file format options
2395-
:param validate: Optional toggle to enable/prevent validation of the process graphs before execution
2392+
:param outputfile: (optional) output path to download to.
2393+
:param format: (optional) an output format supported by the backend.
2394+
:param options: (optional) file format options
2395+
:param validate: (optional) toggle to enable/prevent validation of the process graphs before execution
23962396
(overruling the connection's ``auto_validate`` setting).
2397-
:param auto_add_save_result: Automatically add a ``save_result`` node to the process graph.
2398-
:param additional: additional (top-level) properties to set in the request body
2399-
:param job_options: dictionary of job options to pass to the backend
2397+
:param auto_add_save_result: whether to automatically add a ``save_result`` node to the process graph.
2398+
:param additional: (optional) additional (top-level) properties to set in the request body
2399+
:param job_options: (optional) dictionary of job options to pass to the backend
24002400
(under top-level property "job_options")
24012401
24022402
:return: None if the result is stored to disk, or a bytes object returned by the backend.
@@ -2544,24 +2544,25 @@ def execute_batch(
25442544
for batch jobs that are expected to complete
25452545
in a time that is reasonable for your use case.
25462546
2547-
:param outputfile: Optional, output path to download to.
2548-
:param out_format: (optional) File format to use for the job result.
2549-
:param title: job title.
2550-
:param description: job description.
2551-
:param plan: The billing plan to process and charge the job with
2552-
:param budget: Maximum budget to be spent on executing the job.
2547+
:param outputfile: (optional) output path to download to.
2548+
:param out_format: (optional) file format to use for the job result.
2549+
:param title: (optional) job title.
2550+
:param description: (optional) job description.
2551+
:param plan: (optional) the billing plan to process and charge the job with.
2552+
:param budget: (optional) maximum budget to be spent on executing the job.
25532553
Note that some backends do not honor this limit.
2554-
:param additional: additional (top-level) properties to set in the request body
2555-
:param job_options: dictionary of job options to pass to the backend
2554+
:param additional: (optional) additional (top-level) properties to set in the request body
2555+
:param job_options: (optional) dictionary of job options to pass to the backend
25562556
(under top-level property "job_options")
2557-
:param validate: Optional toggle to enable/prevent validation of the process graphs before execution
2557+
:param validate: (optional) toggle to enable/prevent validation of the process graphs before execution
25582558
(overruling the connection's ``auto_validate`` setting).
2559-
:param auto_add_save_result: Automatically add a ``save_result`` node to the process graph.
2559+
:param auto_add_save_result: whether to automatically add a ``save_result`` node to the process graph.
25602560
:param show_error_logs: whether to automatically print error logs when the batch job failed.
2561-
:param log_level: Optional minimum severity level for log entries that the back-end should keep track of.
2561+
:param log_level: (optional) minimum severity level for log entries that the back-end should keep track of.
25622562
One of "error" (highest severity), "warning", "info", and "debug" (lowest severity).
25632563
:param max_poll_interval: maximum number of seconds to sleep between job status polls
25642564
:param connection_retry_interval: how long to wait when status poll failed due to connection issue
2565+
:param print: print/logging function to show progress/status
25652566
25662567
.. versionchanged:: 0.32.0
25672568
Added ``auto_add_save_result`` option
@@ -2632,22 +2633,22 @@ def create_job(
26322633
Use :py:meth:`execute_batch` instead to let the openEO Python client
26332634
take care of the full job life cycle: create, start and track its progress until completion.
26342635
2635-
:param out_format: output file format.
2636-
:param title: job title.
2637-
:param description: job description.
2638-
:param plan: The billing plan to process and charge the job with.
2639-
:param budget: Maximum budget to be spent on executing the job.
2636+
:param out_format: (optional) file format to use for the job result.
2637+
:param title: (optional) job title.
2638+
:param description: (optional) job description.
2639+
:param plan: (optional) the billing plan to process and charge the job with.
2640+
:param budget: (optional) maximum budget to be spent on executing the job.
26402641
Note that some backends do not honor this limit.
2641-
:param additional: additional (top-level) properties to set in the request body
2642-
:param job_options: dictionary of job options to pass to the backend
2642+
:param additional: (optional) additional (top-level) properties to set in the request body
2643+
:param job_options: (optional) dictionary of job options to pass to the backend
26432644
(under top-level property "job_options")
2644-
:param validate: Optional toggle to enable/prevent validation of the process graphs before execution
2645+
:param validate: (optional) toggle to enable/prevent validation of the process graphs before execution
26452646
(overruling the connection's ``auto_validate`` setting).
2646-
:param auto_add_save_result: Automatically add a ``save_result`` node to the process graph.
2647-
:param log_level: Optional minimum severity level for log entries that the back-end should keep track of.
2647+
:param auto_add_save_result: whether to automatically add a ``save_result`` node to the process graph.
2648+
:param log_level: (optional) minimum severity level for log entries that the back-end should keep track of.
26482649
One of "error" (highest severity), "warning", "info", and "debug" (lowest severity).
26492650
2650-
:return: Created job.
2651+
:return: Handle for the job created at the backend.
26512652
26522653
.. versionchanged:: 0.32.0
26532654
Added ``auto_add_save_result`` option

openeo/rest/mlmodel.py

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,37 @@ def execute_batch(
7979
log_level: Optional[str] = None,
8080
) -> BatchJob:
8181
"""
82-
Evaluate the process graph by creating a batch job, and retrieving the results when it is finished.
83-
This method is mostly recommended if the batch job is expected to run in a reasonable amount of time.
84-
85-
For very long-running jobs, you probably do not want to keep the client running.
86-
87-
:param job_options:
88-
:param outputfile: The path of a file to which a result can be written
89-
:param out_format: (optional) Format of the job result.
90-
:param format_options: String Parameters for the job result format
91-
:param additional: additional (top-level) properties to set in the request body
92-
:param job_options: dictionary of job options to pass to the backend
82+
Execute the underlying process graph at the backend in batch job mode:
83+
84+
- create the job (like :py:meth:`create_job`)
85+
- start the job (like :py:meth:`BatchJob.start() <openeo.rest.job.BatchJob.start>`)
86+
- track the job's progress with an active polling loop
87+
(like :py:meth:`BatchJob.run_synchronous() <openeo.rest.job.BatchJob.run_synchronous>`)
88+
- optionally (if ``outputfile`` is specified) download the job's results
89+
when the job finished successfully
90+
91+
.. note::
92+
Because of the active polling loop,
93+
which blocks any further progress of your script or application,
94+
this :py:meth:`execute_batch` method is mainly recommended
95+
for batch jobs that are expected to complete
96+
in a time that is reasonable for your use case.
97+
98+
:param outputfile: (optional) output path to download to.
99+
:param title: (optional) job title.
100+
:param description: (optional) job description.
101+
:param plan: (optional) the billing plan to process and charge the job with.
102+
:param budget: (optional) maximum budget to be spent on executing the job.
103+
Note that some backends do not honor this limit.
104+
:param additional: (optional) additional (top-level) properties to set in the request body
105+
:param job_options: (optional) dictionary of job options to pass to the backend
93106
(under top-level property "job_options")
94107
:param show_error_logs: whether to automatically print error logs when the batch job failed.
95-
:param log_level: Optional minimum severity level for log entries that the back-end should keep track of.
108+
:param log_level: (optional) minimum severity level for log entries that the back-end should keep track of.
96109
One of "error" (highest severity), "warning", "info", and "debug" (lowest severity).
97110
:param max_poll_interval: maximum number of seconds to sleep between job status polls
98111
:param connection_retry_interval: how long to wait when status poll failed due to connection issue
112+
:param print: print/logging function to show progress/status
99113
100114
.. versionchanged:: 0.36.0
101115
Added argument ``additional``.
@@ -136,18 +150,25 @@ def create_job(
136150
log_level: Optional[str] = None,
137151
) -> BatchJob:
138152
"""
139-
Sends a job to the backend and returns a ClientJob instance.
153+
Send the underlying process graph to the backend
154+
to create an openEO batch job
155+
and return a corresponding :py:class:`~openeo.rest.job.BatchJob` instance.
156+
157+
Note that this method only *creates* the openEO batch job at the backend,
158+
but it does not *start* it.
159+
Use :py:meth:`execute_batch` instead to let the openEO Python client
160+
take care of the full job life cycle: create, start and track its progress until completion.
161+
140162
141-
:param title: job title
142-
:param description: job description
143-
:param plan: The billing plan to process and charge the job with
144-
:param budget: Maximum budget to be spent on executing the job.
163+
:param title: (optional) job title.
164+
:param description: (optional) job description.
165+
:param plan: (optional) the billing plan to process and charge the job with.
166+
:param budget: (optional) maximum budget to be spent on executing the job.
145167
Note that some backends do not honor this limit.
146-
:param additional: additional (top-level) properties to set in the request body
147-
:param job_options: dictionary of job options to pass to the backend
168+
:param additional: (optional) additional (top-level) properties to set in the request body
169+
:param job_options: (optional) dictionary of job options to pass to the backend
148170
(under top-level property "job_options")
149-
:param format_options: String Parameters for the job result format
150-
:param log_level: Optional minimum severity level for log entries that the back-end should keep track of.
171+
:param log_level: (optional) minimum severity level for log entries that the back-end should keep track of.
151172
One of "error" (highest severity), "warning", "info", and "debug" (lowest severity).
152173
:return: Created job.
153174

openeo/rest/result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SaveResult(StacResource):
1010
and :py:meth:`VectorCube.save_result() <openeo.rest.vectorcube.VectorCube.save_result>`.
1111
1212
.. note ::
13-
This class is practically a just direct alias for
13+
This class is practically just a direct alias for
1414
:py:class:`~openeo.rest.stac_resource.StacResource`,
1515
but with a more self-explanatory name.
1616

openeo/rest/stac_resource.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def download(
7474
If outputfile is provided, the result is stored on disk locally, otherwise, a bytes object is returned.
7575
The bytes object can be passed on to a suitable decoder for decoding.
7676
77-
:param outputfile: Optional, output path to download to.
78-
:param validate: Optional toggle to enable/prevent validation of the process graphs before execution
77+
:param outputfile: (optional) output path to download to.
78+
:param validate: (optional) toggle to enable/prevent validation of the process graphs before execution
7979
(overruling the connection's ``auto_validate`` setting).
80-
:param additional: additional (top-level) properties to set in the request body
81-
:param job_options: dictionary of job options to pass to the backend
80+
:param additional: (optional) additional (top-level) properties to set in the request body
81+
:param job_options: (optional) dictionary of job options to pass to the backend
8282
(under top-level property "job_options")
8383
8484
:return: None if the result is stored to disk, or a bytes object returned by the backend.
@@ -113,17 +113,17 @@ def create_job(
113113
Use :py:meth:`execute_batch` instead to let the openEO Python client
114114
take care of the full job life cycle: create, start and track its progress until completion.
115115
116-
:param title: job title.
117-
:param description: job description.
118-
:param plan: The billing plan to process and charge the job with.
119-
:param budget: Maximum budget to be spent on executing the job.
116+
:param title: (optional) job title.
117+
:param description: (optional) job description.
118+
:param plan: (optional) the billing plan to process and charge the job with.
119+
:param budget: (optional) maximum budget to be spent on executing the job.
120120
Note that some backends do not honor this limit.
121-
:param additional: additional (top-level) properties to set in the request body
122-
:param job_options: dictionary of job options to pass to the backend
121+
:param additional: (optional) additional (top-level) properties to set in the request body
122+
:param job_options: (optional) dictionary of job options to pass to the backend
123123
(under top-level property "job_options")
124-
:param validate: Optional toggle to enable/prevent validation of the process graphs before execution
124+
:param validate: (optional) toggle to enable/prevent validation of the process graphs before execution
125125
(overruling the connection's ``auto_validate`` setting).
126-
:param log_level: Optional minimum severity level for log entries that the back-end should keep track of.
126+
:param log_level: (optional) minimum severity level for log entries that the back-end should keep track of.
127127
One of "error" (highest severity), "warning", "info", and "debug" (lowest severity).
128128
129129
:return: Handle for the job created at the backend.
@@ -174,18 +174,18 @@ def execute_batch(
174174
for batch jobs that are expected to complete
175175
in a time that is reasonable for your use case.
176176
177-
:param outputfile: Optional, output path to download to.
178-
:param title: job title.
179-
:param description: job description.
180-
:param plan: The billing plan to process and charge the job with
181-
:param budget: Maximum budget to be spent on executing the job.
177+
:param outputfile: (optional) output path to download to.
178+
:param title: (optional) job title.
179+
:param description: (optional) job description.
180+
:param plan: (optional) the billing plan to process and charge the job with.
181+
:param budget: (optional) maximum budget to be spent on executing the job.
182182
Note that some backends do not honor this limit.
183-
:param additional: additional (top-level) properties to set in the request body
184-
:param job_options: dictionary of job options to pass to the backend
183+
:param additional: (optional) additional (top-level) properties to set in the request body
184+
:param job_options: (optional) dictionary of job options to pass to the backend
185185
(under top-level property "job_options")
186-
:param validate: Optional toggle to enable/prevent validation of the process graphs before execution
186+
:param validate: (optional) toggle to enable/prevent validation of the process graphs before execution
187187
(overruling the connection's ``auto_validate`` setting).
188-
:param log_level: Optional minimum severity level for log entries that the back-end should keep track of.
188+
:param log_level: (optional) minimum severity level for log entries that the back-end should keep track of.
189189
One of "error" (highest severity), "warning", "info", and "debug" (lowest severity).
190190
:param print: print/logging function to show progress/status
191191
:param max_poll_interval: maximum number of seconds to sleep between job status polls

0 commit comments

Comments
 (0)