mirror of
https://github.com/tensorflow/tensorflow.git
synced 2026-09-28 05:13:36 +08:00
67 lines
2.5 KiB
Python
67 lines
2.5 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.
|
|
# =============================================================================
|
|
|
|
"""
|
|
A much simplified version of third_party/py/python_repo.bzl, which generates the "python_version_repo" repo.
|
|
|
|
This is just to keep the current build compatible with both WORKSPACE and Bzlmod, we may not need this in future.
|
|
"""
|
|
|
|
_PY_VERSION_BZL = """
|
|
HERMETIC_PYTHON_VERSION = "{version}"
|
|
HERMETIC_PYTHON_VERSION_KIND = "{py_kind}"
|
|
USE_PYWRAP_RULES = {use_pywrap_rules}
|
|
MACOSX_DEPLOYMENT_TARGET = "{macosx_deployment_target}"
|
|
WHEEL_COLLAB = "{wheel_collab}"
|
|
WHEEL_NAME = "{wheel_name}"
|
|
# TODO(pcloudy): Figure out how to support requirements_lock in Bzlmod.
|
|
REQUIREMENTS = "//:requirements.txt"
|
|
"""
|
|
|
|
def _python_version_repo_impl(repository_ctx):
|
|
version = repository_ctx.os.environ.get("HERMETIC_PYTHON_VERSION", "3.11")
|
|
wheel_name = repository_ctx.os.environ.get("WHEEL_NAME", "tensorflow")
|
|
wheel_collab = repository_ctx.os.environ.get("WHEEL_COLLAB", False)
|
|
macosx_deployment_target = repository_ctx.os.environ.get("MACOSX_DEPLOYMENT_TARGET", "")
|
|
|
|
use_pywrap_rules = bool(
|
|
repository_ctx.os.environ.get("USE_PYWRAP_RULES", False),
|
|
)
|
|
repository_ctx.file("BUILD.bazel", "")
|
|
repository_ctx.file(
|
|
"py_version.bzl",
|
|
_PY_VERSION_BZL.format(
|
|
version = version,
|
|
py_kind = "", # TODO(pcloudy): introduce this value properly.
|
|
use_pywrap_rules = use_pywrap_rules,
|
|
wheel_name = wheel_name,
|
|
wheel_collab = wheel_collab,
|
|
macosx_deployment_target = macosx_deployment_target,
|
|
),
|
|
)
|
|
|
|
python_version_repo = repository_rule(
|
|
implementation = _python_version_repo_impl,
|
|
environ = [
|
|
"HERMETIC_PYTHON_VERSION",
|
|
"HERMETIC_PYTHON_VERSION_KIND",
|
|
"USE_PYWRAP_RULES",
|
|
],
|
|
)
|
|
|
|
python_version_ext = module_extension(
|
|
implementation = lambda mctx: python_version_repo(name = "python_version_repo"),
|
|
)
|