Repository navigation
Conversation
soxofaan
left a comment
There was a problem hiding this comment.
interesting feature
a couple of notes
| 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| @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: |
There was a problem hiding this comment.
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_sourceif 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)
There was a problem hiding this comment.
Changed to the parametrized form: include_source=[False, True] and assert read_source.called == include_source. The git lookup has the same assertion.
| 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) |
There was a problem hiding this comment.
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
openeo-python-client/tests/internal/test_warnings.py
Lines 8 to 18 in ac12204
There was a problem hiding this comment.
Caller detection now uses pytester and runs actual scripts.
| return None | ||
| try: | ||
| result = subprocess.run( | ||
| ["git", "rev-parse", "--verify", "HEAD"], |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
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 |
There was a problem hiding this comment.
🟢 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
Thanks for the suggestions. Before I rework this, would you prefer keeping For titles, should I include an |
yeah, keeping |
- 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
…-description # Conflicts: # CHANGELOG.md
|
Added I didn't add literal |
| 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. |
| *, | ||
| include_source: bool = False, | ||
| source_max_length: Optional[int] = DEFAULT_SOURCE_MAX_LENGTH, | ||
| include_git_commit: bool = False, |

Summary
Closes #476.
Adds
openeo.util.auto_description()to generate job descriptions containing:include_source=True.git_commit=True.The helper returns a string passed through the existing
descriptionargument. It does not change job titles or submission defaults.Implementation
Validation
git diff --checkpassed.