-
-
Notifications
You must be signed in to change notification settings - Fork 639
refactor(gazelle): Generate a modules map per wheel, then merge #3415
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
dougthor42
merged 5 commits into
bazel-contrib:main
from
thejcannon:jcannon/split-the-gen
Nov 18, 2025
Merged
Changes from all commits
Commits
Show all changes
5 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
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
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,45 @@ | ||
| #!/usr/bin/env python3 | ||
| """Merges multiple modules_mapping.json files into a single file.""" | ||
|
|
||
| import argparse | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def merge_modules_mappings(input_files: list[Path], output_file: Path) -> None: | ||
| """Merge multiple modules_mapping.json files into one. | ||
|
|
||
| Args: | ||
| input_files: List of paths to input JSON files to merge | ||
| output_file: Path where the merged output should be written | ||
| """ | ||
| merged_mapping = {} | ||
| for input_file in input_files: | ||
| mapping = json.loads(input_file.read_text()) | ||
| # Merge the mappings, with later files overwriting earlier ones | ||
| # if there are conflicts | ||
| merged_mapping.update(mapping) | ||
|
|
||
| output_file.write_text(json.dumps(merged_mapping)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser( | ||
| description="Merge multiple modules_mapping.json files" | ||
| ) | ||
| parser.add_argument( | ||
| "--output", | ||
| required=True, | ||
| type=Path, | ||
| help="Output file path for merged mapping", | ||
| ) | ||
| parser.add_argument( | ||
| "--inputs", | ||
| required=True, | ||
| nargs="+", | ||
| type=Path, | ||
| help="Input JSON files to merge", | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
| merge_modules_mappings(args.inputs, args.output) |
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,61 @@ | ||
| import pathlib | ||
| import unittest | ||
| import json | ||
| import tempfile | ||
|
|
||
| from merger import merge_modules_mappings | ||
|
|
||
|
|
||
| class MergerTest(unittest.TestCase): | ||
| _tmpdir: tempfile.TemporaryDirectory | ||
|
|
||
| def setUp(self) -> None: | ||
| super().setUp() | ||
| self._tmpdir = tempfile.TemporaryDirectory() | ||
|
|
||
| def tearDown(self) -> None: | ||
| super().tearDown() | ||
| self._tmpdir.cleanup() | ||
| del self._tmpdir | ||
|
|
||
| @property | ||
| def tmppath(self) -> pathlib.Path: | ||
| return pathlib.Path(self._tmpdir.name) | ||
|
|
||
| def make_input(self, mapping: dict[str, str]) -> pathlib.Path: | ||
| _fd, file = tempfile.mkstemp(suffix=".json", dir=self._tmpdir.name) | ||
| path = pathlib.Path(file) | ||
| path.write_text(json.dumps(mapping)) | ||
| return path | ||
|
|
||
| def test_merger(self): | ||
| output_path = self.tmppath / "output.json" | ||
| merge_modules_mappings( | ||
| [ | ||
| self.make_input( | ||
| { | ||
| "_pytest": "pytest", | ||
| "_pytest.__init__": "pytest", | ||
| "_pytest._argcomplete": "pytest", | ||
| "_pytest.config.argparsing": "pytest", | ||
| } | ||
| ), | ||
| self.make_input({"django_types": "django_types"}), | ||
| ], | ||
| output_path, | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| { | ||
| "_pytest": "pytest", | ||
| "_pytest.__init__": "pytest", | ||
| "_pytest._argcomplete": "pytest", | ||
| "_pytest.config.argparsing": "pytest", | ||
| "django_types": "django_types", | ||
| }, | ||
| json.loads(output_path.read_text()), | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.