//python/config_settings

flag--//python/config_settings:add_srcs_to_runfiles

Determines if thesrcs of targets are added to their runfiles.

More specifically, the sources added to runfiles are the.py files insrcs.If precompiling is performed, it is the.py files that are kept accordingtoprecompile_source_retention.

Values:

  • auto: (default) Automatically decide the effective value; the currentbehavior isdisabled.

  • disabled: Don’t addsrcs to a target’s runfiles.

  • enabled: Addsrcs to a target’s runfiles.

Added in version 0.37.0.

Deprecated since version 0.37.0:This is a transition flag and will be removed in a subsequent release.

flag--//python/config_settings:build_python_zip

Controls if apy_binary/py_test output is a self-executable zipapp.

When enabled, the output ofpy_binary orpy_test targets will be aself-executable zipapp.

Note

This affectsallpy_binary andpy_test targets in the build, notonly the target(s) specified on the command line.

Values:

  • true

  • false

This flag replaces the Bazel builtin--build_python_zip flag.

Added in version 1.7.0.

flag--//python/config_settings:experimental_python_import_all_repositories

Controls whether repository directories are added to the import path.

When enabled, the top-level directories in the runfiles root directory (whichare presumbed to be repository directories) are added to the Python importsearch path.

It’s recommended to set this tofalse to avoid external dependenciesunexpectedly interferring with import searching.

Values;

  • true (default)

  • false

This flag replaces the Bazel builtin--experimental_python_import_all_repositories flag.

Added in version 1.7.0.

flag--//python/config_settings:python_path

A fallback path to use for Python for particular legacy Windows-specific code paths.

Deprecated, do not use. This flag is largely a no-op and was replaced bytoolchains. It only remains for some legacy Windows code-paths that willbe removed.

This flag replaces the Bazel builtin--python_path flag.

Deprecated since version 1.7.0:Use toolchains instead.

Added in version 1.7.0.

flag--//python/config_settings:python_version

Determines the default hermetic Python toolchain version. This can be set toone of the values thatrules_python maintains.

//python/config_settings:python_version_major_minor

Parses the value of thepython_version and transforms it into aX.Y value.

flag--//python/config_settings:incompatible_default_to_explicit_init_py

Controls if missing__init__.py files are generated or not.

If false,py_binary andpy_test will, for every*.py and*.so file,create__init__.py files for the containing directory, and all parentdirectories, that do not already have an__init__.py file. If true, thisbehavior is disabled.

It’s recommended to disable this behavior to avoid surprising import effectsfrom directories being importable when they otherwise wouldn’t be, and forhow it can interfere with implicit namespace packages.

Values:

  • true: do not generate missing__init__.py files

  • false (default): generate missing__init__.py files

This flag replaces the Bazel builtin--incompatible_default_to_explicit_init_py flag.

Added in version 1.7.0.

//python/config_settings:is_python_*

config_settings to match Python versions

The name pattern isis_python_X.Y (to match major.minor) andis_python_X.Y.Z(to match major.minor.patch).

Note that the set of available targets depends on the configuredTOOL_VERSIONS. Versions may not always be available if the root module hascustomized them, or as older Python versions are removed from rules_python’s setof builtin, known versions.

If you need to match a version that isn’t present, then you have two options:

  1. Manually define aconfig_setting and have it match--python_versionorpython_version_major_minor. This works best when you don’t control theroot module, or don’t want to rely on the MODULE.bazel configuration. Sucha config settings would look like:

    # Match any 3.5 versionconfig_setting(name="is_python_3.5",flag_values={"@rules_python//python/config_settings:python_version_major_minor":"3.5",})# Match exactly 3.5.1config_setting(name="is_python_3.5.1",flag_values={"@rules_python//python/config_settings:python_version":"3.5.1",})
  2. Usepython.single_override to re-introduce the desired version sothat the corresponding//python/config_setting:is_python_XXX target isgenerated.

flag--//python/config_settings:exec_tools_toolchain

Determines if theexec_tools_toolchain_type toolchain is enabled.

Note

  • Note that this only affects the rules_python generated toolchains.

Values:

  • enabled: Allow matching of the registered toolchains at build time.

  • disabled: Prevent the toolchain from being matched at build time.

Added in version 0.33.2.

flag--//python/config_settings:precompile

Determines if Python source files should be compiled at build time.

Note

The flag value is overridden by the target levelprecompile attribute,except for the case offorce_enabled andforced_disabled.

Values:

  • auto: (default) Automatically decide the effective value based on environment,target platform, etc.

  • enabled: Compile Python source files at build time.

  • disabled: Don’t compile Python source files at build time.

  • force_enabled: Likeenabled, except overrides target-level setting. Thisis mostly useful for development, testing enabling precompilation morebroadly, or as an escape hatch if build-time compiling is not available.

  • force_disabled: Likedisabled, except overrides target-level setting. Thisis useful useful for development, testing enabling precompilation morebroadly, or as an escape hatch if build-time compiling is not available.

Added in version 0.33.0.

Changed in version 0.37.0:Theif_generated_source value was removed

flag--//python/config_settings:precompile_source_retention

Determines, when a source file is compiled, if the source file is keptin the resulting output or not.

