Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

added the ability to specify a custom wheel package root #200

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

Merged
merged 5 commits into from
Jul 9, 2019
Merged

Conversation

sha1n
Copy link
Contributor

@sha1n sha1n commented Jul 3, 2019

This PR suggests a possible way to address the issues described in #199. I added an optional attribute package_root_path to the py_wheel rule, that specifies the root of the package, relative to the workspace path.

This patch only fixes the problem for cases in which the entire package is under the same path. If the package bundles dependencies from other paths, those will not be fixed. It would be nice if we could define the prefix on the sources and strip the prefix when we create the final package. Not sure how to do that and will be very happy to hear suggestions, or alternative approaches.

Thanks.

py_wheel(
    package_root_path = "experimental"
    name = ...
    distribution = ...
    python_tag = ...
    version = ...
    deps = ...
)

@@ -242,6 +243,10 @@ to refer to the package in other packages' dependencies.
"license": attr.string(default = ""),
"classifiers": attr.string_list(),
"description_file": attr.label(allow_single_file = True),
"package_root_path": attr.string(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest renaming this to something like "strip_path_prefix" to make it more explicit what happens here. In particular, I'd read package_root_path as path to prepend (there's a request to do that as well).

In addition, perhaps it would make sense to make this a list so that multiple prefixes to strip could be provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pay attention to the fact that the order of prefixes is important. I created separate tests to show that and documented it in the wheelmaker argument and hinted that in the rule attribute description.

else:
return path

resolved_package_filename = package_filename \
Copy link
Contributor

Choose a reason for hiding this comment

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

Using backslashes for line continuaiton is frowned upon.

Can you change strip_prefix to be no-op when prefix is None and call it unconditionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -254,7 +268,9 @@ def main():
python_tag=arguments.python_tag,
abi=arguments.abi,
platform=arguments.platform,
outfile=arguments.out) as maker:
outfile=arguments.out,
package_root_path=arguments.package_root_path,
Copy link
Contributor

Choose a reason for hiding this comment

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

If I recall correctly having trailing comma on argument list is not supported on all python versions. Please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

# Always use unix path separators.
arcname = package_filename.replace(os.path.sep, '/')
arcname = resolved_package_filename.replace(os.path.sep, '/')
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this happen before strip_prefix? I'd suppose BUILD file would specify the prefix in unix style regardless of build platform, so stripping would need to use '/' separator to work reliably on windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct! Fixed.
I incorporated all the logic into one function that returns the final arcname in order to avoid another variable that can be accidentally used instead of the correct one.

@pstradomski
Copy link
Contributor

Looks good to me.

@pstradomski
Copy link
Contributor

You should be able to "Squash and merge" the change now.

@sha1n
Copy link
Contributor Author

sha1n commented Jul 9, 2019

You should be able to "Squash and merge" the change now.

@pstradomski I don't have any of the merge options, only close and comment.

@pstradomski pstradomski merged commit 3886b1a into bazel-contrib:master Jul 9, 2019
@pstradomski
Copy link
Contributor

@sha1n Weird. Merged it for you.

@brandjon
Copy link
Contributor

brandjon commented Jul 9, 2019

Merging PRs requires write permission, which Pawel has in this repository (for ownership of the rules under the experimental dir).

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.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.