8000 Add experimental support for building wheels. by pstradomski · Pull Request #159 · bazel-contrib/rules_python · GitHub
[go: up one dir, main page]

Skip to content

Add experimental support for building wheels. #159

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 14 commits into from
Apr 9, 2019
Merged

Add experimental support for building wheels. #159

merged 14 commits into from
Apr 9, 2019

Conversation

pstradomski
Copy link
Contributor

Currently only pure python wheels are supported.

This extension builds wheels directly, invoking a simple python script
that creates the zip archive in the desired format instead of using
distutils/setuptools.

This will make building platform-dependent wheels easier in the future,
as bazel will have full control on how extension code is built.

This replaces previous pull request (#128) that had bad merge history.

Currently only pure python wheels are supported.

This extension builds wheels directly, invoking a simple python script
that creates the zip archive in the desired format instead of using
distutils/setuptools.

This will make building platform-dependent wheels easier in the future,
as bazel will have full control on how extension code is built.
@pstradomski
Copy link
Contributor Author

@dsully - another attempt at the same pull request.

@pstradomski
Copy link
Contributor Author

@brandjon @laurentlb - PTAL

@c4urself
Copy link

This looks really nice, great work!

@aiuto aiuto requested a review from brandjon January 31, 2019 20:44
@lberki
Copy link
Contributor
lberki commented Feb 5, 2019

Erm. Sorry for the delay. I've asked @brandjon to take a look, since I'm somewhat unqualified at the moment to review it for I'd need to swap the problem domain into my brain..

Copy link
Contributor
@brandjon brandjon left a comment

Choose a reason for hiding this comment

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

Reviewed the example/test. Moving on to the actual binary / rule next.

@@ -0,0 +1,18 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Is the year correct for when the file was originally authored, or is it a copy/paste error? Fine to keep as-is. (Same issue for other copyright years.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. The code was written in 2018, this was indeed copy/paste error.

# Package data. We're building "example_minimal-0.0.1-py3-none-any.whl"
wheel_name="example_minimal",
version="0.0.1",
python="py3",
Copy link
Contributor

Choose a reason for hiding this comment

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

In PEP 427 this is called "python tag". Maybe we should rename the attribute to python_tag to make the connection clearer? It might also help clarify why this doesn't follow the native rules' convention of python_version = ["PY2" | "PY3"].

Along the same lines, perhaps wheel_name should be called "distribution"? I'll defer to your judgement if you think that's too obscure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed

Copy link
Contributor
@brandjon brandjon left a comment

Choose a reason for hiding this comment

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

Added comments for the rule. All that's left is the actual Python tool.

implementation = _py_wheel_impl,
attrs = {
"deps": attr.label_list(
doc = "Dependencies of this package, e.g. py_library rules",
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 clarify "Dependencies of this package" by changing it to something like "Targets to be included in this distribution", and then make it precise by saying that all runfiles of these targets and their transitive dependencies will be available.

Nit: We tend to discourage "i.e." and "e.g." in user facing documentation since they're more likely to confuse non-native English speakers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


inputs = depset(
transitive = [dep[DefaultInfo].data_runfiles.files for dep in ctx.attr.deps] +
[dep[DefaultInfo].default_runfiles.files for dep in ctx.attr.deps],
Copy link
Contributor

Choose a reason for hiding this comment

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

If your goal is only to get the Python source files, you can use dep[PyInfo].transitive_sources (see PyInfo). But using the runfiles may be more appropriate anyway since it will also include any miscellaneous data files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do make heavy use of packaged data files.

Copy link
Contributor
@brandjon brandjon left a comment

Choose a reason for hiding this comment

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

I don't really have any useful comments for the Python tool, since it's pretty deep in the weeds of the wheel file format. Let's just iterate on what was already discussed.

Thanks for this PR!

outfile=None):
self._name = name
self._version = version
self._build_tag = build_tag
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI this appears unused by the rule.

@pstradomski
Copy link
Contributor Author
pstradomski commented Mar 19, 2019 via email

@alecbz
Copy link
alecbz commented Mar 28, 2019

Question from the peanut gallery: at first glance it seems like this doesn't handle automatically the distinction between external and internal dependencies (as, e.g., pants does).

I.e., ideally, any "internal" code that's not itself published to PyPI or elsewhere should be packaged into the wheel, but code that is published elsewhere shouldn't be directly included in the wheel, and should instead just be listed as a requirement of the wheel.

Are there plans to handle this?

@pstradomski
Copy link
Contributor Author
pstradomski commented Mar 28, 2019 via email

@alecbz
Copy link
alecbz commented Mar 28, 2019

I'm not sure we should be making that choice automatically; in particular,
one might want to create multiple wheels out of a single repository with
one of them depending on the other..

Yeah, that seems like a fair concern.

Would there be a way to do some kind of automatic detection that one can opt in/out of? Perhaps combined with some way of marking any given target as "exported", to indicate that it should be referred to as a requirement and not packaged directly (I believe this is roughly how pants does it).

@pstradomski
Copy link
Contributor Author
pstradomski commented Mar 28, 2019 via email

@pstradomski
Copy link
< 10000 /div>
Contributor Author
pstradomski commented Mar 29, 2019 via email

@pstradomski
Copy link
Contributor Author

@brandjon - Anything else I should do for this pull request?

@brandjon
Copy link
Contributor
brandjon commented Apr 8, 2019

Looks good!

@pstradomski pstradomski merged commit fa6ab78 into bazel-contrib:master Apr 9, 2019
prebeta pushed a commit to prebeta/rules_python that referenced this pull request Jul 2, 2019
Add experimental support for building wheels.

Currently only pure python wheels are supported.

This extension builds wheels directly, invoking a simple python script
that creates the zip archive in the desired format instead of using
distutils/setuptools.

This will make building platform-dependent wheels easier in the future,
as bazel will have full control on how extension code is built.
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.

6 participants
< 31C1 /div>
0