Skip to content
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

Empty __init__.py files are being generated for repo root and runfiles root #7653

Closed
brandjon opened this issue Mar 6, 2019 · 5 comments
Closed
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-Python Native rules for Python type: bug

Comments

@brandjon
Copy link
Member

brandjon commented Mar 6, 2019

This happens only for targets that are referenced by their full repo name, i.e. @//foo:bar or //foo:bar. This probably includes all external repo targets (though I have not tested that), and main repo targets when the main repo's full name is not used and when --incompatible_remap_main_repo is false.

See here for a more detailed explanation.

The effect of this bug is that some targets have been able to get away with omitting a dependency on the top-level __init__.py file of their repo, provided that the legacy_create_init attribute is true (default). Fixing this bug may break these targets.

It's also questionable whether we should bother fixing this behavior at all, or just go ahead and deprecate automatic init creation.

@brandjon brandjon added type: bug P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Python Native rules for Python labels Mar 6, 2019
@brandjon
Copy link
Member Author

brandjon commented Mar 6, 2019

Note, however, that targets that have been getting away with not declaring a dependency on the top-level init file will likely break when --incompatible_remap_main_repo is flipped on. In fact, flipping that flag may have the side-effect of effectively fixing this bug, or at least making it inaccessible. (@dkelmer)

@eacousineau
Copy link

I think relates #3998 (for remote repos)? (along the lines of legacy_create_init)

@brandjon
Copy link
Member Author

They're both import-related, but that bug's about name clashes between multiple things on the PYTHONPATH, and this is about __init__.py getting created in places where it isn't expected.

@EricCousineau-TRI
Copy link
Contributor

EricCousineau-TRI commented Apr 29, 2020

FTR, here's a doc link for current version of Bazel (3.1.0):
https://docs.bazel.build/versions/3.1.0/be/python.html#py_binary.legacy_create_init

In those docs, there's the flag --incompatible_default_to_explicit_init_py, which can be used to override.

As a small related note, without control over how the runfiles tree is generated, it may be impossible to do things like workaround #4594 for Python, where the implicit module allows on to do a hack like import external.{repository}.{package}.
See example solution here:
RobotLocomotion/drake#8240
Code: https://github.com/EricCousineau-TRI/drake/blob/de4f7a74afc78c221c85d76601e834f06e825e97/bindings/pydrake/__init__.py#L17

EDIT: I lied. The above Python workaround can be done using Rlocation stuff.

@sgowroji sgowroji added the stale Issues or PRs that are stale (no activity for 30 days) label Feb 16, 2023
@sgowroji
Copy link
Member

Hi there! We're doing a clean up of old issues and will be closing this one. Please reopen if you’d like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so.

@sgowroji sgowroji closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-Python Native rules for Python type: bug
Projects
None yet
Development

No branches or pull requests

4 participants