-
-
Notifications
You must be signed in to change notification settings - Fork 597
feat!: always generating py_library #2982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@aignas Can you take a look? The failing test is due to an infra issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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" |
Maybe can take this approach instead. This would make the migration easier. |
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 |
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). |
It's solving the same issue as #2822: the same Python file can exist both in a |
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_library
target. When a module is imported by another target, Gazelle no longer resolves it topy_binary
and only resolves topy_library
, which is consistent with other languages.Note that in file mode, this means there would be duplicate
py_binary
andpy_library
, with the samesrcs
anddeps
(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 anembeds
attribute topy_binary
, so it can inherit allsrcs
anddeps
frompy_library
, similar to theembeds
attribute of Go rules.In addition, this PR renames the
py_binary
target offoo.py
tofoo_bin
and usefoo
for thepy_library
, to be consistent with the current naming convention in package mode. However, this requires users to remove or rename their existingpy_binary
rules during the migration.This is an alternative implementation of #2822. cc @yushan26