Uh oh!
There was an error while loading. Please reload this page.
feat!: always generating py_library - #2982
Conversation
linzhp
commented
Jun 12, 2025
@aignas Can you take a look? The failing test is due to an infra issue. |
aignas
left a comment
There was a problem hiding this comment.
In general I am +1 on the change as I think the behaviour makes sense, but this has to come together with CHANGELOG notes explaining users how they can migrate to the new thing.
I think the problem may be for all of the data dependencies where users depend on the py_binary named foo and they will have to migrate to foo_bin in the data dependencies. Maybe having a few buildozer commands might be enough to help users onboard to the new schema?
@dougthor42, what do you think?
I'm not sure how I feel about this. These are my concerns, in no particular order:
This feels like a 2.0 change to me, if it gets added. |
dougthor42
commented
Jun 13, 2025
Ah, looks like @aignas we share at least some thoughts, if not the same conclusion 🙃 . While buildozer commands might be useful for an initial migration, I don't think such a thing is really suitable for long-term use. Requiring users to set up buildozer to sync target attributes from library to binary at every change seems like undue burden. We'd basically be asking everyone to set up CI for their project that runs "buildozer copy attributes from A to B" |
linzhp
commented
Jun 13, 2025
Maybe can take this approach instead. This would make the migration easier. |
rickeylev
commented
Jun 13, 2025
Re: same src in multiple files The technical constraint is it'll interact poorly with precompiling. In general, though, yes, the same source being in multiple targets is an anti pattern and prone to causing issues. I think what makes more sense is to allow a binary to get it's main source from another target directly. Eg allow a library to be the target of |
dougthor42
commented
Jun 14, 2025
Perhaps we should move this to a Discussion or write up a design doc to hash things out. I'm still not sure I fully understand the issue that it's solving, but to be fair I almost exclusively use file generation mode so maybe I'm simply not running into the issue(s). |
linzhp
commented
Jun 15, 2025
It's solving the same issue as #2822: the same Python file can exist both in a |
linzhp
commented
Jun 15, 2025
Did some archeology and found the discussion in #1664. I agree with @rickeylev in that discussion that:
However, it's too late to fix it due to migration cost discussed in this thread. So I put out a lightweight fix to it in #2989 instead. Please take a look. |
This PR makes sure that all non-test Python modules are covered by a
py_librarytarget. When a module is imported by another target, Gazelle no longer resolves it topy_binaryand only resolves topy_library, which is consistent with other languages.Note that in file mode, this means there would be duplicate
py_binaryandpy_library, with the samesrcsanddeps(see changed test cases). Because these attributes are maintained by Gazelle, there is no additional maintenance cost from the users. To reduce the duplication, we will need to change rules_python to add anembedsattribute topy_binary, so it can inherit allsrcsanddepsfrompy_library, similar to theembedsattribute of Go rules.In addition, this PR renames the
py_binarytarget offoo.pytofoo_binand usefoofor thepy_library, to be consistent with the current naming convention in package mode. However, this requires users to remove or rename their existingpy_binaryrules during the migration.This is an alternative implementation of #2822. cc @yushan26