-
-
Notifications
You must be signed in to change notification settings - Fork 598
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6e231e6
Add experimental support for building wheels.
pstradomski c174a10
Format skylark files.
pstradomski 923b731
Rename "wheel_name" to "distribution" and "python" to "python_tag".
pstradomski 05b6f26
Fix bad copyright notice - the code was written in 2018, not 2017.
pstradomski d8768cd
Add comments on why it's better to package py_library rather than py_…
pstradomski 52af714
Handle autogenerated __init__.py files.
pstradomski bd44d15
Add documentation; fix skylint errors and run buildifier.
pstradomski 0d8f1be
Make packages filter non-mandatory.
pstradomski 96b5955
Chane description_file to "allow_single_file".
pstradomski 0ee1949
Separate selection of files to package and actual packaging.
pstradomski d413b2e
Add examples for using py_wheel with py_library targets.
pstradomski 2a5eb7f
Added "values" restriction to python_tag attribute. Buildifier format…
pstradomski 5de53d8
Add a test that uses wheel based on py_package to check filtering beh…
pstradomski 8dc4e8b
Merge branch 'master' into master
pstradomski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2018 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) # Apache 2.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Copyright 2018 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
load("//python:python.bzl", "py_library", "py_test") | ||
load("//experimental/python:wheel.bzl", "py_package", "py_wheel") | ||
|
||
py_library( | ||
name = "main", | ||
srcs = ["main.py"], | ||
deps = [ | ||
"//experimental/examples/wheel/lib:simple_module", | ||
"//experimental/examples/wheel/lib:module_with_data", | ||
# Example dependency which is not packaged in the wheel | ||
# due to "packages" filter on py_package rule. | ||
"//examples/helloworld", | ||
], | ||
) | ||
|
||
# Package just a specific py_libraries, without their dependencies | ||
py_wheel( | ||
name = "minimal_with_py_library", | ||
# Package data. We're building "example_minimal_library-0.0.1-py3-none-any.whl" | ||
distribution = "example_minimal_library", | ||
python_tag = "py3", | ||
version = "0.0.1", | ||
deps = [ | ||
"//experimental/examples/wheel/lib:module_with_data", | ||
"//experimental/examples/wheel/lib:simple_module", | ||
], | ||
) | ||
|
||
# Use py_package to collect all transitive dependencies of a target, | ||
# selecting just the files within a specific python package. | ||
py_package( | ||
name = "example_pkg", | ||
# Only include these Python packages. | ||
packages = ["experimental.examples.wheel"], | ||
deps = [":main"], | ||
) | ||
|
||
py_wheel( | ||
name = "minimal_with_py_package", | ||
# Package data. We're building "example_minimal_package-0.0.1-py3-none-any.whl" | ||
distribution = "example_minimal_package", | ||
python_tag = "py3", | ||
version = "0.0.1", | ||
deps = [":example_pkg"], | ||
) | ||
|
||
# An example that uses all features provided by py_wheel. | ||
py_wheel( | ||
name = "customized", | ||
author = "Example Author with non-ascii characters: żółw", | ||
author_email = "example@example.com", | ||
classifiers = [ | ||
"License :: OSI Approved :: Apache Software License", | ||
"Intended Audience :: Developers", | ||
], | ||
console_scripts = { | ||
"customized_wheel": "experimental.examples.wheel.main:main", | ||
}, | ||
description_file = "README.md", | ||
# Package data. We're building "example_customized-0.0.1-py3-none-any.whl" | ||
distribution = "example_customized", | ||
homepage = "www.example.com", | ||
license = "Apache 2.0", | ||
python_tag = "py3", | ||
# Requirements embedded into the wheel metadata. | ||
requires = ["pytest"], | ||
version = "0.0.1", | ||
deps = [":example_pkg"], | ||
) | ||
|
||
py_test( | ||
name = "wheel_test", | ||
srcs = ["wheel_test.py"], | ||
data = [ | ||
":customized", | ||
":minimal_with_py_library", | ||
":minimal_with_py_package", | ||
], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a sample description of a wheel. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2018 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
load("//python:python.bzl", "py_library") | ||
|
||
py_library( | ||
name = "simple_module", | ||
srcs = ["simple_module.py"], | ||
) | ||
|
||
py_library( | ||
name = "module_with_data", | ||
srcs = ["module_with_data.py"], | ||
data = [":data.txt"], | ||
) | ||
|
||
genrule( | ||
name = "make_data", | ||
outs = ["data.txt"], | ||
cmd = "echo foo bar baz > $@", | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2018 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
def function(): | ||
return "foo" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2018 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
def function(): | ||
return "bar" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2018 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import experimental.examples.wheel.lib.module_with_data as module_with_data | ||
import experimental.examples.wheel.lib.simple_module as simple_module | ||
|
||
|
||
def function(): | ||
return "baz" | ||
|
||
|
||
def main(): | ||
print(function()) | ||
print(module_with_data.function()) | ||
print(simple_module.function()) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Copyright 2018 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import unittest | ||
import zipfile | ||
|
||
|
||
class WheelTest(unittest.TestCase): | ||
def test_py_library_wheel(self): | ||
filename = os.path.join(os.environ['TEST_SRCDIR'], | ||
'io_bazel_rules_python', 'experimental', | ||
'examples', 'wheel', | ||
'example_minimal_library-0.0.1-py3-none-any.whl') | ||
with zipfile.ZipFile(filename) as zf: | ||
self.assertEquals( | ||
zf.namelist(), | ||
['experimental/examples/wheel/lib/module_with_data.py', | ||
'experimental/examples/wheel/lib/simple_module.py', | ||
'example_minimal_library-0.0.1.dist-info/WHEEL', | ||
'example_minimal_library-0.0.1.dist-info/METADATA', | ||
'example_minimal_library-0.0.1.dist-info/RECORD']) | ||
|
||
def test_py_package_wheel(self): | ||
filename = os.path.join(os.environ['TEST_SRCDIR'], | ||
'io_bazel_rules_python', 'experimental', | ||
'examples', 'wheel', | ||
'example_minimal_package-0.0.1-py3-none-any.whl') | ||
with zipfile.ZipFile(filename) as zf: | ||
self.assertEquals( | ||
zf.namelist(), | ||
['experimental/examples/wheel/lib/data.txt', | ||
'experimental/examples/wheel/lib/module_with_data.py', | ||
'experimental/examples/wheel/lib/simple_module.py', | ||
'experimental/examples/wheel/main.py', | ||
'example_minimal_package-0.0.1.dist-info/WHEEL', | ||
'example_minimal_package-0.0.1.dist-info/METADATA', | ||
'example_minimal_package-0.0.1.dist-info/RECORD']) | ||
|
||
def test_customized_wheel(self): | ||
filename = os.path.join(os.environ['TEST_SRCDIR'], | ||
'io_bazel_rules_python', 'experimental', | ||
'examples', 'wheel', | ||
'example_customized-0.0.1-py3-none-any.whl') | ||
with zipfile.ZipFile(filename) as zf: | ||
self.assertEquals( | ||
zf.namelist(), | ||
['experimental/examples/wheel/lib/data.txt', | ||
'experimental/examples/wheel/lib/module_with_data.py', | ||
'experimental/examples/wheel/lib/simple_module.py', | ||
'experimental/examples/wheel/main.py', | ||
'example_customized-0.0.1.dist-info/WHEEL', | ||
'example_customized-0.0.1.dist-info/METADATA', | ||
'example_customized-0.0.1.dist-info/entry_points.txt', | ||
'example_customized-0.0.1.dist-info/RECORD']) | ||
record_contents = zf.read( | ||
'example_customized-0.0.1.dist-info/RECORD') | ||
wheel_contents = zf.read( | ||
'example_customized-0.0.1.dist-info/WHEEL') | ||
metadata_contents = zf.read( | ||
'example_customized-0.0.1.dist-info/METADATA') | ||
# The entries are guaranteed to be sorted. | ||
self.assertEquals(record_contents, b"""\ | ||
example_customized-0.0.1.dist-info/METADATA,sha256=TeeEmokHE2NWjkaMcVJuSAq4_AXUoIad2-SLuquRmbg,372 | ||
example_customized-0.0.1.dist-info/RECORD,, | ||
example_customized-0.0.1.dist-info/WHEEL,sha256=F01lGfVCzcXUzzQHzUkBmXAcu_TXd5zqMLrvrspncJo,85 | ||
example_customized-0.0.1.dist-info/entry_points.txt,sha256=olLJ8FK88aft2pcdj4BD05F8Xyz83Mo51I93tRGT2Yk,74 | ||
experimental/examples/wheel/lib/data.txt,sha256=9vJKEdfLu8bZRArKLroPZJh1XKkK3qFMXiM79MBL2Sg,12 | ||
experimental/examples/wheel/lib/module_with_data.py,sha256=K_IGAq_CHcZX0HUyINpD1hqSKIEdCn58d9E9nhWF2EA,636 | ||
experimental/examples/wheel/lib/simple_module.py,sha256=72-91Dm6NB_jw-7wYQt7shzdwvk5RB0LujIah8g7kr8,636 | ||
experimental/examples/wheel/main.py,sha256=E0xCyiPg6fCo4IrFmqo_tqpNGtk1iCewobqD0_KlFd0,935 | ||
""") | ||
self.assertEquals(wheel_contents, b"""\ | ||
Wheel-Version: 1.0 | ||
Generator: wheelmaker 1.0 | ||
Root-Is-Purelib: true | ||
Tag: py3-none-any | ||
""") | ||
self.assertEquals(metadata_contents, b"""\ | ||
Metadata-Version: 2.1 | ||
Name: example_customized | ||
Version: 0.0.1 | ||
Author: Example Author with non-ascii characters: \xc5\xbc\xc3\xb3\xc5\x82w | ||
Author-email: example@example.com | ||
Home-page: www.example.com | ||
License: Apache 2.0 | ||
Classifier: License :: OSI Approved :: Apache Software License | ||
Classifier: Intended Audience :: Developers | ||
Requires-Dist: pytest | ||
|
||
This is a sample description of a wheel. | ||
""") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2018 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
exports_files(["wheel.bzl"]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.