-
Notifications
You must be signed in to change notification settings - Fork 17
feat(utils)!: store vcs info in metadata #268
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
Open
ways
wants to merge
6
commits into
ecmwf:main
Choose a base branch
from
ways:feat(utils)!-store-vcs-info-in-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+125
−6
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
88c20ea
Read direct_url.json if available, and add more VCS metadata. Add pyt…
ways 39a964e
Merge branch 'ecmwf:main' into feat(utils)!-store-vcs-info-in-metadata
ways 4826504
Flatten try tests in _get_package_source_url. Always return version d…
ways 241b4fd
Simplify comment
ways 0dd4ee7
Update src/anemoi/utils/provenance.py
ways 3a71258
Fix comment to be more precise
ways File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,77 @@ | |
| # nor does it submit to any jurisdiction. | ||
|
|
||
|
|
||
| import json | ||
| import sys | ||
| import tempfile | ||
| from pathlib import Path | ||
|
|
||
| from anemoi.utils import provenance | ||
|
|
||
|
|
||
| def test_gather() -> None: | ||
| """Test success of gather_provenance_info.""" | ||
| provenance.gather_provenance_info() | ||
|
|
||
|
|
||
| def test_get_package_source_url_with_git_integration(): | ||
| """Test _get_package_source_url on a synthetic .dist-info structure. | ||
|
|
||
| Create a temporary package metadata directory that Python's importlib.metadata | ||
| can read | ||
| """ | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| # This is what pip creates when installing a package | ||
| dist_info = Path(tmpdir) / "test_git_package-1.0.0.dist-info" | ||
| dist_info.mkdir() | ||
|
|
||
| # Create METADATA file (required for importlib.metadata to recognize it) | ||
| metadata_content = """Metadata-Version: 2.1 | ||
| Name: test-git-package | ||
| Version: 1.0.0 | ||
| """ | ||
| (dist_info / "METADATA").write_text(metadata_content) | ||
|
|
||
| # Create direct_url.json - this is what pip creates for git installs | ||
| direct_url_content = { | ||
| "url": "git+https://github.com/ways/[email protected]", | ||
| "vcs_info": { | ||
| "commit_id": "abc123def456", | ||
| "requested_revision": "models-0.12.0", | ||
| "vcs": "git", | ||
| }, | ||
| "subdirectory": "models", | ||
| } | ||
| (dist_info / "direct_url.json").write_text(json.dumps(direct_url_content)) | ||
|
|
||
| # Add tmpdir to sys.path so importlib.metadata can discover it | ||
| sys.path.insert(0, tmpdir) | ||
|
|
||
| try: | ||
| result = provenance._get_package_source_url("test-git-package") | ||
|
|
||
| assert result is not None, "Should return source info for git package" | ||
| assert result["url"] == "git+https://github.com/ways/[email protected]" | ||
| assert result["vcs_info"]["commit_id"] == "abc123def456" | ||
| assert result["vcs_info"]["requested_revision"] == "models-0.12.0" | ||
| assert result["subdirectory"] == "models" | ||
|
|
||
| finally: | ||
| # Clean up | ||
| sys.path.remove(tmpdir) | ||
|
|
||
|
|
||
| def test_get_package_source_url_regular_package_integration(): | ||
| """Test with a real regular package installed from PyPI.""" | ||
| # pip is always installed and almost always from PyPI, not git | ||
| result = provenance._get_package_source_url("pip") | ||
|
|
||
| # For a regular PyPI package, should return None (no direct_url.json) | ||
| # In rare dev environments pip might be from git, but that's also valid | ||
| assert result is None or isinstance(result, dict) | ||
|
|
||
|
|
||
| def test_get_package_source_url_nonexistent(): | ||
| """Test with a package that doesn't exist.""" | ||
| result = provenance._get_package_source_url("nonexistent-package-xyz-12345") | ||
| assert result is None | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.