Skip to content

Conversation

@arrdem
Copy link
Collaborator

@arrdem arrdem commented Nov 5, 2025

Determining the main using suffix matching was always weird and a poor choice of semantics. The underlying rules have long required that main be a label. Other rules such as rust_binary and go_binary strictly require labels, Gazelle generates strict label references. As such this behavior is inconsistent with the broader ecosystem, a source of an unneeded action and potential footguns. Rip out determine_main and provide minimal default semantics for main as part of the existing wrapper macros.

Those too should go away, but for now we have them.

Replaces #641 with thanks to Keith.
Fixes #605
Fixes #621

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change (forces users to change their own code or config): yes
  • Suggested release notes appear below: yes

BREAKING: The main= of py_* targets must now be a file label. Main will no longer be searched for by string suffix.

Test plan

  • Covered by existing test cases

@arrdem arrdem requested review from alexeagle and dzbarsky November 5, 2025 00:36
@arrdem arrdem added the breaking Requires a semver-major release due to breaking public API changes label Nov 5, 2025
arrdem and others added 2 commits November 4, 2025 17:50
Determining the main using suffix matching was always a goofy idea. The
underlying rules have long required that main be a label. Rip out
determine_main and provide minimal default semantics for main as part of
the existing wrapper macros.

Those too should go away, but for now we have them.

Replaces #641 with thanks to Keith.
@arrdem arrdem force-pushed the arrdem/remove-determine-main branch from 59f9875 to bf5852e Compare November 5, 2025 00:51
@aspect-workflows
Copy link

aspect-workflows bot commented Nov 5, 2025

test-os:linux-bzl:8 (Test)

⚠️ Buildkite build #921 is currently failing.

//py:defs.doc_extract failed to build

in src attribute of starlark_doc_extract rule //py:defs.doc_extract: at
/mnt/ephemeral/workdir/aspect-build/rules_py/py/defs.bzl:38:6: cannot load
'@@aspect_bazel_lib+//lib:util.bzl': no such file. Since this rule was created by the macro 'bzl_library',
the error might have been caused by the macro implementation

💡 To reproduce the build failures, run

bazel build //py:defs.doc_extract

test-os:linux-bzl:latest (Test)

⚠️ Buildkite build #921 is currently failing.

//py:defs.doc_extract failed to build

in src attribute of starlark_doc_extract rule //py:defs.doc_extract: at
/mnt/ephemeral/workdir/aspect-build/rules_py/py/defs.bzl:38:6: cannot load
'@@aspect_bazel_lib+//lib:util.bzl': no such file. Since this rule was created by the macro 'bzl_library',
the error might have been caused by the macro implementation

💡 To reproduce the build failures, run

bazel build //py:defs.doc_extract

test-os:linux-bzl:8 (Test)

e2e

⚠️ Buildkite build #921 failed.

@@+_repo_rules2+subrepo_a//:foo failed to build

error loading package '@@+_repo_rules2+subrepo_a//': at
/mnt/ephemeral/output/rules_py/e2e/external/aspect_rules_py+/py/defs.bzl:38:6: cannot load
'@@aspect_bazel_lib+//lib:util.bzl': no such file

💡 To reproduce the build failures, run

bazel build @@+_repo_rules2+subrepo_a//:foo

test-os:linux-bzl:latest (Test)

e2e

⚠️ Buildkite build #921 failed.

@@+_repo_rules2+subrepo_a//:foo failed to build

error loading package '@@+_repo_rules2+subrepo_a//': at
/mnt/ephemeral/output/rules_py/e2e/external/aspect_rules_py+/py/defs.bzl:38:6: cannot load
'@@aspect_bazel_lib+//lib:util.bzl': no such file

💡 To reproduce the build failures, run

bazel build @@+_repo_rules2+subrepo_a//:foo

test-os:linux-bzl:8 (Test)

examples/uv_pip_compile

Waiting for runner...


test-os:linux-bzl:latest (Test)

examples/uv_pip_compile

All tests were cache hits

1 test (100.0%) was fully cached saving 335ms.

@alexeagle
Copy link
Member

note that this is a subtle compatibility break with rules_python, at least last time I dug into this code, rules_python users couldn't adopt rules_py without changing their code.

Perhaps we can make the case that we no longer aim for drop-in compatibility with rules_python, but if we give that up we ought to be clear about it in the readme or other communication with users.

@dzbarsky
Copy link
Collaborator

dzbarsky commented Nov 5, 2025

note that this is a subtle compatibility break with rules_python, at least last time I dug into this code, rules_python users couldn't adopt rules_py without changing their code.

Perhaps we can make the case that we no longer aim for drop-in compatibility with rules_python, but if we give that up we ought to be clear about it in the readme or other communication with users.

This is true; rules_python has already swapped determine_main to be a function instead of a standalone target, so let's at least do that if we don't want to make the bigger change. (Though I do think the new semantics are clearer)

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

Labels

breaking Requires a semver-major release due to breaking public API changes

Projects

None yet

5 participants