-
Notifications
You must be signed in to change notification settings - Fork 103
Only remove sibling paths from cargo manifests #781
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
Merged
+167
−15
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| import os | ||
| import shutil | ||
| import tempfile | ||
| import tomli_w | ||
|
|
||
| try: | ||
| import tomllib | ||
| except ImportError: | ||
| import tomli as tomllib | ||
|
|
||
| from bloom.generators.release import ReleaseGenerator | ||
|
|
||
|
|
||
| class MockPackage: | ||
| def __init__(self, build_type): | ||
| self._build_type = build_type | ||
|
|
||
| def get_build_type(self): | ||
| return self._build_type | ||
|
|
||
|
|
||
| def test_normalize_cargo_manifest(): | ||
| # Create a temporary directory for the test | ||
| temp_dir = tempfile.mkdtemp() | ||
| try: | ||
| manifest_path = os.path.join(temp_dir, 'Cargo.toml') | ||
|
|
||
| # Define the original manifest content | ||
| original_manifest = { | ||
| 'dependencies': { | ||
| 'absolute_dep': {'path': '/abs/path/to/dep'}, | ||
| 'sibling_nested_dep': {'path': '../parent/dep'}, | ||
| 'sibling_dep': {'path': '../sibling'}, | ||
| 'subdir_dep': {'path': 'subdir/dep'}, | ||
| 'dot_subdir_dep': {'path': './subdir/dep'}, | ||
| 'nested_subdir_dep': {'path': 'subdir/sub2/../../subdir/sub3'}, | ||
| 'not_dict_dep': '1.0.0', | ||
| }, | ||
| 'dev-dependencies': { | ||
| 'dev_sibling_dep': {'path': '../dev-dep'}, | ||
| 'dev_subdir_dep': {'path': 'dev-subdir'}, | ||
| }, | ||
| 'build-dependencies': { | ||
| 'build_sibling_dep': {'path': '../build-dep'}, | ||
| 'build_subdir_dep': {'path': 'build-subdir'}, | ||
| } | ||
| } | ||
|
|
||
| # Case 1: Package of type 'cmake' (should NOT be modified or written to) | ||
| with open(manifest_path, 'wb') as f: | ||
| tomli_w.dump(original_manifest, f) | ||
|
|
||
| # Set modification time to the past | ||
| past_time = os.path.getmtime(manifest_path) - 100 | ||
| os.utime(manifest_path, (past_time, past_time)) | ||
|
|
||
| generator = ReleaseGenerator() | ||
| generator.packages = {temp_dir: MockPackage('cmake')} | ||
|
|
||
| generator._normalize_cargo_manifest(temp_dir) | ||
|
|
||
| # Assert no change to content and no write (modification time remains the same) | ||
| with open(manifest_path, 'rb') as f: | ||
| data = tomllib.load(f) | ||
| assert data == original_manifest | ||
| assert os.path.getmtime(manifest_path) == past_time | ||
|
|
||
| # Case 2: Package of type 'cargo' with no relative dependencies (should NOT be modified or written to) | ||
| manifest_no_sibling_deps = { | ||
| 'dependencies': { | ||
| 'absolute_dep': {'path': '/abs/path/to/dep'}, | ||
| 'subdir_dep': {'path': 'subdir/dep'}, | ||
| } | ||
| } | ||
| with open(manifest_path, 'wb') as f: | ||
| tomli_w.dump(manifest_no_sibling_deps, f) | ||
|
|
||
| os.utime(manifest_path, (past_time, past_time)) | ||
|
|
||
| generator.packages = {temp_dir: MockPackage('cargo')} | ||
| generator._normalize_cargo_manifest(temp_dir) | ||
|
|
||
| # Assert no change to content and no write (modification time remains the same) | ||
| with open(manifest_path, 'rb') as f: | ||
| data = tomllib.load(f) | ||
| assert data == manifest_no_sibling_deps | ||
| assert os.path.getmtime(manifest_path) == past_time | ||
|
|
||
| # Case 3: Package of type 'cargo' with parent relative dependencies (should normalize only parent relative dependencies) | ||
| with open(manifest_path, 'wb') as f: | ||
| tomli_w.dump(original_manifest, f) | ||
|
|
||
| generator._normalize_cargo_manifest(temp_dir) | ||
|
|
||
| with open(manifest_path, 'rb') as f: | ||
| data = tomllib.load(f) | ||
|
|
||
| # Let's verify each dependency after normalization | ||
| deps = data['dependencies'] | ||
|
|
||
| # Absolute path - preserved! | ||
| assert deps['absolute_dep']['path'] == '/abs/path/to/dep' | ||
| assert 'version' not in deps['absolute_dep'] | ||
|
|
||
| # Parent referencing path - dropped and version set to * | ||
| assert 'path' not in deps['sibling_nested_dep'] | ||
| assert deps['sibling_nested_dep']['version'] == '*' | ||
|
|
||
| assert 'path' not in deps['sibling_dep'] | ||
| assert deps['sibling_dep']['version'] == '*' | ||
|
|
||
| # Subdirectory path - preserved! | ||
| assert deps['subdir_dep']['path'] == 'subdir/dep' | ||
| assert 'version' not in deps['subdir_dep'] | ||
|
|
||
| assert deps['dot_subdir_dep']['path'] == './subdir/dep' | ||
| assert 'version' not in deps['dot_subdir_dep'] | ||
|
|
||
| assert deps['nested_subdir_dep']['path'] == 'subdir/sub2/../../subdir/sub3' | ||
| assert 'version' not in deps['nested_subdir_dep'] | ||
|
|
||
| # dev-dependencies | ||
| dev_deps = data['dev-dependencies'] | ||
| assert 'path' not in dev_deps['dev_sibling_dep'] | ||
| assert dev_deps['dev_sibling_dep']['version'] == '*' | ||
| assert dev_deps['dev_subdir_dep']['path'] == 'dev-subdir' | ||
|
|
||
| # build-dependencies | ||
| build_deps = data['build-dependencies'] | ||
| assert 'path' not in build_deps['build_sibling_dep'] | ||
| assert build_deps['build_sibling_dep']['version'] == '*' | ||
| assert build_deps['build_subdir_dep']['path'] == 'build-subdir' | ||
|
|
||
| finally: | ||
| shutil.rmtree(temp_dir) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my mental model,
../siblingit's a sibling of my current crate, correct, but I don't see why../parent/depit's a parent. Looks like it's a child of another sibling, a nephew?Maybe I'm getting something wrong
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is maybe just a mismatch in nomenclature between what I asked Gemini to do and how I write the commit description.
All of these paths are from the perspective of a package at it's root directory. We archive the packages from that directory, so anything above it (starting with
../) is removed by Bloom's package-level processing and will NOT be present when the package is built on the buildfarm.Maybe we just call these
sibling_depandnested_sibling_dep. Doesn't really matter, either way they should be removed (and possibly converted to aversion = '*'constraint).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That change sounds good to me then, that renaming would makes sense from the description and matches the test behavior