-
-
Notifications
You must be signed in to change notification settings - Fork 680
feat(venv): support data, include, and scripts schemes #3726
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 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,8 @@ _BAZEL_REPO_FILE_GLOBS = [ | |||||||||||||||||||||||||||||||||||||
| "WORKSPACE.bazel", | ||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| _IS_VENV_SITE_PACKAGES_YES = Label("//python/config_settings:_is_venvs_site_packages_yes") | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def whl_library_targets_from_requires( | ||||||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||||||
| name, | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -194,8 +196,10 @@ def whl_library_targets( | |||||||||||||||||||||||||||||||||||||
| DIST_INFO_LABEL: dict( | ||||||||||||||||||||||||||||||||||||||
| include = ["site-packages/*.dist-info/**"], | ||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ## TO CHECK: should bin/ and include/ be part of the data target? | ||||||||||||||||||||||||||||||||||||||
| DATA_LABEL: dict( | ||||||||||||||||||||||||||||||||||||||
| include = ["data/**"], | ||||||||||||||||||||||||||||||||||||||
| include = ["data/**", "bin/**", "include/**"], | ||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -356,11 +360,15 @@ def whl_library_targets( | |||||||||||||||||||||||||||||||||||||
| if item not in _data_exclude: | ||||||||||||||||||||||||||||||||||||||
| _data_exclude.append(item) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| data = data + native.glob( | ||||||||||||||||||||||||||||||||||||||
| data = data + [":" + DATA_LABEL] + native.glob( | ||||||||||||||||||||||||||||||||||||||
| ["site-packages/**/*"], | ||||||||||||||||||||||||||||||||||||||
| exclude = _data_exclude, | ||||||||||||||||||||||||||||||||||||||
| allow_empty = True, | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| data = data + select({ | ||||||||||||||||||||||||||||||||||||||
| _IS_VENV_SITE_PACKAGES_YES: [DATA_LABEL], | ||||||||||||||||||||||||||||||||||||||
| "//conditions:default": [], | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+363
to
+371
Contributor
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 It is recommended to remove the unconditional addition and rely on the
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| pyi_srcs = native.glob( | ||||||||||||||||||||||||||||||||||||||
| ["site-packages/**/*.pyi"], | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -369,7 +377,7 @@ def whl_library_targets( | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if not enable_implicit_namespace_pkgs: | ||||||||||||||||||||||||||||||||||||||
| generated_namespace_package_files = select({ | ||||||||||||||||||||||||||||||||||||||
| Label("//python/config_settings:is_venvs_site_packages"): [], | ||||||||||||||||||||||||||||||||||||||
| _IS_VENV_SITE_PACKAGES_YES: [], | ||||||||||||||||||||||||||||||||||||||
| "//conditions:default": rules.create_inits( | ||||||||||||||||||||||||||||||||||||||
| srcs = srcs + data + pyi_srcs, | ||||||||||||||||||||||||||||||||||||||
| ignored_dirnames = [], # If you need to ignore certain folders, you can patch rules_python here to do so. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -275,10 +275,16 @@ def _get_file_venv_path(ctx, f, site_packages_root): | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| A tuple `(venv_path, rf_root_path)` if the file is under | ||||||||||||||||||||||||||||||||||||||||||||||||||
| `site_packages_root`, otherwise `(None, None)`. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| `site_packages_root` or data/, bin/, include/ otherwise `(None, None)`. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| rf_root_path = runfiles_root_path(ctx, f.short_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| _, _, repo_rel_path = rf_root_path.partition("/") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Check for wheel data/bin/include folders first | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for prefix in ["data/", "bin/", "include/"]: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if repo_rel_path.startswith(prefix): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return (repo_rel_path, rf_root_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| head, found_sp_root, venv_path = repo_rel_path.partition(site_packages_root) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if head or not found_sp_root: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # If head is set, then the path didn't start with site_packages_root | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -452,19 +458,36 @@ def get_venv_symlinks( | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Finally, for each group, we create the VenvSymlinkEntry objects | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for venv_path, files in optimized_groups.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if venv_path.startswith("data/"): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| out_venv_path = venv_path[len("data/"):] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| kind = VenvSymlinkKind.DATA | ||||||||||||||||||||||||||||||||||||||||||||||||||
| prefix = "" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elif venv_path.startswith("include/"): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| out_venv_path = venv_path[len("include/"):] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| kind = VenvSymlinkKind.INCLUDE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| prefix = "" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elif venv_path.startswith("bin/"): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| out_venv_path = venv_path[len("bin/"):] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| kind = VenvSymlinkKind.BIN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| prefix = "" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+461
to
+472
Contributor
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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| out_venv_path = venv_path | ||||||||||||||||||||||||||||||||||||||||||||||||||
| kind = VenvSymlinkKind.LIB | ||||||||||||||||||||||||||||||||||||||||||||||||||
| prefix = site_packages_root | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| link_to_path = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| _get_label_runfiles_repo(ctx, files[0].owner) + | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "/" + | ||||||||||||||||||||||||||||||||||||||||||||||||||
| site_packages_root + | ||||||||||||||||||||||||||||||||||||||||||||||||||
| prefix + | ||||||||||||||||||||||||||||||||||||||||||||||||||
| venv_path | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| venv_symlinks[venv_path] = VenvSymlinkEntry( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| kind = VenvSymlinkKind.LIB, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| kind = kind, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| link_to_path = link_to_path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| link_to_file = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| package = package, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| version = version_str, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| venv_path = venv_path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| venv_path = out_venv_path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| files = depset(files), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| exports_files(glob(["*"])) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .data/data |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .data/headers |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .data/platlib |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .data |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #!/bin/sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Metadata-Version: 2.1 | ||
| Name: whl-with-data | ||
| Version: 1.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| whl_with_data-1.0.data/platlib/whl_with_data/platlib_file.txt,sha256=123,123 | ||
| whl_with_data-1.0.data/scripts/whl_script.sh,sha256=123,123 | ||
| whl_with_data-1.0.data/headers/whl_with_data/header_file.h,sha256=123,123 | ||
| whl_with_data-1.0.data/purelib/whl_with_data/data_file.txt,sha256=123,123 | ||
| whl_with_data-1.0.data/data/whl_with_data/data_data_file.txt,sha256=123,123 | ||
| whl_with_data-1.0.data/data/whl_with_data/data_data_file.txt,sha256=123,123 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Wheel-Version: 1.0 |
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 internal comment should be removed or resolved before merging. Based on the implementation in
venv_runfiles.bzl, these directories are indeed necessary to be part of the runfiles so that the venv construction logic can discover and symlink them into the appropriate platform-specific locations.