Skip to content

incompatible_python_disallow_native_rules #17773

@rickeylev

Description

@rickeylev

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 of native.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:

  1. Add rules_python to your WORKSPACE and/or MODULE.bazel, per the rules_python instructions
  2. Reference any symbols through @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:

load("@rules_python//python:py_binary.bzl", "py_binary")

py_binary(...)

For versions before 0.20.0, load the symbols from :defs.bzl:

load("@rules_python//python:defs.bzl", "py_binary")
py_binary(...)

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:

  • link to tool that rewrites BUILD and bzl files

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions