-
-
Notifications
You must be signed in to change notification settings - Fork 630
feat: support per-wheel enable_implicit_namespace_pkgs in whl_mods (WIP) #3279
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -109,6 +109,8 @@ def generate_whl_library_build_bazel( | |||||||||||||||
kwargs["copy_executables"] = annotation.copy_executables | ||||||||||||||||
kwargs["data_exclude"] = kwargs.get("data_exclude", []) + annotation.data_exclude_glob | ||||||||||||||||
kwargs["srcs_exclude"] = annotation.srcs_exclude_glob | ||||||||||||||||
if hasattr(annotation, "enable_implicit_namespace_pkgs") and annotation.enable_implicit_namespace_pkgs != None: | ||||||||||||||||
kwargs["enable_implicit_namespace_pkgs"] = annotation.enable_implicit_namespace_pkgs | ||||||||||||||||
Comment on lines
+112
to
+113
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. To accommodate the change from The new logic should check for
Suggested change
|
||||||||||||||||
if annotation.additive_build_content: | ||||||||||||||||
additional_content.append(annotation.additive_build_content) | ||||||||||||||||
if default_python_version: | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,7 +20,8 @@ def package_annotation( | |||||||||
copy_executables = {}, | ||||||||||
data = [], | ||||||||||
data_exclude_glob = [], | ||||||||||
srcs_exclude_glob = []): | ||||||||||
srcs_exclude_glob = [], | ||||||||||
enable_implicit_namespace_pkgs = None): | ||||||||||
"""Annotations to apply to the BUILD file content from package generated from a `pip_repository` rule. | ||||||||||
|
||||||||||
[cf]: https://github.com/bazelbuild/bazel-skylib/blob/main/docs/copy_file_doc.md | ||||||||||
|
@@ -35,6 +36,8 @@ def package_annotation( | |||||||||
data_exclude_glob (list, optional): A list of exclude glob patterns to add as `data` to the generated | ||||||||||
`py_library` target. | ||||||||||
srcs_exclude_glob (list, optional): A list of labels to add as `srcs` to the generated `py_library` target. | ||||||||||
enable_implicit_namespace_pkgs (bool, optional): Override the global setting for generating __init__.py | ||||||||||
files for namespace packages. If None, uses the repository-level setting. | ||||||||||
Comment on lines
+39
to
+40
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. The type hint
Suggested change
|
||||||||||
|
||||||||||
Returns: | ||||||||||
str: A json encoded string of the provided content. | ||||||||||
|
@@ -46,4 +49,5 @@ def package_annotation( | |||||||||
data = data, | ||||||||||
data_exclude_glob = data_exclude_glob, | ||||||||||
srcs_exclude_glob = srcs_exclude_glob, | ||||||||||
enable_implicit_namespace_pkgs = enable_implicit_namespace_pkgs, | ||||||||||
)) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -49,6 +49,20 @@ simple==0.0.1 \ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _whl_mod(*, hub_name, whl_name, additive_build_content = None, additive_build_content_file = None, copy_executables = {}, copy_files = {}, data = [], data_exclude_glob = [], srcs_exclude_glob = [], enable_implicit_namespace_pkgs = None): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return struct( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
hub_name = hub_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
whl_name = whl_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
additive_build_content = additive_build_content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
additive_build_content_file = additive_build_content_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
copy_executables = copy_executables, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
copy_files = copy_files, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
data = data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
data_exclude_glob = data_exclude_glob, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
srcs_exclude_glob = srcs_exclude_glob, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
enable_implicit_namespace_pkgs = enable_implicit_namespace_pkgs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+52
to
+64
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. To align with the suggested change of using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _mod(*, name, default = [], parse = [], override = [], whl_mods = [], is_root = True): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return struct( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
name = name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -234,6 +248,69 @@ def _test_build_pipstar_platform(env): | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
_tests.append(_test_build_pipstar_platform) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _test_whl_mods_with_namespace_pkgs(env): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
pypi = _parse_modules( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
env, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
module_ctx = _mock_mctx( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
_mod( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
name = "rules_python", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
parse = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
_parse( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
hub_name = "pypi", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
python_version = "3.15", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
requirements_lock = "requirements.txt", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
whl_mods = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
_whl_mod( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
hub_name = "pypi", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
whl_name = "simple", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
additive_build_content = "# Custom build content", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
enable_implicit_namespace_pkgs = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
available_interpreters = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"python_3_15_host": "unit_test_interpreter_target", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
minor_mapping = {"3.15": "3.15.19"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
pypi.exposed_packages().contains_exactly({"pypi": ["simple"]}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
pypi.hub_group_map().contains_exactly({"pypi": {}}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
pypi.hub_whl_map().contains_exactly({"pypi": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"simple": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"pypi_315_simple": [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
whl_config_setting( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
version = "3.15", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
pypi.whl_libraries().contains_exactly({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"pypi_315_simple": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"dep_template": "@pypi//{name}:{target}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"python_interpreter_target": "unit_test_interpreter_target", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"requirement": "simple==0.0.1 --hash=sha256:deadbeef --hash=sha256:deadbaaf", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
pypi.whl_mods().contains_exactly({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"pypi": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"simple": struct( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
build_content = "# Custom build content", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
copy_files = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
copy_executables = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
data = [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
data_exclude_glob = [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
srcs_exclude_glob = [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
enable_implicit_namespace_pkgs = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
_tests.append(_test_whl_mods_with_namespace_pkgs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
def extension_test_suite(name): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Create the test suite. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
Using
attr.bool
here will not work as intended. The goal is to have a tri-state value (True, False, or not set to use the global default), butattr.bool
only supportsTrue
andFalse
. If a user does not specify this attribute, it will default toFalse
, incorrectly overriding the global setting.To correctly implement the tri-state logic, I suggest using
attr.string
with a set of allowed values, for example"True"
,"False"
, and"auto"
(for the default when not set).You will also need to update the code that consumes this attribute to handle string values, which I've commented on in
python/private/pypi/generate_whl_library_build_bazel.bzl
.