-
-
Notifications
You must be signed in to change notification settings - Fork 678
fix: namespace package calculation on windows #3693
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
rickeylev
merged 10 commits into
bazel-contrib:main
from
rickeylev:fix.namespace.packages.windows
Apr 12, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bcc6cab
fix: namespace package on windows
rickeylev 5ec7baa
fix relative path computation
rickeylev 0fc2a9c
add test, fix mixed case
rickeylev a2d7aba
refacator mocks to mocks
rickeylev 20f6024
add more tests
rickeylev 5dc5668
format
rickeylev 48fbf1d
format
rickeylev 4dcbd6e
format
rickeylev 84d929b
format
rickeylev bad3352
remove window CR
rickeylev 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| load(":repo_utils_test.bzl", "repo_utils_test_suite") | ||
|
|
||
| repo_utils_test_suite(name = "repo_utils_tests") |
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,59 @@ | ||
| """Unit tests for repo_utils.bzl.""" | ||
|
|
||
| load("@rules_testing//lib:test_suite.bzl", "test_suite") | ||
| load("//python/private:repo_utils.bzl", "repo_utils") # buildifier: disable=bzl-visibility | ||
| load("//tests/support:mocks.bzl", "mocks") | ||
|
|
||
| _tests = [] | ||
|
|
||
| def _test_get_platforms_os_name(env): | ||
| mock_mrctx = mocks.rctx(os_name = "Mac OS X") | ||
| got = repo_utils.get_platforms_os_name(mock_mrctx) | ||
| env.expect.that_str(got).equals("osx") | ||
|
|
||
| _tests.append(_test_get_platforms_os_name) | ||
|
|
||
| def _test_relative_to(env): | ||
| mock_mrctx_linux = mocks.rctx(os_name = "linux") | ||
| mock_mrctx_win = mocks.rctx(os_name = "windows") | ||
|
|
||
| # Case-sensitive matching (Linux) | ||
| got = repo_utils.relative_to(mock_mrctx_linux, "foo/bar/baz", "foo/bar") | ||
| env.expect.that_str(got).equals("baz") | ||
|
|
||
| # Case-insensitive matching (Windows) | ||
| got = repo_utils.relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "c:/foo/bar") | ||
| env.expect.that_str(got).equals("Baz") | ||
|
|
||
| # Failure case | ||
| failures = [] | ||
|
|
||
| def _mock_fail(msg): | ||
| failures.append(msg) | ||
|
|
||
| repo_utils.relative_to(mock_mrctx_linux, "foo/bar/baz", "qux", fail = _mock_fail) | ||
| env.expect.that_collection(failures).contains_exactly(["foo/bar/baz is not relative to qux"]) | ||
|
|
||
| _tests.append(_test_relative_to) | ||
|
|
||
| def _test_is_relative_to(env): | ||
| mock_mrctx_linux = mocks.rctx(os_name = "linux") | ||
| mock_mrctx_win = mocks.rctx(os_name = "windows") | ||
|
|
||
| # Case-sensitive matching (Linux) | ||
| env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_linux, "foo/bar/baz", "foo/bar")).equals(True) | ||
| env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_linux, "foo/bar/baz", "qux")).equals(False) | ||
|
|
||
| # Case-insensitive matching (Windows) | ||
| env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "c:/foo/bar")).equals(True) | ||
| env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "D:/Foo")).equals(False) | ||
|
|
||
| _tests.append(_test_is_relative_to) | ||
|
|
||
| def repo_utils_test_suite(name): | ||
| """Create the test suite. | ||
|
|
||
| Args: | ||
| name: the name of the test suite | ||
| """ | ||
| test_suite(name = name, basic_tests = _tests) |
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,31 @@ | ||
| """Mocks for testing.""" | ||
|
|
||
| def _rctx(os_name = "linux", os_arch = "x86_64", environ = None, **kwargs): | ||
| """Creates a mock of repository_ctx or module_ctx. | ||
|
|
||
| Args: | ||
| os_name: The OS name to mock (e.g., "linux", "Mac OS X", "windows"). | ||
| os_arch: The OS architecture to mock (e.g., "x86_64", "aarch64"). | ||
| environ: A dictionary representing the environment variables. | ||
| **kwargs: Additional attributes to add to the mock struct. | ||
|
|
||
| Returns: | ||
| A struct mocking repository_ctx. | ||
| """ | ||
| if environ == None: | ||
| environ = {} | ||
|
|
||
| attrs = { | ||
| "getenv": environ.get, | ||
| "os": struct( | ||
| name = os_name, | ||
| arch = os_arch, | ||
| ), | ||
| } | ||
| attrs.update(kwargs) | ||
|
|
||
| return struct(**attrs) | ||
|
|
||
| mocks = struct( | ||
| rctx = _rctx, | ||
| ) |
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.