Skip to content

Add opt-in automatic job descriptions - #962

Open
minaskar wants to merge 3 commits into
Open-EO:masterfrom
minaskar:feat/476-auto-job-description
Open

minaskar wants to merge 3 commits into
Open-EO:masterfrom
minaskar:feat/476-auto-job-description

Conversation

@minaskar

Copy link
Copy Markdown

Summary

Closes #476.

Adds openeo.util.auto_description() to generate job descriptions containing:

  • The script filename and, when detected automatically, the calling function.
  • Optional full Python source with include_source=True.
  • Optional Git commit information with git_commit=True.
from openeo.util import auto_description

job = cube.create_job(
    title="Vegetation analysis",
    description=auto_description(
        src=__file__,
        include_source=True,
        git_commit=True,
    ),
)

The helper returns a string passed through the existing description argument. It does not change job titles or submission defaults.

Implementation

  • No new runtime dependencies; optional Git lookup uses the Git executable.
  • Missing or failed Git lookup logs a warning without preventing job creation.
  • Handles unavailable caller information in interactive environments.
  • Full source inclusion is explicitly opt-in, with documentation warning about sensitive information.
  • Adds API documentation, usage examples, tests, and a changelog entry.

Validation

  • Full suite on Python 3.11: 2,906 passed, 9 skipped.
  • 31 focused tests passed before committing.
  • Changed-file pre-commit hooks, CI fatal lint, and git diff --check passed.
  • Documentation built successfully.
  • A small live CDSE Sentinel-2 NDVI job finished successfully; the backend preserved the generated filename/function/Git description exactly, and its TIFF result downloaded successfully. Full source inclusion was not exercised in the live test.

@soxofaan soxofaan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

interesting feature

a couple of notes

