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

Python rules ignore "imports" provider passed in from Starlark-defined rules #7054

Closed
brandjon opened this issue Jan 7, 2019 · 6 comments
Closed
Labels
P1 I'll work on this now. (Assignee required) team-Rules-Python Native rules for Python type: bug

Comments

@brandjon
Copy link
Member

brandjon commented Jan 7, 2019

From what I can tell from reading the code and some quick experimentation, it looks like we pull the imports from the native PythonImportsProvider and from BazelPythonSemantics#getImports (which reads the imports attribute), but not from the imports field of a py provider struct of a dependency. This is a simple fix, but we can probably combine it with a cleanup that removes PythonImportsProvider altogether. Won't address until after we deprecate the py legacy struct provider.

@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 Jan 7, 2019
bazel-io pushed a commit that referenced this issue Jan 18, 2019
The rewritten test is non-Bazel specific and directly checks the sandwich use case.

There's a slight loss in coverage that will be addressed with #7054.

Work towards #1446.

RELNOTES: None
PiperOrigin-RevId: 230002328
weixiao-huang pushed a commit to weixiao-huang/bazel that referenced this issue Jan 31, 2019
The rewritten test is non-Bazel specific and directly checks the sandwich use case.

There's a slight loss in coverage that will be addressed with bazelbuild#7054.

Work towards bazelbuild#1446.

RELNOTES: None
PiperOrigin-RevId: 230002328
@ovy
Copy link

ovy commented Feb 8, 2019

Hi guys,

I am in dire need of a fix for this right now. The fact that the imports attribute was being silently ignored, coupled with the transitionary state of the py provider docs, has already lead to much hair pulling in my proposed migration to Bazel. Is there any chance you can prioritize it, even if that means making it PyInfo-only ("modern-only") ** ? I really don't know how to make imports work properly otherwise. A py_library wrapper seems like a non-starter because of the other transitive information we need to propagate.

Best,
Ovy

Edit: to clarify, a world in which PyInfo.imports works but "py".imports doesn't still seems much better than a world in which neither works. So we don't have to wait until the disallow_legacy is default, I think. Or am I misunderstanding and PyInfo.imports will work in 0.23?

@brandjon
Copy link
Member Author

brandjon commented Feb 8, 2019

When I was refactoring how PyCommon manages the Python provider(s), I made a conscious decision to not try to bugfix / alter semantics, for fear of introducing regressions that would require their own incompatible changes and complicate the migration to PyInfo. It's not actually any harder to fix it for both the legacy provider and PyInfo than for just one or the other.

Looking over the rule logic again, it seems that this is simpler than I remember. (Refactorings have that effect after all...) PythonImportsProvider -- which is the native code's way of passing imports around, and the one that the rules actually listen to -- is only ever created and used in a straightforward way. There's really no reason we can't replace it with the imports field of the legacy and PyInfo providers.

Given the ease of the fix vs the benefit, I'll prioritize this. Should appear in 0.24 (the release after the current RC).

@brandjon brandjon added P1 I'll work on this now. (Assignee required) and removed P3 We're not considering working on this, but happy to review a PR. (No assignee) labels Feb 8, 2019
@ovy
Copy link

ovy commented Feb 8, 2019

Thanks Jon! I appreciate the quick response and offer to fix. I wish it was sooner than 0.24 though... any chance it's simple enough (as well as being pure forward progress) to be in .23?

I also look forward to the py provider matching the others.

Once this is done, I'll probably contribute a nice chunk of Starlark (for interop with ROS) back to the community, so this is good karma all around.

@brandjon
Copy link
Member Author

brandjon commented Feb 8, 2019

Unfortunately the baseline for 0.23 has already been cut, and we tend not to cherry pick feature requests in, as opposed to bug fixes. In the meantime you can try it out with bazel built at head. Watch this bug to see when the fix is in.

@brandjon
Copy link
Member Author

brandjon commented Feb 8, 2019

Also, you should still be able to add imports using the regular old py_library rule. Maybe you can combine that with your rule in a macro to hack around this bug in the meantime.

@brandjon
Copy link
Member Author

Fix is in if you wanted to grab a dev build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 I'll work on this now. (Assignee required) team-Rules-Python Native rules for Python type: bug
Projects
None yet
Development

No branches or pull requests

2 participants