Skip to content

Commit

Permalink
Update Python docs and messages to refer to @rules_python
Browse files Browse the repository at this point in the history
This replaces some uses of @bazel_tools//tools/python/... in user-visible strings with the appropriate @rules_python-based paths.

Work toward #8893.

RELNOTES: None
PiperOrigin-RevId: 261197893
  • Loading branch information
brandjon authored and copybara-github committed Aug 1, 2019
1 parent 00f8d65 commit e4ccba4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ executable Python rule (<code>py_binary</code> or <code>py_test</code>).
you can run the <code>find_requirements</code> aspect on your target:
<pre>
bazel build &lt;your target&gt; \
--aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements \
--aspects=@rules_python//python:defs.bzl%find_requirements \
--output_groups=pyversioninfo
</pre>
This will build a file with the suffix <code>-pyversioninfo.txt</code> giving information
Expand Down Expand Up @@ -195,8 +195,8 @@ is always set (possibly by default) to whatever version is specified by this att
this one.
<p>If you want to <code>select()</code> on the current Python version, you can inspect the
value of <code>@bazel_tools//tools/python:python_version</code>. See
<a href="https://github.com/bazelbuild/bazel/blob/4b74ea9a3f81b7ed30562f1689827b5488884c86/tools/python/BUILD#L33">here</a>
value of <code>@rules_python//python:python_version</code>. See
<a href="https://github.com/bazelbuild/rules_python/blob/120590e2f2b66e5590bf4dc8ebef9c5338984775/python/BUILD#L43">here</a>
for more information.
<p><b>Bug warning:</b> This attribute sets the version for which Bazel builds your target,
Expand Down
12 changes: 12 additions & 0 deletions tools/python/BUILD.tools
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
################################################################################
# DEPRECATION WARNING #
# #
# Direct access to @bazel_tools//tools/python, and to the native Python rules #
# and providers, is deprecated. All of these symbols are now accessible from #
# bazelbuild/rules_python. #
# #
# For native rules in particular, --incompatible_load_python_rules_from_bzl #
# (#9006) prohibits direct access to the native rules, and will be flipped on #
# in Bazel 1.0. #
################################################################################

load(":python_version.bzl", "define_python_version_flag")
load(":toolchain.bzl", "define_autodetecting_toolchain")

Expand Down
10 changes: 5 additions & 5 deletions tools/python/pywrapper_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ STRICT="%STRICT%"
if [ "$STRICT" = "1" ]; then
FAILURE_HEADER="\
Error occurred while attempting to use the default Python toolchain \
(@bazel_tools//tools/python:autodetecting_toolchain)."
(@rules_python//python:autodetecting_toolchain)."
else
FAILURE_HEADER="\
Error occurred while attempting to use the non-strict autodetecting Python \
toolchain (@bazel_tools//tools/python:autodetecting_toolchain_nonstrict)."
toolchain (@rules_python//python:autodetecting_toolchain_nonstrict)."
fi

die() {
Expand Down Expand Up @@ -60,7 +60,7 @@ $PATH
Please ensure an interpreter is available on this platform (and marked \
executable), or else register an appropriate Python toolchain as per the \
documentation for py_runtime_pair \
(https://github.com/bazelbuild/bazel/blob/master/tools/python/toolchain.bzl)."
(https://github.com/bazelbuild/rules_python/blob/master/docs/python.md#py_runtime_pair)."
fi

if [ "$STRICT" = "1" ]; then
Expand All @@ -76,15 +76,15 @@ $PATH
Please ensure an interpreter with version %VERSION% is available on this \
platform as 'python%VERSION%' or 'python', or else register an appropriate \
Python toolchain as per the documentation for py_runtime_pair \
(https://github.com/bazelbuild/bazel/blob/master/tools/python/toolchain.bzl).
(https://github.com/bazelbuild/rules_python/blob/master/docs/python.md#py_runtime_pair).
Note that prior to Bazel 0.27, there was no check to ensure that the \
interpreter's version matched the version declared by the target (#4815). If \
your build worked prior to Bazel 0.27, and you're sure your targets do not \
require Python %VERSION%, you can opt out of this version check by using the \
non-strict autodetecting toolchain instead of the standard autodetecting \
toolchain. This can be done by passing the flag \
\`--extra_toolchains=@bazel_tools//tools/python:autodetecting_toolchain_nonstrict\` \
\`--extra_toolchains=@rules_python//python:autodetecting_toolchain_nonstrict\` \
on the command line or adding it to your bazelrc."
fi
fi
Expand Down
6 changes: 3 additions & 3 deletions tools/python/runfiles/runfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
py_binary(
name = "my_binary",
...
deps = ["@bazel_tools//tools/python/runfiles"],
deps = ["@rules_python//python/runfiles"],
)
2. Import the runfiles library.
from bazel_tools.tools.python.runfiles import runfiles
from rules_python.python.runfiles import runfiles
3. Create a Runfiles object and use rlocation to look up runfile paths:
Expand All @@ -49,7 +49,7 @@
the right environment variables for them:
import subprocess
from bazel_tools.tools.python.runfiles import runfiles
from rules_python.python.runfiles import runfiles
r = runfiles.Create()
env = {}
Expand Down
2 changes: 1 addition & 1 deletion tools/python/srcs_version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ find_requirements = aspect(
The aspect definition. Can be invoked on the command line as
bazel build //pkg:my_py_binary_target \
--aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements \
--aspects=@rules_python//python:defs.bzl%find_requirements \
--output_groups=pyversioninfo
""",
)
Expand Down
4 changes: 2 additions & 2 deletions tools/python/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Example usage:
```python
# In your BUILD file...
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
load("@rules_python//python:defs.bzl", "py_runtime_pair")
py_runtime(
name = "my_py2_runtime",
Expand All @@ -101,7 +101,7 @@ toolchain(
name = "my_toolchain",
target_compatible_with = <...>,
toolchain = ":my_py_runtime_pair",
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
toolchain_type = "@rules_python//python:toolchain_type",
)
```
Expand Down

0 comments on commit e4ccba4

Please sign in to comment.