-
-
Notifications
You must be signed in to change notification settings - Fork 698
feat(pypi): add pip.dep to declare abstract pypi dependencies #3850
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
rickeylev
wants to merge
1
commit into
bazel-contrib:main
Choose a base branch
from
rickeylev:add-pip-dep-tag-class
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.
+171
−1
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| trigger: glob | ||
| description: Starlark / Bazel .bzl file coding style rules | ||
| globs: *.bzl | ||
| --- | ||
|
|
||
| * Use triple-quoted strings for multi-line rule doc args. | ||
| * Don't use backslash line continuation in rule doc args. |
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,4 @@ | ||
| (pypi) Added a `dep` tag class to the `pip` bzlmod extension. This allows | ||
| modules to declare abstract PyPI dependencies, ensuring target structures | ||
| exist in the unified hub, while allowing other modules to provide the | ||
| concrete implementation via `pip.parse`. |
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,2 @@ | ||
| # Dummy file for integration test | ||
| print("declared_only") |
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 |
|---|---|---|
|
|
@@ -90,14 +90,21 @@ _default_tags_default = [ | |
| }.items() | ||
| ] | ||
|
|
||
| def _mod(*, name, default = _default_tags_default, parse = [], override = [], whl_mods = [], is_root = True): | ||
| def _dep(*, name, extra_targets = []): | ||
| return struct( | ||
| name = name, | ||
| extra_targets = extra_targets, | ||
| ) | ||
|
|
||
| def _mod(*, name, default = _default_tags_default, parse = [], override = [], whl_mods = [], dep = [], is_root = True): | ||
| return struct( | ||
| name = name, | ||
| tags = struct( | ||
| parse = parse, | ||
| override = override, | ||
| whl_mods = whl_mods, | ||
| default = default, | ||
| dep = dep, | ||
| ), | ||
| is_root = is_root, | ||
| ) | ||
|
|
@@ -106,6 +113,7 @@ def _parse_modules(env, **kwargs): | |
| return env.expect.that_struct( | ||
| parse_modules(**kwargs), | ||
| attrs = dict( | ||
| declared_deps = subjects.dict, | ||
| default_hub = subjects.str, | ||
| exposed_packages = subjects.dict, | ||
| hub_group_map = subjects.dict, | ||
|
|
@@ -435,6 +443,35 @@ def _test_default_hub_precedence(env): | |
|
|
||
| _tests.append(_test_default_hub_precedence) | ||
|
|
||
| def _test_extension_dep(env): | ||
| pypi = _parse_modules( | ||
| env, | ||
| module_ctx = _pypi_mock_mctx( | ||
| _mod( | ||
| name = "my_module", | ||
| dep = [ | ||
| _dep( | ||
| name = "declared-pkg", | ||
| extra_targets = ["declared-alias"], | ||
| ), | ||
|
Comment on lines
+453
to
+456
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a unit test to ensure that if we declare a dep and then it is provided by a pip.parse, that it works as expected. |
||
| ], | ||
| ), | ||
| os_name = "linux", | ||
| arch_name = "x86_64", | ||
| ), | ||
| available_interpreters = {}, | ||
| minor_mapping = {}, | ||
| ) | ||
|
|
||
| pypi.declared_deps().contains_exactly({"declared_pkg": {"declared-alias": None}}) | ||
| pypi.exposed_packages().contains_exactly({}) | ||
| pypi.hub_group_map().contains_exactly({}) | ||
| pypi.hub_whl_map().contains_exactly({}) | ||
| pypi.whl_libraries().contains_exactly({}) | ||
| pypi.whl_mods().contains_exactly({}) | ||
|
|
||
| _tests.append(_test_extension_dep) | ||
|
|
||
| def extension_test_suite(name): | ||
| """Create the test suite. | ||
|
|
||
|
|
||
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.
The keys of
mods.declared_depsare already normalized when they are populated inparse_modules(usingnormalize_name(dep_attr.name)). Therefore, callingnormalize_name(dep_name)here is redundant. We can simplify this loop by directly unpacking the normalized package name asnorm_pkg.