@@ -37,20 +37,6 @@ different name. Then we can load it from defs.bzl and export it there under
3737the original name.
3838"""
3939
40- load ("@bazel_tools//tools/python:toolchain.bzl" , _py_runtime_pair = "py_runtime_pair" )
41-
42- # The implementation of the macros and tagging mechanism follows the example
43- # set by rules_cc and rules_java.
44-
45- _MIGRATION_TAG = "__PYTHON_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"
46-
47- def _add_tags (attrs ):
48- if "tags" in attrs and attrs ["tags" ] != None :
49- attrs ["tags" ] = attrs ["tags" ] + [_MIGRATION_TAG ]
50- else :
51- attrs ["tags" ] = [_MIGRATION_TAG ]
52- return attrs
53-
5440# Don't use underscore prefix, since that would make the symbol local to this
5541# file only. Use a non-conventional name to emphasize that this is not a public
5642# symbol.
@@ -59,125 +45,3 @@ internal_PyInfo = PyInfo
5945
6046# buildifier: disable=name-conventions
6147internal_PyRuntimeInfo = PyRuntimeInfo
62-
63- def py_library (** attrs ):
64- """See the Bazel core [py_library](https://docs.bazel.build/versions/master/be/python.html#py_library) documentation.
65-
66- Args:
67- **attrs: Rule attributes
68- """
69- if attrs .get ("srcs_version" ) in ("PY2" , "PY2ONLY" ):
70- fail ("Python 2 is no longer supported: https://github.com/bazelbuild/rules_python/issues/886" )
71-
72- # buildifier: disable=native-python
73- native .py_library (** _add_tags (attrs ))
74-
75- def py_binary (** attrs ):
76- """See the Bazel core [py_binary](https://docs.bazel.build/versions/master/be/python.html#py_binary) documentation.
77-
78- Args:
79- **attrs: Rule attributes
80- """
81- if attrs .get ("python_version" ) == "PY2" :
82- fail ("Python 2 is no longer supported: https://github.com/bazelbuild/rules_python/issues/886" )
83- if attrs .get ("srcs_version" ) in ("PY2" , "PY2ONLY" ):
84- fail ("Python 2 is no longer supported: https://github.com/bazelbuild/rules_python/issues/886" )
85-
86- # buildifier: disable=native-python
87- native .py_binary (** _add_tags (attrs ))
88-
89- def py_test (** attrs ):
90- """See the Bazel core [py_test](https://docs.bazel.build/versions/master/be/python.html#py_test) documentation.
91-
92- Args:
93- **attrs: Rule attributes
94- """
95- if attrs .get ("python_version" ) == "PY2" :
96- fail ("Python 2 is no longer supported: https://github.com/bazelbuild/rules_python/issues/886" )
97- if attrs .get ("srcs_version" ) in ("PY2" , "PY2ONLY" ):
98- fail ("Python 2 is no longer supported: https://github.com/bazelbuild/rules_python/issues/886" )
99-
100- # buildifier: disable=native-python
101- native .py_test (** _add_tags (attrs ))
102-
103- def py_runtime (** attrs ):
104- """See the Bazel core [py_runtime](https://docs.bazel.build/versions/master/be/python.html#py_runtime) documentation.
105-
106- Args:
107- **attrs: Rule attributes
108- """
109- if attrs .get ("python_version" ) == "PY2" :
110- fail ("Python 2 is no longer supported: see https://github.com/bazelbuild/rules_python/issues/886" )
111-
112- # buildifier: disable=native-python
113- native .py_runtime (** _add_tags (attrs ))
114-
115- # NOTE: This doc is copy/pasted from the builtin py_runtime_pair rule so our
116- # doc generator gives useful API docs.
117- def py_runtime_pair (name , py2_runtime = None , py3_runtime = None , ** attrs ):
118- """A toolchain rule for Python.
119-
120- This used to wrap up to two Python runtimes, one for Python 2 and one for Python 3.
121- However, Python 2 is no longer supported, so it now only wraps a single Python 3
122- runtime.
123-
124- Usually the wrapped runtimes are declared using the `py_runtime` rule, but any
125- rule returning a `PyRuntimeInfo` provider may be used.
126-
127- This rule returns a `platform_common.ToolchainInfo` provider with the following
128- schema:
129-
130- ```python
131- platform_common.ToolchainInfo(
132- py2_runtime = None,
133- py3_runtime = <PyRuntimeInfo or None>,
134- )
135- ```
136-
137- Example usage:
138-
139- ```python
140- # In your BUILD file...
141-
142- load("@rules_python//python:defs.bzl", "py_runtime_pair")
143-
144- py_runtime(
145- name = "my_py3_runtime",
146- interpreter_path = "/system/python3",
147- python_version = "PY3",
148- )
149-
150- py_runtime_pair(
151- name = "my_py_runtime_pair",
152- py3_runtime = ":my_py3_runtime",
153- )
154-
155- toolchain(
156- name = "my_toolchain",
157- target_compatible_with = <...>,
158- toolchain = ":my_py_runtime_pair",
159- toolchain_type = "@rules_python//python:toolchain_type",
160- )
161- ```
162-
163- ```python
164- # In your WORKSPACE...
165-
166- register_toolchains("//my_pkg:my_toolchain")
167- ```
168-
169- Args:
170- name: str, the name of the target
171- py2_runtime: optional Label; must be unset or None; an error is raised
172- otherwise.
173- py3_runtime: Label; a target with `PyRuntimeInfo` for Python 3.
174- **attrs: Extra attrs passed onto the native rule
175- """
176- if attrs .get ("py2_runtime" ):
177- fail ("PYthon 2 is no longer supported: see https://github.com/bazelbuild/rules_python/issues/886" )
178- _py_runtime_pair (
179- name = name ,
180- py2_runtime = py2_runtime ,
181- py3_runtime = py3_runtime ,
182- ** attrs
183- )
0 commit comments