Added support to expose imports for python to Skylark. - #2791
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.
|
|
I signed it! |
|
CLAs look good, thanks! |
| // adjusted to be relative to the workspace name. | ||
| packageFragment = PathFragment.create(ruleContext.getWorkspaceName()) | ||
| .getRelative(packageFragment); | ||
| return PathFragment.create(ruleContext.getWorkspaceName()) |
There was a problem hiding this comment.
Isn't this the same as PackageIdentifier#getRunfilesPath()?
|
|
||
| /** | ||
| * @return - {@link PathFragment} representing the python package. | ||
| */ |
There was a problem hiding this comment.
Likewise, there is no need to put this here; since it's just PackageIdentifier#getRunfilesPath(), let's just use that and not pollute the PythonSemantics interface (which shouldn't exist anyway...)
| IS_USING_SHARED_LIBRARY, | ||
| isUsingSharedLibrary), | ||
| isUsingSharedLibrary, | ||
| PACKAGE_FRAGMENT, |
There was a problem hiding this comment.
Given that this is computable from the package fragment, how about not having this function here? If needed, we could add a method to Label that tells its runfiles path, right, @laurentlb ?
|
@srikalyan can you follow up on this? |
|
@iirina I followed up couple days back. Please let me know if I am missing something. |
srikalyan
left a comment
There was a problem hiding this comment.
Addressed all the review comments.
|
Thank you! |
| isUsingSharedLibrary, | ||
| IMPORTS, | ||
| SkylarkNestedSet.of(String.class, | ||
| makeImportStrings(imports )) |
There was a problem hiding this comment.
super nit: unnecessary space after "imports"
|
Reviewed. |
|
Can one of the admins verify this patch? |
| final NestedSetBuilder<String> builder = NestedSetBuilder.compileOrder(); | ||
|
|
||
| for (PathFragment pathFragment : imports) { | ||
| builder.add(pathFragment.toString()); |
There was a problem hiding this comment.
This effectively negates any benefit of nested sets here, because you create a new, flat nested set with the strings instead of the carefully built-up nested set with import path fragments inherited from dependent targets.
@laurentlb @vladmos , is there a way to expose a NestedSet<PathFragment> to Skylark instead? That's a more promising avenue than working around the limitation that PathFragments aren't available there. This would also help with flattening the PathFragments into strings so that e.g. "longdirectory/a" and "longdirectory/b" can share structure.
There was a problem hiding this comment.
Sorry for late reply. We do not plan to expose PathFragments to Skylark. Can you do with NestedSet<String> instead?
There was a problem hiding this comment.
Or return a Iterable that lazily iterates a nested set when needed.
There was a problem hiding this comment.
Sorry for my late reply. I will add it asap.
There was a problem hiding this comment.
I am sorry for not understanding what you are trying to suggest here. I think (I may be completely wrong) that you are suggesting the proposed change? @dslomov can you comment?
There was a problem hiding this comment.
Please read https://docs.bazel.build/versions/master/skylark/depsets.html.
What you are doing here is flattening the depset of path fragments to convert them to strings.
Since this is happening for every python rule, that will bloat the memory.
There are two approaches you can take instead:
- Use
NestedSet<String>instead ofNestedSet<PathFragment>everywhere. - Make a value of 'imports' an
Iterablethat lazily flattens a nested set on iteration.
My preferred approach is (1) but I do not know how expensive it is to keep Strings instead of PathFragments.
(2) is ok as well.
| PythonSemantics semantics, NestedSet<Artifact> filesToBuild) { | ||
|
|
||
| public void addCommonTransitiveInfoProviders( | ||
| RuleContext ruleContext, |
There was a problem hiding this comment.
Why do you need RuleContext here?
There was a problem hiding this comment.
I don't exactly remember as this has been really old. I think I had to add it because rule context in pycommon was different from pylibrary/pybinary.
There was a problem hiding this comment.
I can double check this and let you know.
| final NestedSetBuilder<String> builder = NestedSetBuilder.compileOrder(); | ||
|
|
||
| for (PathFragment pathFragment : imports) { | ||
| builder.add(pathFragment.toString()); |
There was a problem hiding this comment.
Or return a Iterable that lazily iterates a nested set when needed.
|
Friendly ping @srikalyan , is this still being developed? |
|
Can one of the admins verify this patch? |
|
any update on this? |
|
Any chance this is getting in in 2017? |
|
@fahhem I am waiting on the review comments |
|
@srikalyan, yes, I was hoping to prod the bazel maintainers more than you. Sorry for that! @dslomov or @vladmos, ping! Is there a plan to make something more general available soon or can we merge this PR for now? Unfortunately, we missed the 0.9.0 release, but hopefully we can get in before the next one still! |
|
@dslomov PTAL at the review comments when you have the bandwidth? |
|
Ping @dslomov - please take action on this PR. |
|
Can one of the admins verify this patch? |
|
ping -- are there any updates? can we merge or close this PR? |
|
I think it is safe to merge. I am just waiting for approval :( |
| final NestedSetBuilder<String> builder = NestedSetBuilder.compileOrder(); | ||
|
|
||
| for (PathFragment pathFragment : imports) { | ||
| builder.add(pathFragment.toString()); |
There was a problem hiding this comment.
Please read https://docs.bazel.build/versions/master/skylark/depsets.html.
What you are doing here is flattening the depset of path fragments to convert them to strings.
Since this is happening for every python rule, that will bloat the memory.
There are two approaches you can take instead:
- Use
NestedSet<String>instead ofNestedSet<PathFragment>everywhere. - Make a value of 'imports' an
Iterablethat lazily flattens a nested set on iteration.
My preferred approach is (1) but I do not know how expensive it is to keep Strings instead of PathFragments.
(2) is ok as well.
|
Hi @srikalyan, Bazel sheriff here, what's the status of this pull request? It hasn't been updated for more than a week so it'd be good to understand if it's still ongoing or safe to close. Thanks. |
|
@srikalyan ping, could you please address @dslomov's comments? thanks! |
|
A lot of people are wasting cycles on this, trying to reimplement all the python rules in Skylark to be able to access their version of the |
|
Closing due to lack of updates from the original author. Maybe someone else wants to take this over. |
Fixes #2617. Please let me know if you need anything else.