|
1 |
| -""" |
2 |
| -Python wheel repository rules. |
3 |
| -
|
4 |
| -The calculated wheel version suffix depends on the wheel type: |
5 |
| -- nightly: .dev{build_date} |
6 |
| -- release: ({custom_version_suffix})? |
7 |
| -- custom: .dev{build_date}(+{git_hash})?({custom_version_suffix})? |
8 |
| -- snapshot (default): -0 |
9 |
| -
|
10 |
| -The following environment variables can be set: |
11 |
| -{wheel_type}: ML_WHEEL_TYPE |
12 |
| -{build_date}: ML_WHEEL_BUILD_DATE (should be YYYYMMDD or YYYY-MM-DD) |
13 |
| -{git_hash}: ML_WHEEL_GIT_HASH |
14 |
| -{custom_version_suffix}: ML_WHEEL_VERSION_SUFFIX |
15 |
| -
|
16 |
| -Examples: |
17 |
| -1. nightly wheel version: 2.19.0.dev20250107 |
18 |
| - Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=nightly |
19 |
| - --repo_env=ML_WHEEL_BUILD_DATE=20250107 |
20 |
| -2. release wheel version: 2.19.0 |
21 |
| - Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=release |
22 |
| -3. release candidate wheel version: 2.19.0-rc1 |
23 |
| - Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=release |
24 |
| - --repo_env=ML_WHEEL_VERSION_SUFFIX=-rc1 |
25 |
| -4. custom wheel version: 2.19.0.dev20250107+cbe478fc5-custom |
26 |
| - Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=custom |
27 |
| - --repo_env=ML_WHEEL_BUILD_DATE=$(git show -s --format=%as HEAD) |
28 |
| - --repo_env=ML_WHEEL_GIT_HASH=$(git rev-parse HEAD) |
29 |
| - --repo_env=ML_WHEEL_VERSION_SUFFIX=-custom |
30 |
| -5. snapshot wheel version: 2.19.0-0 |
31 |
| - Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=snapshot |
32 |
| -
|
33 |
| -""" |
| 1 | +""" Repository and build rules for Python wheels packaging utilities. """ |
34 | 2 |
|
35 | 3 | def _get_host_environ(repository_ctx, name, default_value = None):
|
36 | 4 | """Returns the value of an environment variable on the host platform.
|
@@ -127,3 +95,64 @@ python_wheel_version_suffix_repository = repository_rule(
|
127 | 95 | implementation = _python_wheel_version_suffix_repository_impl,
|
128 | 96 | environ = _ENVIRONS,
|
129 | 97 | )
|
| 98 | + |
| 99 | +""" Repository rule for storing Python wheel filename version suffix. |
| 100 | +
|
| 101 | +The calculated wheel version suffix depends on the wheel type: |
| 102 | +- nightly: .dev{build_date} |
| 103 | +- release: ({custom_version_suffix})? |
| 104 | +- custom: .dev{build_date}(+{git_hash})?({custom_version_suffix})? |
| 105 | +- snapshot (default): -0 |
| 106 | +
|
| 107 | +The following environment variables can be set: |
| 108 | +{wheel_type}: ML_WHEEL_TYPE |
| 109 | +{build_date}: ML_WHEEL_BUILD_DATE (should be YYYYMMDD or YYYY-MM-DD) |
| 110 | +{git_hash}: ML_WHEEL_GIT_HASH |
| 111 | +{custom_version_suffix}: ML_WHEEL_VERSION_SUFFIX |
| 112 | +
|
| 113 | +Examples: |
| 114 | +1. nightly wheel version: 2.19.0.dev20250107 |
| 115 | + Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=nightly |
| 116 | + --repo_env=ML_WHEEL_BUILD_DATE=20250107 |
| 117 | +2. release wheel version: 2.19.0 |
| 118 | + Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=release |
| 119 | +3. release candidate wheel version: 2.19.0-rc1 |
| 120 | + Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=release |
| 121 | + --repo_env=ML_WHEEL_VERSION_SUFFIX=-rc1 |
| 122 | +4. custom wheel version: 2.19.0.dev20250107+cbe478fc5-custom |
| 123 | + Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=custom |
| 124 | + --repo_env=ML_WHEEL_BUILD_DATE=$(git show -s --format=%as HEAD) |
| 125 | + --repo_env=ML_WHEEL_GIT_HASH=$(git rev-parse HEAD) |
| 126 | + --repo_env=ML_WHEEL_VERSION_SUFFIX=-custom |
| 127 | +5. snapshot wheel version: 2.19.0-0 |
| 128 | + Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=snapshot |
| 129 | +
|
| 130 | +""" # buildifier: disable=no-effect |
| 131 | + |
| 132 | +def _transitive_py_deps_impl(ctx): |
| 133 | + outputs = depset( |
| 134 | + [], |
| 135 | + transitive = [dep[PyInfo].transitive_sources for dep in ctx.attr.deps], |
| 136 | + ) |
| 137 | + |
| 138 | + return DefaultInfo(files = outputs) |
| 139 | + |
| 140 | +_transitive_py_deps = rule( |
| 141 | + attrs = { |
| 142 | + "deps": attr.label_list( |
| 143 | + allow_files = True, |
| 144 | + providers = [PyInfo], |
| 145 | + ), |
| 146 | + }, |
| 147 | + implementation = _transitive_py_deps_impl, |
| 148 | +) |
| 149 | + |
| 150 | +def transitive_py_deps(name, deps = []): |
| 151 | + _transitive_py_deps(name = name + "_gather", deps = deps) |
| 152 | + native.filegroup(name = name, srcs = [":" + name + "_gather"]) |
| 153 | + |
| 154 | +"""Collects python files that a target depends on. |
| 155 | +
|
| 156 | +It traverses dependencies of provided targets, collect their direct and |
| 157 | +transitive python deps and then return a list of paths to files. |
| 158 | +""" # buildifier: disable=no-effect |
0 commit comments