Skip to content

Commit 918399f

Browse files
Refactor mechanisms of building TF wheel and storing TF project version.
This change introduces a uniform way of building the TF wheel and controlling the filename version suffixes. A new repository rule `python_wheel_version_suffix_repository` provides information about project and wheel version suffixes. The final value depends on environment variables passed to Bazel command: `_ML_WHEEL_WHEEL_TYPE, _ML_WHEEL_BUILD_DATE, _ML_WHEEL_GIT_HASH, _ML_WHEEL_VERSION_SUFFIX` `tf_version.bzl` defines the TF project version and loads the version suffix information calculated by `python_wheel_version_suffix_repository`. The targets `//tensorflow/core/public:release_version, //tensorflow:tensorflow_bzl //tensorflow/tools/pip_package:setup_py` use the version chunks defined above. The version of the wheel in the build rule output depends on the environment variables. Environment variables combinations for creating wheels with different versions: * snapshot (default build rule behavior): `--repo_env=ML_WHEEL_TYPE=snapshot` * release: `--repo_env=ML_WHEEL_TYPE=release` * release candidate: `--repo_env=ML_WHEEL_TYPE=release --repo_env=ML_WHEEL_VERSION_SUFFIX=-rc1` * nightly build with date as version suffix: `--repo_env=ML_WHEEL_TYPE=nightly --repo_env=ML_WHEEL_BUILD_DATE=<YYYYmmdd>` * build with git data as version suffix: `--repo_env=ML_WHEEL_TYPE=custom --repo_env=ML_WHEEL_BUILD_DATE=$(git show -s --format=%as HEAD) --repo_env=ML_WHEEL_GIT_HASH=$(git rev-parse HEAD)` PiperOrigin-RevId: 716296989
1 parent aa9ac98 commit 918399f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

third_party/py/python_wheel.bzl

+5-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def _python_wheel_version_suffix_repository_impl(repository_ctx):
3939

4040
wheel_version_suffix = ""
4141
semantic_wheel_version_suffix = ""
42-
build_tag = ""
4342
if wheel_type == "nightly":
4443
if not build_date:
4544
fail("Environment variable ML_BUILD_DATE is required for nightly builds!")
@@ -63,14 +62,13 @@ def _python_wheel_version_suffix_repository_impl(repository_ctx):
6362
wheel_version_suffix += custom_version_suffix.replace("-", "")
6463
semantic_wheel_version_suffix += custom_version_suffix
6564
else:
66-
build_tag = "0"
65+
wheel_version_suffix = ".dev0+selfbuilt"
66+
semantic_wheel_version_suffix = "-dev0+selfbuilt"
6767

6868
version_suffix_bzl_content = """WHEEL_VERSION_SUFFIX = '{wheel_version_suffix}'
69-
SEMANTIC_WHEEL_VERSION_SUFFIX = '{semantic_wheel_version_suffix}'
70-
BUILD_TAG = '{build_tag}'""".format(
69+
SEMANTIC_WHEEL_VERSION_SUFFIX = '{semantic_wheel_version_suffix}'""".format(
7170
wheel_version_suffix = wheel_version_suffix,
7271
semantic_wheel_version_suffix = semantic_wheel_version_suffix,
73-
build_tag = build_tag,
7472
)
7573

7674
repository_ctx.file(
@@ -102,7 +100,7 @@ The calculated wheel version suffix depends on the wheel type:
102100
- nightly: .dev{build_date}
103101
- release: ({custom_version_suffix})?
104102
- custom: .dev{build_date}(+{git_hash})?({custom_version_suffix})?
105-
- snapshot (default): -0
103+
- snapshot (default): .dev0+selfbuilt
106104
107105
The following environment variables can be set:
108106
{wheel_type}: ML_WHEEL_TYPE
@@ -124,7 +122,7 @@ Examples:
124122
--repo_env=ML_WHEEL_BUILD_DATE=$(git show -s --format=%as HEAD)
125123
--repo_env=ML_WHEEL_GIT_HASH=$(git rev-parse HEAD)
126124
--repo_env=ML_WHEEL_VERSION_SUFFIX=-custom
127-
5. snapshot wheel version: 2.19.0-0
125+
5. snapshot wheel version: 2.19.0.dev0+selfbuilt
128126
Env vars passed to Bazel command: --repo_env=ML_WHEEL_TYPE=snapshot
129127
130128
""" # buildifier: disable=no-effect

0 commit comments

Comments
 (0)