-
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
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! |
// Python scripts start with x.runfiles/ as the module space, so everything must be manually | ||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as PackageIdentifier#getRunfilesPath()?
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.
Removed it.
@@ -60,6 +60,11 @@ void collectDefaultRunfilesForBinary(RuleContext ruleContext, Runfiles.Builder b | |||
RuleContext ruleContext, Collection<Artifact> sources, PyCommon common); | |||
|
|||
/** | |||
* @return - {@link PathFragment} representing the python package. | |||
*/ | |||
PathFragment getPackageFragment(RuleContext ruleContext); |
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.
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...)
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.
Removed it.
return NativeClassObjectConstructor.STRUCT.create( | ||
ImmutableMap.<String, Object>of( | ||
TRANSITIVE_PYTHON_SRCS, | ||
SkylarkNestedSet.of(Artifact.class, transitivePythonSources), | ||
IS_USING_SHARED_LIBRARY, | ||
isUsingSharedLibrary), | ||
isUsingSharedLibrary, | ||
PACKAGE_FRAGMENT, |
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.
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 ?
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.
Removed it.
@srikalyan can you follow up on this? |
@iirina I followed up couple days back. Please let me know if I am missing something. |
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.
Addressed all the review comments.
Thank you! |
isUsingSharedLibrary, | ||
IMPORTS, | ||
SkylarkNestedSet.of(String.class, | ||
makeImportStrings(imports )) |
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.
super nit: unnecessary space after "imports"
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.
Done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 PathFragment
s aren't available there. This would also help with flattening the PathFragment
s into strings so that e.g. "longdirectory/a" and "longdirectory/b" can share structure.
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.
Sorry for late reply. We do not plan to expose PathFragment
s to Skylark. Can you do with NestedSet<String>
instead?
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.
Or return a Iterable that lazily iterates a nested set when needed.
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.
Sorry for my late reply. I will add it asap.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Friendly ping @dslomov :)
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 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
Iterable
that 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need RuleContext
here?
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can double check this and let you know.
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.
Removed it.
final NestedSetBuilder<String> builder = NestedSetBuilder.compileOrder(); | ||
|
||
for (PathFragment pathFragment : imports) { | ||
builder.add(pathFragment.toString()); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Iterable
that 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.