Skip to content

Added support to expose imports for python to Skylark. - #2791

Closed
srikalyan wants to merge 8 commits into
bazelbuild:masterfrom
srikalyan:master
Closed

Added support to expose imports for python to Skylark.#2791
srikalyan wants to merge 8 commits into
bazelbuild:masterfrom
srikalyan:master

Conversation

@srikalyan

Copy link
Copy Markdown

Fixes #2617. Please let me know if you need anything else.

@bazel-io

bazel-io commented Apr 7, 2017

Copy link
Copy Markdown
Member

Can one of the admins verify this patch?

@googlebot

Copy link
Copy Markdown

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!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@srikalyan

Copy link
Copy Markdown
Author

I signed it!

@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Apr 7, 2017
// adjusted to be relative to the workspace name.
packageFragment = PathFragment.create(ruleContext.getWorkspaceName())
.getRelative(packageFragment);
return PathFragment.create(ruleContext.getWorkspaceName())

Copy link
Copy Markdown
Contributor

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()?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it.


/**
* @return - {@link PathFragment} representing the python package.
*/

Copy link
Copy Markdown
Contributor

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...)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it.

IS_USING_SHARED_LIBRARY,
isUsingSharedLibrary),
isUsingSharedLibrary,
PACKAGE_FRAGMENT,

Copy link
Copy Markdown
Contributor

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 ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it.

@iirina

iirina commented May 23, 2017

Copy link
Copy Markdown
Contributor

@srikalyan can you follow up on this?

@srikalyan

Copy link
Copy Markdown
Author

@iirina I followed up couple days back. Please let me know if I am missing something.

@iirina

iirina commented May 23, 2017

Copy link
Copy Markdown
Contributor

I didn't see any replies to @lberki's comments and I overlooked the last commit, sorry. Can you mark the comments as done?
@lberki, can you take another look at this?

@srikalyan srikalyan left a comment

Copy link
Copy Markdown
Author

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.

@iirina

iirina commented May 23, 2017

Copy link
Copy Markdown
Contributor

Thank you!

isUsingSharedLibrary,
IMPORTS,
SkylarkNestedSet.of(String.class,
makeImportStrings(imports ))

Copy link
Copy Markdown
Contributor

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"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@lberki

lberki commented May 24, 2017

Copy link
Copy Markdown
Contributor

Reviewed.

@bazel-io

Copy link
Copy Markdown
Member

Can one of the admins verify this patch?

final NestedSetBuilder<String> builder = NestedSetBuilder.compileOrder();

for (PathFragment pathFragment : imports) {
builder.add(pathFragment.toString());

Copy link
Copy Markdown
Contributor

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 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.

Copy link
Copy Markdown
Contributor

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 PathFragments to Skylark. Can you do with NestedSet<String> instead?

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown
Author

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Friendly ping @dslomov :)

Copy link
Copy Markdown
Contributor

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:

  1. Use NestedSet<String> instead of NestedSet<PathFragment> everywhere.
  2. 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,

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown
Author

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());

Copy link
Copy Markdown
Contributor

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.

@hlopko

hlopko commented Oct 11, 2017

Copy link
Copy Markdown
Member

Friendly ping @srikalyan , is this still being developed?

@bazel-io

Copy link
Copy Markdown
Member

Can one of the admins verify this patch?

@ali5h

ali5h commented Dec 8, 2017

Copy link
Copy Markdown

any update on this?

@fahhem

fahhem commented Dec 12, 2017

Copy link
Copy Markdown
Contributor

Any chance this is getting in in 2017?

@srikalyan

Copy link
Copy Markdown
Author

@fahhem I am waiting on the review comments

@fahhem

fahhem commented Dec 19, 2017

Copy link
Copy Markdown
Contributor

@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!

@jin

jin commented Jan 8, 2018

Copy link
Copy Markdown
Member

@dslomov PTAL at the review comments when you have the bandwidth?

@philwo

philwo commented Feb 3, 2018

Copy link
Copy Markdown
Member

Ping @dslomov - please take action on this PR.

@bazel-io

bazel-io commented Feb 3, 2018

Copy link
Copy Markdown
Member

Can one of the admins verify this patch?

@laszlocsomor

Copy link
Copy Markdown
Contributor

ping -- are there any updates? can we merge or close this PR?

@srikalyan

Copy link
Copy Markdown
Author

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());

Copy link
Copy Markdown
Contributor

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:

  1. Use NestedSet<String> instead of NestedSet<PathFragment> everywhere.
  2. 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.

@lfpino

lfpino commented Mar 27, 2018

Copy link
Copy Markdown
Contributor

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.

@jin

jin commented Apr 9, 2018

Copy link
Copy Markdown
Member

@srikalyan ping, could you please address @dslomov's comments? thanks!

@c4urself

Copy link
Copy Markdown
Contributor

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 imports attribute, see for example: https://github.com/TriggerMail/rules_pyz/blob/master/rules_python_zip/rules_python_zip.bzl#L39 anything we can do to move this forward?

@ulfjack

ulfjack commented Oct 11, 2018

Copy link
Copy Markdown
Contributor

Closing due to lack of updates from the original author. Maybe someone else wants to take this over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.