Note

This flag is overridden by the target levelprecompile_source_retentionattribute.

Values:

  • auto: (default) Automatically decide the effective value based on environment,target platform, etc.

  • keep_source: Include the original Python source.

  • omit_source: Don’t include the orignal py source.

Added in version 0.33.0.

Added in version 0.36.0:Theauto value

Changed in version 0.37.0:Theomit_if_generated_source value was removed

flag--//python/config_settings:py_linux_libc

Set what libc is used for the target platform. This will affect which whl binaries will be pulled and what toolchain will be auto-detected. Currentlyrules_python only supplies toolchains compatible withglibc.

Values:

  • glibc: Useglibc, default.

  • muslc: Usemuslc.

Added in version 0.33.0.

flag--//python/config_settings:py_freethreaded

Set whether to use an interpreter with the experimental freethreaded option set to true.

Values:

  • no: Use regular Python toolchains, default.

  • yes: Use the experimental Python toolchain with freethreaded compile option enabled.

Added in version 0.38.0.

flag--//python/config_settings:pip_env_marker_config

The target that provides the values for pip env marker evaluation.

Default://python/config_settings:_pip_env_marker_default_config

This flag points to a target providingEnvMarkerInfo, which determinesthe values used when environment markers are resolved at build time.

Added in version 1.5.0.

flag--//python/config_settings:pip_whl

Set what distributions are used in thepip integration.

Values:

  • auto: Preferwhl distributions if they are compatible with a targetplatform, but fallback tosdist. This is the default.

  • only: Only usewhl distributions and error out if it is not available.

  • no: Only usesdist distributions. The wheels will be built non-hermetically in thewhl_library repository rule.

Added in version 0.33.0.

flag--//python/config_settings:pip_whl_osx_arch

Set what wheel types we should prefer when building on the OSX platform.

Values:

  • arch: Prefer architecture specific wheels.

  • universal: Prefer universal wheels that usually are bigger and contain binaries for both, Intel and ARM architectures in the same wheel.

Added in version 0.33.0.

flag--//python/config_settings:pip_whl_glibc_version

Set the minimumglibc version that thepy_binary usingwhl distributions from a PyPI index should support.

Values:

  • "": Select the lowest available version of each wheel giving you the maximum compatibility. This is the default.

  • X.Y: The string representation of aglibc version. The allowed values depend on therequirements.txt lock file contents.

Added in version 0.33.0.

flag--//python/config_settings:pip_whl_muslc_version

Set the minimummuslc version that thepy_binary usingwhl distributions from a PyPI index should support.

Values:

  • "": Select the lowest available version of each wheel giving you the maximum compatibility. This is the default.

  • X.Y: The string representation of amuslc version. The allowed values depend on therequirements.txt lock file contents.

Added in version 0.33.0.

flag--//python/config_settings:pip_whl_osx_version

Set the minimumosx version that thepy_binary usingwhl distributions from a PyPI index should support.

Values:

  • "": Select the lowest available version of each wheel giving you the maximum compatibility. This is the default.

  • X.Y: The string representation of the MacOS version. The allowed values depend on therequirements.txt lock file contents.

Added in version 0.33.0.

flag--//python/config_settings:venvs_site_packages

Determines if libraries use a site-packages layout for their files.

Note this flag only affects PyPI dependencies of--bootstrap_impl=script binaries

Warning

Experimental API. This API is still under development and may change or beremoved without notice.

Values:

  • no (default): Make libraries importable by adding tosys.path

  • yes: Make libraries importable by creating paths in a binary’s site-packages directory.

flag--//python/config_settings:bootstrap_impl

Determine how programs implement their startup process.

Values:

  • system_python: (default) Use a bootstrap that requires a system Python availablein order to start programs. This requiresPyRuntimeInfo.bootstrap_template to be a Python program.

  • script: Use a bootstrap that uses an arbitrary executable script (usually ashell script) instead of requiring it be a Python program.

Note

Thescript bootstrap requires the toolchain to provide thePyRuntimeInfoprovider fromrules_python. This loosely translates to using Bazel 7+ with atoolchain created by rules_python. Most notably, WORKSPACE builds default tousing a legacy toolchain built into Bazel itself which doesn’t support thescript bootstrap. If not available, thesystem_python bootstrap will be usedinstead.

Added in version 0.33.0.

flag--//python/config_settings:current_config

Fail the build if the current build configuration does not match thepip.parse defined wheels.

Values:

  • fail: Will fail in the build action ensuring that we get the errormessage no matter the action cache.

  • ``: (empty string) The default value, that will just print a warning.

See also

pip.parse

Added in version 1.1.0.

flag--//python/config_settings:venvs_use_declare_symlink

Determines if relative symlinks are created usingdeclare_symlink() at buildtime.

This is only intended to work around#2489, where somepackaging rules don’t supportdeclare_symlink() artifacts.

Values:

  • yes: Usedeclare_symlink() and create relative symlinks at build time.

  • no: Do not usedeclare_symlink(). Instead, the venv will be created atruntime.

See also

RULES_PYTHON_EXTRACT_ROOT for customizing where the runtime venvis created.

Added in version 1.2.0.