chore: remove semantics.bzl (#2725)
semantics.bzl is an artifact of how the rules avoided patching when they
were part of Bazel.
With the code moved out of Bazel, such helper files aren't necessary
anymore.
Work towards https://github.com/bazel-contrib/rules_python/issues/2522
diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel
index 0f6668f..ef4580e 100644
--- a/python/private/BUILD.bazel
+++ b/python/private/BUILD.bazel
@@ -72,7 +72,6 @@
":py_internal_bzl",
":reexports_bzl",
":rules_cc_srcs_bzl",
- ":semantics_bzl",
"@bazel_skylib//rules:common_settings",
],
)
@@ -131,7 +130,6 @@
":py_internal_bzl",
":reexports_bzl",
":rules_cc_srcs_bzl",
- ":semantics_bzl",
"@bazel_skylib//lib:paths",
],
)
@@ -302,7 +300,6 @@
":attributes_bzl",
":py_executable_bzl",
":rule_builders_bzl",
- ":semantics_bzl",
"@bazel_skylib//lib:dicts",
],
)
@@ -537,7 +534,6 @@
":common_bzl",
":py_executable_bzl",
":rule_builders_bzl",
- ":semantics_bzl",
"@bazel_skylib//lib:dicts",
],
)
@@ -677,11 +673,6 @@
],
)
-bzl_library(
- name = "semantics_bzl",
- srcs = ["semantics.bzl"],
-)
-
# Needed to define bzl_library targets for docgen. (We don't define the
# bzl_library target here because it'd give our users a transitive dependency
# on Skylib.)
diff --git a/python/private/attributes.bzl b/python/private/attributes.bzl
index b57e275..b042b3d 100644
--- a/python/private/attributes.bzl
+++ b/python/private/attributes.bzl
@@ -23,11 +23,6 @@
load(":py_internal.bzl", "py_internal")
load(":reexports.bzl", "BuiltinPyInfo")
load(":rule_builders.bzl", "ruleb")
-load(
- ":semantics.bzl",
- "DEPS_ATTR_ALLOW_RULES",
- "SRCS_ATTR_ALLOW_FILES",
-)
_PackageSpecificationInfo = getattr(py_internal, "PackageSpecificationInfo", None)
@@ -250,9 +245,6 @@
[PyInfo],
[CcInfo],
] + _MaybeBuiltinPyInfo,
- # TODO(b/228692666): Google-specific; remove these allowances once
- # the depot is cleaned up.
- allow_rules = DEPS_ATTR_ALLOW_RULES,
doc = """
List of additional libraries to be linked in to the target.
See comments about
@@ -359,8 +351,7 @@
allow_files = True,
),
"srcs": lambda: attrb.LabelList(
- # Google builds change the set of allowed files.
- allow_files = SRCS_ATTR_ALLOW_FILES,
+ allow_files = [".py", ".py3"],
# Necessary for --compile_one_dependency to work.
flags = ["DIRECT_COMPILE_TIME_INPUT"],
doc = """
diff --git a/python/private/py_executable.bzl b/python/private/py_executable.bzl
index d54a3d7..fed46ab 100644
--- a/python/private/py_executable.bzl
+++ b/python/private/py_executable.bzl
@@ -60,13 +60,6 @@
load(":reexports.bzl", "BuiltinPyInfo", "BuiltinPyRuntimeInfo")
load(":rule_builders.bzl", "ruleb")
load(
- ":semantics.bzl",
- "ALLOWED_MAIN_EXTENSIONS",
- "BUILD_DATA_SYMLINK_PATH",
- "IS_BAZEL",
- "PY_RUNTIME_ATTR_NAME",
-)
-load(
":toolchain_types.bzl",
"EXEC_TOOLS_TOOLCHAIN_TYPE",
"TARGET_TOOLCHAIN_TYPE",
@@ -1116,19 +1109,12 @@
#
# TOOD(bazelbuild/bazel#7901): Remove this once --python_path flag is removed.
- if IS_BAZEL:
- flag_interpreter_path = ctx.fragments.bazel_py.python_path
- toolchain_runtime, effective_runtime = _maybe_get_runtime_from_ctx(ctx)
- if not effective_runtime:
- # Clear these just in case
- toolchain_runtime = None
- effective_runtime = None
-
- else: # Google code path
- flag_interpreter_path = None
- toolchain_runtime, effective_runtime = _maybe_get_runtime_from_ctx(ctx)
- if not effective_runtime:
- fail("Unable to find Python runtime")
+ flag_interpreter_path = ctx.fragments.bazel_py.python_path
+ toolchain_runtime, effective_runtime = _maybe_get_runtime_from_ctx(ctx)
+ if not effective_runtime:
+ # Clear these just in case
+ toolchain_runtime = None
+ effective_runtime = None
if effective_runtime:
direct = [] # List of files
@@ -1207,7 +1193,7 @@
effective_runtime = toolchain_runtime
else:
toolchain_runtime = None
- attr_target = getattr(ctx.attr, PY_RUNTIME_ATTR_NAME)
+ attr_target = ctx.attr._py_interpreter
# In Bazel, --python_top is null by default.
if attr_target and PyRuntimeInfo in attr_target:
@@ -1335,9 +1321,9 @@
central_uncachable_version_file,
extra_write_build_data_env,
)
- build_data_runfiles = ctx.runfiles(symlinks = {
- BUILD_DATA_SYMLINK_PATH: build_data_file,
- })
+ build_data_runfiles = ctx.runfiles(files = [
+ build_data_file,
+ ])
return build_data_file, build_data_runfiles
def _write_build_data(ctx, central_uncachable_version_file, extra_write_build_data_env):
@@ -1552,7 +1538,7 @@
"""
if ctx.attr.main:
proposed_main = ctx.attr.main.label.name
- if not proposed_main.endswith(tuple(ALLOWED_MAIN_EXTENSIONS)):
+ if not proposed_main.endswith(".py"):
fail("main must end in '.py'")
else:
if ctx.label.name.endswith(".py"):
diff --git a/python/private/semantics.bzl b/python/private/semantics.bzl
deleted file mode 100644
index 3811b17..0000000
--- a/python/private/semantics.bzl
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright 2022 The Bazel 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.
-"""Contains constants that vary between Bazel and Google-internal"""
-
-IMPORTS_ATTR_SUPPORTED = True
-
-SRCS_ATTR_ALLOW_FILES = [".py", ".py3"]
-
-DEPS_ATTR_ALLOW_RULES = None
-
-PY_RUNTIME_ATTR_NAME = "_py_interpreter"
-
-BUILD_DATA_SYMLINK_PATH = None
-
-IS_BAZEL = True
-
-NATIVE_RULES_MIGRATION_HELP_URL = "https://github.com/bazelbuild/bazel/issues/17773"
-NATIVE_RULES_MIGRATION_FIX_CMD = "add_python_loads"
-
-ALLOWED_MAIN_EXTENSIONS = [".py"]