Comment thread openeo/util.py Resolved
Comment thread openeo/util.py Resolved
Comment thread openeo/util.py Resolved
Comment thread openeo/util.py Resolved
Comment thread openeo/util.py Resolved
Comment thread tests/rest/datacube/test_datacube100.py Outdated
def test_create_job_description(self, dummy_backend, tmp_path, with_description):
src = tmp_path / "analysis.py"
src.write_text("print('café')\n", encoding="utf-8")
description = auto_description(src, include_source=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this test feels a bit misleading: it uses auto_description, but nothing is actually assert about it, it only checks passing and obtaining the description, the fact that it was generated from auto_description is not actually tested

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed auto_description from it. The test now uses a literal description and only checks the request payload; generation is covered in tests/utils/test_describe.py.

Comment thread tests/test_util.py Outdated
@pytest.mark.parametrize("path_factory", [str, pathlib.Path])
def test_explicit_source(self, tmp_path, path_factory):
src = tmp_path / "analysis.py"
with mock.patch("openeo.util.tokenize.open") as read_source, mock.patch("openeo.util.subprocess.run") as run:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this pattern is highly coupled with and assuming about implementation details, and worse will not fail even if the implementation details change

with mock.patch("openeo.util.tokenize.open") as read_source
...
read_source.assert_not_called()

this test will never flag if something is wrong with the test itself (e.g. a typo in openeo.util.tokenize.open) or the implementation changed.

you can harden this test roughly as follows:

@pytest.mark.parametrize("include_source", [False, True])
    ...
    with mock.patch("openeo.util.tokenize.open") as read_source:
        auto_description(src=path_factory(src), include_source=include_source)
    ...
    assert read_source.called == include_source

if you now have a typo in openeo.util.tokenize.open or the implementation changes, the test will also fail

(same with openeo.util.subprocess.run)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changed to the parametrized form: include_source=[False, True] and assert read_source.called == include_source. The git lookup has the same assertion.

Comment thread tests/test_util.py Outdated
source = f"description = auto_description(include_source={include_source})\n"
src.write_text(source, encoding="utf-8")
namespace = {"auto_description": auto_description}
exec(compile(source, str(src), "exec"), namespace)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For these and further tests, consider using the "pytester" fixture, which can take care of executing a python script and collecting its output, eliminating all the boilerplate here

e.g. see

def test_user_deprecation_warning(pytester):
pytester.makepyfile(myscript="""
from openeo.internal.warnings import test_warnings
test_warnings()
test_warnings(2)
""")
result = pytester.runpython("myscript.py")
stderr = "\n".join(result.errlines)
assert "This is a UserDeprecationWarning (stacklevel 1)" in stderr
assert "myscript.py:3: UserDeprecationWarning: This is a UserDeprecationWarning (stacklevel 2)" in stderr

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Caller detection now uses pytester and runs actual scripts.

Comment thread openeo/util.py Outdated
return None
try:
result = subprocess.run(
["git", "rev-parse", "--verify", "HEAD"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as mentioned above: this git command does not indicate the dirtiness of the repo, which could be important to include

and also: it returns the commit of the whole repo, not the source file itself (which could even be untracked)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, yeah. A HEAD hash alone doesn’t tell us whether it represents the script that actually ran. Would recording the repository’s HEAD commit, whether the working tree is dirty, and whether the source file is untracked cover what you had in mind?

or were you thinking of metadata focused on the source file itself? e.g. its last commit and whether it has local changes?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The description now reports the repo HEAD, whether the working tree is dirty, and whether the script is untracked. I didn't go per-file: the last commit touching the file says little when the file has local edits, and it costs an extra git call. Say if you'd still prefer that.

@soxofaan

soxofaan commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

apart from the notes above, I think it would also be interesting have an "auto title" helper, which might actually be more popular as the title is show by default in batch job listings in the openeo web editor and python client.

so in that regard, instead of the current opinionated auto_description() helper, I would also consider providing small building block helpers (one to get file name, one to get git commit, ...), so that users can quickly assemble a title and/or description based on their needs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The opt-in job provenance change has no active review issues blocking approval.

No open issues 🎉

What changed in this PR

Adds opt-in job provenance through openeo.util.auto_description(), addressing #476 without changing job titles or submission defaults. The generated text uses the existing job description argument.

Changes:

  • Generates script and caller metadata, with optional full source and Git commit information.
  • Adds tests for metadata generation, unavailable sources, Git failures, and job-description submission.
  • Documents usage, source-disclosure risks, and the new public API.
File Description
tests/​test_util.py Tests description generation and error handling.
tests/​rest/​datacube/​test_datacube100.py Tests job creation with and without generated descriptions.
openeo/​util.py Implements auto_description() and optional Git lookup.
docs/​batch_jobs.rst Adds usage examples, limitations, and sensitive-source warnings.
docs/​api.rst Includes the helper in the API reference.
CHANGELOG.md Records the new opt-in feature.

Review effort: Balanced

@minaskar

Copy link
Copy Markdown
Author

apart from the notes above, I think it would also be interesting have an "auto title" helper, which might actually be more popular as the title is show by default in batch job listings in the openeo web editor and python client.

so in that regard, instead of the current opinionated auto_description() helper, I would also consider providing small building block helpers (one to get file name, one to get git commit, ...), so that users can quickly assemble a title and/or description based on their needs

Thanks for the suggestions. Before I rework this, would you prefer keeping auto_description() as a convenience wrapper around smaller public helpers iin openeo.utils.describe, or replacing it with those helpers and showing users how to compose their own descriptions?

For titles, should I include an auto_title() helper in this PR too, or would examples using the building blocks be enough for now?

@soxofaan

Copy link
Copy Markdown
Member

Before I rework this, would you prefer keeping auto_description() as a convenience wrapper around smaller public helpers iin openeo.utils.describe, or replacing it with those helpers and showing users how to compose their own descriptions?

yeah, keeping auto_description() as convenience wrapper makes sense indeed

- Add auto_title() and get_source_path/get_function_name/get_git_info/get_source_code building blocks
- Rename git_commit to include_git_commit and add git_ref
- Report uncommitted changes and untracked source files
- Truncate included source code (1000 characters by default)
- Move out of openeo.util; rework tests and docs
@minaskar

minaskar commented Nov 4, 2026

Copy link
Copy Markdown
Author

Added auto_title() and the building blocks in openeo.utils.describe: get_source_path, get_function_name, get_git_info, get_source_code. auto_description() is now a wrapper around them. I kept auto_title() in this PR; can split it out if you'd rather keep this one smaller.

I didn't add literal get_file_name() / get_git_commit() helpers: get_source_path() returns a Path (.name is the filename) and get_git_info() returns commit plus dirty/tracked state.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The Git flags need clearer documentation of their revision-matching limitations, and the PR example uses an unsupported import path and keyword.

2 open issues

Review effort: Balanced

Comment thread openeo/utils/describe.py
Comment on lines +145 to +146
The commit is that of the whole repository, so :py:attr:`GitInfo.dirty` and
:py:attr:`GitInfo.file_tracked` tell whether the source file matches that revision.
Comment thread openeo/utils/describe.py
*,
include_source: bool = False,
source_max_length: Optional[int] = DEFAULT_SOURCE_MAX_LENGTH,
include_git_commit: bool = False,

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autogenerated job description

4 participants