Files
WeHub Mirror 16d3f15320
ARM CI / build (3.10) (push) Has been cancelled
cffconvert / validate (push) Has been cancelled
Creates a GitHub Issue when a PR Rolled back via Commit to Master / create-issue-on-pr-rollback (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
WeHub snapshot of ee606724a5c2f63bf60704cb3e1b169618993fd9
2026-08-07 16:11:07 +08:00

58 lines
1.9 KiB
Python

# Copyright 2026 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""
Repository rule to set python version and wheel name.
Version can be set via build parameter "--repo_env=TF_PYTHON_VERSION=3.10"
Defaults to 3.10.
To set wheel name, add "--repo_env=WHEEL_NAME=tensorflow_cpu"
"""
VERSIONS = ["3.10", "3.11", "3.12", "3.13", "3.14"]
DEFAULT_VERSION = "3.11"
WARNING = """
TF_PYTHON_VERSION environment variable was not set correctly; using Python {}.
To set Python version, run:
export TF_PYTHON_VERSION=3.11
""".format(DEFAULT_VERSION)
content = """
TF_PYTHON_VERSION = "{}"
HERMETIC_PYTHON_VERSION = "{}"
WHEEL_NAME = "{}"
WHEEL_COLLAB = "{}"
"""
def _python_repository_impl(repository_ctx):
repository_ctx.file("BUILD", "")
version = repository_ctx.os.environ.get("TF_PYTHON_VERSION", "")
wheel_name = repository_ctx.os.environ.get("WHEEL_NAME", "tensorflow")
wheel_collab = repository_ctx.os.environ.get("WHEEL_COLLAB", False)
if version not in VERSIONS:
print(WARNING) # buildifier: disable=print
version = DEFAULT_VERSION
repository_ctx.file(
"py_version.bzl",
content.format(version, version, wheel_name, wheel_collab),
)
python_repository = repository_rule(
implementation = _python_repository_impl,
environ = ["TF_PYTHON_VERSION", "WHEEL_NAME", "WHEEL_COLLAB"],
)