Skip to content

fix(precompile): skip precompilation for directory and pyc inputs in srcs - #4113

Open
rickeylev wants to merge 12 commits into
bazel-contrib:mainfrom
rickeylev:skip_precompile_src_errors
Open

fix(precompile): skip precompilation for directory and pyc inputs in srcs#4113
rickeylev wants to merge 12 commits into
bazel-contrib:mainfrom
rickeylev:skip_precompile_src_errors

Conversation

@rickeylev

Copy link
Copy Markdown
Collaborator

Precompiling py_library, py_binary, or py_test targets fails when
srcs contains directory artifacts or .pyc files. The precompiler
declares invalid actions on directories and drops non-.py sources from
default outputs.

This change:

  • Expands direct sources to include Python files, .pyc files, and
    directories.
  • Skips precompilation for directories and non-Python files while
    retaining them in default outputs.
  • Updates srcs validation and documentation.

Add analysis and execution tests verifying precompiling behavior when directory or pyc file inputs are passed in target srcs.
Directories and precompiled pyc files cannot be compiled directly into pyc files. Skip precompiling when src.is_directory is true or the extension is pyc/pyo while retaining them in target outputs.
… srcs

Allow arbitrary files in the srcs attribute while filtering to Python source files via an is_py_source helper. Skip precompilation for directories or any file that is not a Python source file, and remove legacy py3 extension references.
…mat srcs doc

Propagate input .pyc files through precompilation into target default outputs, and format the srcs attribute docstring with a list of allowed file types.
…ies to maybe_precompile

Compute direct_sources as the py, pyc, and directory files from srcs, pass direct_sources to maybe_precompile, and update tree artifact analysis test outputs.
…ecompile doc

Factor out filter_to_direct_sources helper in common.bzl to share direct sources filtering across py_library and py_executable, and update _precompile return type docstring.
…bzl_library dep

Add news fragment for skip precompile src errors fix, document allowed srcs file types with versionchanged in attributes.bzl, and add :common dependency to precompile bzl_library.
Associate news entry with newly created PR bazel-contrib#4113.
…ctive

Update version directive in attributes.bzl from VERSION_NEXT_FEATURE to VERSION_NEXT_PATCH.
…ntry

Update news/4113.fixed.md to use valid Sphinx MyST {obj} syntax, wrap lines within 80 columns, and link to PR bazel-contrib#4113.
@rickeylev
rickeylev marked this pull request as ready for review August 25, 2026 07:43
@rickeylev
rickeylev requested a review from aignas as a code owner August 25, 2026 07:43
],
)
srcs_attr = builder.attrs.get("srcs")
srcs_attr.set_allow_files(True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed.

srcs_attr.set_allow_files(True)
srcs_attr.set_doc(srcs_attr.doc() + """

:::{versionchanged} 2.3.2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be also consolidated in the common.bzl?

@aignas aignas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending the comments, LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants