Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ END_UNRELEASED_TEMPLATE
* (pypi) To configure the environment for `requirements.txt` evaluation, use the newly added
developer preview of the `pip.default` tag class. Only `rules_python` and root modules can use
this feature. You can also configure `constraint_values` using `pip.default`.
* (pypi) PyPI dependencies now expose an `:extracted_whl_files` filegroup target
of all the files extracted from the wheel. This can be used in lieu of
{obj}`whl_filegroup` to avoid copying/extracting wheel multiple times to
get a subset of their files.

{#v0-0-0-removed}
### Removed
Expand Down
7 changes: 7 additions & 0 deletions docs/pypi/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ Note, that the hub repo contains the following targets for each package:
* `@pypi//numpy:data` - the {obj}`filegroup` that is for all of the extra files that are included
as data in the `pkg` target.
* `@pypi//numpy:dist_info` - the {obj}`filegroup` that is for all of the files in the `<pkg prefix with version>.distinfo` directory.
* `@pypi//numpy:extracted_whl_files` - a {obj}`filegroup` of all the files
extracted from the whl file.
* `@pypi//numpy:whl` - the {obj}`filegroup` that is the `.whl` file itself which includes all of
the transitive dependencies via the {attr}`filegroup.data` attribute.

:::{versionadded} VERSION_NEXT_FEATURE

The `:extracted_whl_files` target was added
:::

## Entry points

If you would like to access [entry points][whl_ep], see the `py_console_script_binary` rule documentation,
Expand Down
1 change: 1 addition & 0 deletions python/private/pypi/labels.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Constants used by parts of pip_repository for naming libraries and wheels."""

EXTRACTED_WHEEL_FILES = "extracted_whl_files"
WHEEL_FILE_PUBLIC_LABEL = "whl"
WHEEL_FILE_IMPL_LABEL = "_whl"
PY_LIBRARY_PUBLIC_LABEL = "pkg"
Expand Down
2 changes: 2 additions & 0 deletions python/private/pypi/pkg_aliases.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ load(
":labels.bzl",
"DATA_LABEL",
"DIST_INFO_LABEL",
"EXTRACTED_WHEEL_FILES",
"PY_LIBRARY_IMPL_LABEL",
"PY_LIBRARY_PUBLIC_LABEL",
"WHEEL_FILE_IMPL_LABEL",
Expand Down Expand Up @@ -151,6 +152,7 @@ def pkg_aliases(
WHEEL_FILE_PUBLIC_LABEL: WHEEL_FILE_IMPL_LABEL if group_name else WHEEL_FILE_PUBLIC_LABEL,
DATA_LABEL: DATA_LABEL,
DIST_INFO_LABEL: DIST_INFO_LABEL,
EXTRACTED_WHEEL_FILES: EXTRACTED_WHEEL_FILES,
} | {
x: x
for x in extra_aliases or []
Expand Down
29 changes: 21 additions & 8 deletions python/private/pypi/whl_library_targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ load(
":labels.bzl",
"DATA_LABEL",
"DIST_INFO_LABEL",
"EXTRACTED_WHEEL_FILES",
"PY_LIBRARY_IMPL_LABEL",
"PY_LIBRARY_PUBLIC_LABEL",
"WHEEL_ENTRY_POINT_PREFIX",
Expand Down Expand Up @@ -100,11 +101,8 @@ def whl_library_targets(
data_exclude = [],
srcs_exclude = [],
tags = [],
filegroups = {
DIST_INFO_LABEL: ["site-packages/*.dist-info/**"],
DATA_LABEL: ["data/**"],
},
dependencies = [],
filegroups = None,
dependencies_by_platform = {},
dependencies_with_markers = {},
group_deps = [],
Expand Down Expand Up @@ -134,8 +132,8 @@ def whl_library_targets(
dependencies by platform key.
dependencies_with_markers: {type}`dict[str, str]` A marker to evaluate
in order for the dep to be included.
filegroups: {type}`dict[str, list[str]]` A dictionary of the target
names and the glob matches.
filegroups: {type}`dict[str, list[str]] | None` A dictionary of the target
names and the glob matches. If `None`, defaults will be used.
group_name: {type}`str` name of the dependency group (if any) which
contains this library. If set, this library will behave as a shim
to group implementation rules which will provide simultaneously
Expand Down Expand Up @@ -168,10 +166,25 @@ def whl_library_targets(
tags = sorted(tags)
data = [] + data

for filegroup_name, glob in filegroups.items():
if filesgroups == None:
filegroups = {
EXTRACTED_WHEEL_FILES: dict(
include = ["**"],
exclude = [name],
),
DIST_INFO_LABEL: dict(
include = ["site-packages/*.dist-info/**"],
),
DATA_LABEL: dict(
include = ["data/**"],
),
}

for filegroup_name, glob_kwargs in filegroups.items():
glob_kwargs = {"allow_empty": True} | glob_kwargs
native.filegroup(
name = filegroup_name,
srcs = native.glob(glob, allow_empty = True),
srcs = native.glob(**glob_kwargs),
visibility = ["//visibility:public"],
)

Expand Down
7 changes: 7 additions & 0 deletions python/private/whl_filegroup/whl_filegroup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ cc_library(
includes = ["numpy_includes/numpy/core/include"],
deps = ["@rules_python//python/cc:current_py_cc_headers"],
)
```
:::{seealso}
The `:extracted_whl_files` target, which is a filegroup of all the files
from the already extracted whl file.
:::
""",
attrs = {
"pattern": attr.string(default = "", doc = "Only file paths matching this regex pattern will be extracted."),
Expand Down