-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Make __init__.py files creation optional #4470
Conversation
Can one of the admins verify this patch? |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
48cfa4b
to
ea3e8f7
Compare
Controls whether to create __init__.py files in paths where they don't exists | ||
or not, default is to true for backward compatibility and to support legacy behavior. | ||
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */ | ||
.add(attr("legacy_create_init", BOOLEAN).value(true)) |
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.
Please advise on the name of the attribute, I went with the legacy_
convention since I saw it used for some attributes but I am not sure if it's the right use case.
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.
I was wondering if this should be an enum or integer, in case we want more than two behaviors. But I can't think of any third thing we might do.
Can we call it legacy if we don't have a specific plan to switch everything to the new behavior? I'm ok with it, but if you wanted a different name, maybe implict_create_init_py
?
You could expand the comment a bit to explain the legacy behavior:
Whether to implicitly create empty __init__.py files in the runfiles tree.
These are created in every directory containing Python source code or
shared libraries, and every parent directory of those directories.
Default is true for backward compatibility. If false, the user is responsible
for creating __init__.py files (empty or not) and adding them to `srcs` or `deps`
of Python targets as required.
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.
I like your description will adapt, concerning the attribute name IMHO we should drop the behavior in the future and that's how I understood it here bazelbuild/rules_python#55 (comment).
I signed it! |
CLAs look good, thanks! |
Thanks for the patch! Code changes look good. Unfortunately, we haven't open sourced some of the py_* tests yet :-(, so it's not easy to write unit tests. @lberki, what do you think? |
/cc @scentini (sorry for the late reply, this surfaced in my inbox after @ulfjack 's reply) @ulfjack : do you think this is desirable functionality? There is clearly need for it, but our Python rules aren't very well shepherded at the moment and it's One More Knob. I'd say "anyways, here's Wonderwall^H the new attribute", but would like to have a second opinion. |
See bazelbuild/rules_python#55 for context. This seems to be an issue for a number of users, and @duggelz said that the current behavior is legacy. |
Let me just write an integration test which you can then extend.... |
How about open sourcing PyBinaryConfiguredTarget instead? Writing more integration tests will just make our presubmits run even more slowly. :-P |
I looked at it and I'm all for fast tests, but at the same time, we should have a few integration tests just to be sure. |
FYI: Code review for the test sent out: https://bazel-review.googlesource.com/c/bazel/+/34750 |
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.
This is terrific.
Controls whether to create __init__.py files in paths where they don't exists | ||
or not, default is to true for backward compatibility and to support legacy behavior. | ||
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */ | ||
.add(attr("legacy_create_init", BOOLEAN).value(true)) |
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.
I was wondering if this should be an enum or integer, in case we want more than two behaviors. But I can't think of any third thing we might do.
Can we call it legacy if we don't have a specific plan to switch everything to the new behavior? I'm ok with it, but if you wanted a different name, maybe implict_create_init_py
?
You could expand the comment a bit to explain the legacy behavior:
Whether to implicitly create empty __init__.py files in the runfiles tree.
These are created in every directory containing Python source code or
shared libraries, and every parent directory of those directories.
Default is true for backward compatibility. If false, the user is responsible
for creating __init__.py files (empty or not) and adding them to `srcs` or `deps`
of Python targets as required.
|
||
if (ruleContext.attributes().get("legacy_create_init", Type.BOOLEAN)) { | ||
builder.setEmptyFilesSupplier(PythonUtils.GET_INIT_PY_FILES); | ||
} |
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.
I'm a little dumbfounded that it's this simple. I guess that means the Bazel code is well structured.
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.
Indeed it is, if I can do it then everyone can :)
@lberki Awesome, will try to adapt. |
Just a small update, I didn't forget about this, it have been some busy two weeks with conferences and sickness, I will try to update it in the weekend, apologies for any issues that the delay may have caused. |
No problem, looking forward to it! |
Introduce a new attribute to py_binary and py_test to control whether to create `__init__.py` or not. Fixes bazelbuild/rules_python#55
Also address review comment concerning documentation.
ea3e8f7
to
1211395
Compare
Automated tests added @lberki please have a look. |
Erm, sorry for the late reply. Looks good, I'll merge this. Thanks for the patience! |
/cc @scentini Wait a moment... is it still the case that flipping the flag doesn't delete/add the |
Yes its still the case, the way I understood it, and please correct me if I
am wrong, is that Bazel in general doesn’t track files that it doesn’t know
off (this issue is common in tools that works with files like configuration
management), so disabling a behaviour that was creating some files will not
make this files disappear afterwards only a clean run will do that.
One way of fixing this is instead of telling Bazel to not create
__init__.py files, Bazel should insure that no __init__.py is there that
doesn’t have an equivalent in workspace, in practical sense what we can do
is to start by deleting all __init__.py files as pre step, thoughts?
…On Wed 14. Feb 2018 at 09:39, lberki ***@***.***> wrote:
/cc @scentini <https://github.com/scentini>
Wait a moment... is it still the case that flipping the flag doesn't
delete/add the *init*.py files? I'd be surprised if that was the case and
it's not for you to fix in any case, but that sounds somewhat scary.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4470 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABzBc_7lRF3D92Jmau0bZLgwazM2ynn2ks5tUpungaJpZM4RhMIs>
.
|
The |
Will be rolled back then resubmitted; this change breaks some tests. |
*** Reason for rollback *** Breaks Kokoro and I accidentally submitted the change without presubmit checks. *** Original change description *** Make __init__.py files creation optional Introduce a new attribute to py_binary and py_test to control whether to create `__init__.py` or not. Fixes bazelbuild/rules_python#55 Closes #4470. PiperOrigin-RevId: 185676592
*** Reason for rollback *** Remove example changes; those need to build with the last Bazel release. *** Original change description *** Automated rollback of commit 0f9c6ea. *** Reason for rollback *** Breaks Kokoro and I accidentally submitted the change without presubmit checks. *** Original change description *** Make __init__.py files creation optional Introduce a new attribute to py_binary and py_test to control whether to create `__init__.py` or not. Fixes bazelbuild/rules_python#55 Closes #4470. PiperOrigin-RevId: 185806241
I am a bit lost, @lberki can you explain what's the status of the fix? |
Erm, this is indeed confusing -- I merged your change, then had to roll it back, for it broke some tests and I accidentally submtited it without checking the tests, then rolled back the rollback after fixing the tests, so it should be now on HEAD. Its final version is e9c885a . |
FTR I just tried to reproduce the incremental correctness issue where |
Introduce a new attribute to py_binary and py_test to control whether to
create
__init__.py
or not.Fixes bazelbuild/rules_python#55
TODO:
__init__.py
files, b/c currently running clean is required after flipping the flag.