-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incompatible_python_disallow_native_rules #17773
Comments
The `--incompatible_python_disallow_native_rules` flag, when enabled, will cause an error if a native Python rule is used without going through the @rule_python rule set. To aid incremental migration, an allowlist can be specified using `--python_native_rules_allowlist`. When specified, packages in the allowlist won't fail when directly using the native rules. Work towards #17773 PiperOrigin-RevId: 516687379 Change-Id: I154b538a9c7956bc3b2fba9e619fe63207559598
If you want this flag to be tested by https://buildkite.com/bazel/bazelisk-plus-incompatible-flags, please add |
The `--incompatible_python_disallow_native_rules` flag, when enabled, will cause an error if a native Python rule is used without going through the @rule_python rule set. To aid incremental migration, an allowlist can be specified using `--python_native_rules_allowlist`. When specified, packages in the allowlist won't fail when directly using the native rules. Work towards bazelbuild#17773 PiperOrigin-RevId: 516687379 Change-Id: I154b538a9c7956bc3b2fba9e619fe63207559598
@rickeylev: When I activate this flag (Bazel 7.0.0) using a toolchain registered with
I'm commenting here (and not in rules_python), because I think there's a bug in how this check is implemented: |
Doh. Thanks for the report. Yeah, I think you're right. Should be an easy fix. Basic repro steps: run rules_python's pip_parse example tests with
|
…mpty package This basically makes it usable with the downloaded runtimes rules_python makes available. The issue was the code to construct the label was leaving a trailing "/" when the the target being checked at the root of the workspace. To fix, just omit the trailing slash when the package name is empty to prevent the trailing slash. Work towards bazelbuild#17773
…mpty package This basically makes it usable with the downloaded runtimes rules_python makes available. The issue was the code to construct the label was leaving a trailing "/" when the the target being checked at the root of the workspace. To fix, just omit the trailing slash when the package name is empty to prevent the trailing slash. Work towards bazelbuild#17773
…mpty package This basically makes it usable with the downloaded runtimes rules_python makes available. The issue was the code to construct the label was leaving a trailing "/" when the the target being checked at the root of the workspace. To fix, just omit the trailing slash when the package name is empty to prevent the trailing slash. Work towards bazelbuild#17773
…mpty package This basically makes it usable with the downloaded runtimes rules_python makes available. The issue was the code to construct the label was leaving a trailing "/" when the the target being checked at the root of the workspace. To fix, just omit the trailing slash when the package name is empty to prevent the trailing slash. Work towards bazelbuild#17773
…mpty package This basically makes it usable with the downloaded runtimes rules_python makes available. The issue was the code to construct the label was leaving a trailing "/" when the the target being checked at the root of the workspace. To fix, just omit the trailing slash when the package name is empty to prevent the trailing slash. Work towards bazelbuild#17773
…evel external repo targets This basically makes it usable with the downloaded runtimes rules_python makes available, which reference their runtimes as e.g. `@python_3_11//:python`. The issue was the code to construct the label was leaving a trailing "/" when the the target being checked at the root of the workspace. To fix, just omit the trailing slash when the package name is empty to prevent the trailing slash. Work towards #17773 Closes #20516 PiperOrigin-RevId: 591053422 Change-Id: I7790df2db10278844ae2b36cfe671de03164972f
Ok, this should be fixed at head now. It's worth putting that into a 7.x patch release |
@bazel-io flag |
@bazel-io fork 7.1.0 |
…evel external repo targets This basically makes it usable with the downloaded runtimes rules_python makes available, which reference their runtimes as e.g. `@python_3_11//:python`. The issue was the code to construct the label was leaving a trailing "/" when the the target being checked at the root of the workspace. To fix, just omit the trailing slash when the package name is empty to prevent the trailing slash. Work towards bazelbuild#17773 Closes bazelbuild#20516 PiperOrigin-RevId: 591053422 Change-Id: I7790df2db10278844ae2b36cfe671de03164972f
…or top-level external repo targets (#20923) This basically makes it usable with the downloaded runtimes rules_python makes available, which reference their runtimes as e.g. `@python_3_11//:python`. The issue was the code to construct the label was leaving a trailing "/" when the the target being checked at the root of the workspace. To fix, just omit the trailing slash when the package name is empty to prevent the trailing slash. Work towards #17773 Closes #20516 Commit 1533cd1 PiperOrigin-RevId: 591053422 Change-Id: I7790df2db10278844ae2b36cfe671de03164972f Co-authored-by: Richard Levasseur <[email protected]>
On
when specifying but then that caused a self edge:
Edit: it looks like I can solve this by doing python_register_toolchains(
name = "python_3_9",
python_version = "3.9",
) to do that for me, but it did not |
The flag
|
There is a typo in @rickeylev 's comment above. The string you need in the package group is |
This reverts commit 1348c3b. The --incompatible_python_disallow_native_rules flag fails in WORKSPACE mode due to incompatible use in the builtin `@bazel_tools` repo. See https://github.com/aherrmann/rules_zig/actions/runs/11626106944/job/32377199087?pr=380#step:3:762 ``` (07:45:07) ERROR: /home/runner/.cache/bazel-repo/bazel/_bazel_runner/e97befc866f153aa83e528704066dbd2/external/bazel_tools/tools/python/BUILD:110:31: in py_runtime rule @@bazel_tools//tools/python:_autodetecting_py3_runtime: Traceback (most recent call last): File "/virtual_builtins_bzl/common/python/py_runtime_rule.bzl", line 24, column 25, in _py_runtime_impl File "/virtual_builtins_bzl/common/python/common.bzl", line 520, column 13, in check_native_allowed Error in fail: @bazel_tools//tools/python:_autodetecting_py3_runtime not allowed to use native.py_runtime Generated by: define_autodetecting_toolchain(name=autodetecting_toolchain) in tools/python/BUILD:110:31 Allowlist: no allowlist specified; all disallowed; specify one with --python_native_rules_allowlist Migrate to using @rules_python, see bazelbuild/bazel#17773 FIXCMD: add_python_loads --target=@bazel_tools//tools/python:_autodetecting_py3_runtime --rule=py_runtime --generator_name=autodetecting_toolchain --location=tools/python/BUILD:110:31 ``` The `@bazel_tools` repo cannot be modified, so the `FIXCMD` solution does not apply. The allowlist flag expects a package_group, but `@bazel_tools` has no pre-defined package_group, and a user defined `package_group` cannot refer to other workspaces because elements of the `packages` attribute must start with `//`.
This reverts commit 1348c3b. The --incompatible_python_disallow_native_rules flag fails in WORKSPACE mode due to incompatible use in the builtin `@bazel_tools` repo. See https://github.com/aherrmann/rules_zig/actions/runs/11626106944/job/32377199087?pr=380#step:3:762 ``` (07:45:07) ERROR: /home/runner/.cache/bazel-repo/bazel/_bazel_runner/e97befc866f153aa83e528704066dbd2/external/bazel_tools/tools/python/BUILD:110:31: in py_runtime rule @@bazel_tools//tools/python:_autodetecting_py3_runtime: Traceback (most recent call last): File "/virtual_builtins_bzl/common/python/py_runtime_rule.bzl", line 24, column 25, in _py_runtime_impl File "/virtual_builtins_bzl/common/python/common.bzl", line 520, column 13, in check_native_allowed Error in fail: @bazel_tools//tools/python:_autodetecting_py3_runtime not allowed to use native.py_runtime Generated by: define_autodetecting_toolchain(name=autodetecting_toolchain) in tools/python/BUILD:110:31 Allowlist: no allowlist specified; all disallowed; specify one with --python_native_rules_allowlist Migrate to using @rules_python, see bazelbuild/bazel#17773 FIXCMD: add_python_loads --target=@bazel_tools//tools/python:_autodetecting_py3_runtime --rule=py_runtime --generator_name=autodetecting_toolchain --location=tools/python/BUILD:110:31 ``` The `@bazel_tools` repo cannot be modified, so the `FIXCMD` solution does not apply. The allowlist flag expects a package_group, but `@bazel_tools` has no pre-defined package_group, and a user defined `package_group` cannot refer to other workspaces because elements of the `packages` attribute must start with `//`. See the discussion around the following comment for other solutions: bazelbuild/bazel#17773 (comment)
This reverts commit 1348c3b. The --incompatible_python_disallow_native_rules flag fails in WORKSPACE mode due to incompatible use in the builtin `@bazel_tools` repo. See https://github.com/aherrmann/rules_zig/actions/runs/11626106944/job/32377199087?pr=380#step:3:762 ``` (07:45:07) ERROR: /home/runner/.cache/bazel-repo/bazel/_bazel_runner/e97befc866f153aa83e528704066dbd2/external/bazel_tools/tools/python/BUILD:110:31: in py_runtime rule @@bazel_tools//tools/python:_autodetecting_py3_runtime: Traceback (most recent call last): File "/virtual_builtins_bzl/common/python/py_runtime_rule.bzl", line 24, column 25, in _py_runtime_impl File "/virtual_builtins_bzl/common/python/common.bzl", line 520, column 13, in check_native_allowed Error in fail: @bazel_tools//tools/python:_autodetecting_py3_runtime not allowed to use native.py_runtime Generated by: define_autodetecting_toolchain(name=autodetecting_toolchain) in tools/python/BUILD:110:31 Allowlist: no allowlist specified; all disallowed; specify one with --python_native_rules_allowlist Migrate to using @rules_python, see bazelbuild/bazel#17773 FIXCMD: add_python_loads --target=@bazel_tools//tools/python:_autodetecting_py3_runtime --rule=py_runtime --generator_name=autodetecting_toolchain --location=tools/python/BUILD:110:31 ``` The `@bazel_tools` repo cannot be modified, so the `FIXCMD` solution does not apply. The allowlist flag expects a package_group, but `@bazel_tools` has no pre-defined package_group, and a user defined `package_group` cannot refer to other workspaces because elements of the `packages` attribute must start with `//`. See the discussion around the following comment for other solutions: bazelbuild/bazel#17773 (comment)
As part of moving the Python rules out of Bazel itself, usage of the
native.py_*
will only be allowed when done through the@rules_python
.The
--incompatible_python_disallow_native_rules
flag will control this behavior. When true, direct usage ofnative.py_*
will result in a build failure.To make migration easier, an allow list can be specifed using
--python_native_rules_allowlist
. If not specified, all usages are disallowed. When specified, packages matching the paths in the allowlist will be permitted to use the native rules, while others will fail. This makes incrementally migrating easier.The basic changes necessary are:
@rules_python
.How to load the symbols depends on what versions of rules_python you need to support.
If you require version 0.20.0 or later, load the symbols from their specific files:
For versions before 0.20.0, load the symbols from
:defs.bzl
:Googlers: visibility is required to use defs.bzl; see the py-add-loads-lsc document for instructions
(To clarify: defs.bzl is present in all versions, but deprecated as of 0.20.0)
TODO:
The text was updated successfully, but these errors were encountered: