Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Deprecate and remove implicit py_binary zipapp support

Ouverte
#3,567 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
45/100
Type d'issue
Refactorisation
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python
Domaine
build-system

Piste de recherche

Recherchez build_python_zip et python_zip_file dans le dépôt, puis examinez les fichiers BUILD référencés, les implémentations de my_rule.bzl et les transitions de rule.bzl. Comparez chaque utilisation aux cas de migration de cette issue et identifiez les cibles Bazel concernées. C’est terminé lorsque les anciens chemins zipapp implicites ont été supprimés ou migrés vers py_zipapp_binary ou py_zipapp_test sans casser les builds concernés.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

The implicit zipapp support of py_binary and py_test is being deprecated and removed. It is replaced by the py_zipapp_binary and py_zipapp_test rules. There are several ways the implicit zipapp logic may be activated.

For reference, these are the two loads you're most likely to need:

load("@rules_python//python/zipapp:py_zipapp_binary.bzl", "py_zipapp_binary")
load("@rules_python//python/zipapp:py_zipapp_test.bzl", "py_zipapp_test")

The flag name you want to look for is build_python_zip.

Windows-specific note: Windows enables zipapp by default, so the absence of the flag is the same as --build_python_zip=true !

Migration guide

This guide tries to give information on how to handle all possible cases of what may need to be migrated. Most changes are small, should be transparent, and can be done incrementally.

In practice, the most likely scenario you'll need to fix is using the
--build_python_zip flag on the command line -- see the "Migrate explicit --build_python_zip" section for that case.

Disable legacy zipapp flag

Add common --build_python_zip=false --@rules_python//python/config_settings:build_python_zip=false to your .bazelrc

Windows-specific note: Windows enables zipapp by default

Migrate explicit --build_python_zip usage

TLDR: Replace --build_python_zip on the command line with a py_zipapp_binary target in a BUILD file.

Replace this:

# File: BUILD

py_binary(name="bin")

# Command line
bazel build //:bin --build_python_zip

With this:

# File: BUILD
load("@rules_python//python/zipapp:py_zipapp_binary", "py_zipapp_binary")

py_binary(name="bin")
py_zipapp_binary(name = "bin_zipapp", binary=":bin")

# Command line
bazel build //:bin_zipapp

Migrate py_binary using config_settings with py_zipapp rule

TLDR: Add py_zipapp_binary for each py_binary you want as a zipapp

Replace this:

py_binary(
  name = "bin"
  config_settings = {
    "@rules_python//python/config:build_python_zip": "true",
    "//command_line_option:build_python_zip": "true",
  },
  ...
)

With this:

load("@rules_python//python/zipapp:py_zipapp_binary", "py_zipapp_binary")

py_binary(
  name = "bin"
  ...
)

py_zipapp_binary(
  name = "bin.zipapp",
  binary = ":bin",
)

Migrate filegroup using python_zip_file output group

Replace this:

TLDR: Add py_zipapp_binary and point the filegroup to it.

py_binary(name = "bin", ...)

filegroup(
  name = "bin_zip_file",
  output_group = "python_zip_file",
  srcs = [":bin"],
)

With this:

load("@rules_python//python/zipapp:py_zipapp_binary", "py_zipapp_binary")

py_binary(name = "bin", ...)
py_zipapp_binary(name = "bin_zipapp", binary=":bin")
filegroup(
  name = "bin_zip_file",
  output_group = "python_zip_file",
  srcs = [":bin_zipapp"],
)

Migrate Starlark using python_zip_file output group

TLDR: Add py_zipapp target and use it as the input target instead.

Replace this:

# File: my_rule.bzl
def _my_rule_impl(ctx):
  zip_file = ctx.attr.binary[OutputGroupInfo]["python_zip_file"].to_list()[0]

# File: BUILD.bazel
py_binary(name="bin", ...)
my_rule(name = "mytarget", binary=":bin", ...)

With this:

# File: my_rule.bzl

def _my_rule_impl(ctx):
  zip_file = ctx.attr.binary[OutputGroupInfo]["python_zip_file"].to_list()[0]

# File: BUILD.bazel
load("@rules_python//python/zipapp:py_zipapp_binary", "py_zipapp_binary")
py_binary(name="bin", ...)
py_zipapp_binary(name = "bin_zipapp", binary=":bin")
my_rule(name = "mytarget", binary=":bin_zipapp", ...)

Migration transitions setting build_python_zip flags

TLDR: Remove the build_python_zip flags from the transition and refactor into a separate target.

Replace this:

# File: rule.bzl
my_transition = transition(
   outputs = [
      "//command_line_settings:build_python_zip",
      "@rules_python//python/config_settings:build_python_zip",
   ],
   ...
)
my_rule(cfg = my_transition, ...)

# File: BUILD
py_binary(name="bin", ...)
my_rule(target=":bin")

With this:

# File: rule.bzl
my_transition = transition(
   outputs = [],
   ...
)
my_rule(cfg = my_transition, ...)

# File: BUILD
load("@rules_python//python/zipapp:py_zipapp_binary", "py_zipapp_binary")
py_binary(name="bin", ...)
py_zipapp_binary(name="bin_zipapp", binary=":bin")
my_rule(target=":bin_zipapp")
Langage dominant
Starlark
Étoiles
687
Forks
726
Merge moyen
1 j 10 h
PR mergées (30 j)
69

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de bazel-contrib/rules_python

Toutes les issues de bazel-contrib/rules_python

Issues similaires

Plus d'issues Build System

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.