Skip to content

Commit

Permalink
Merge branch 'master' into groodt-pip-21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
groodt committed Feb 2, 2021
2 parents ca981a7 + c7e068d commit b12e6e8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ http_archive(
)
```

If you want to use the pip packaging rules, also add:

```python
load("@rules_python//python:pip.bzl", "pip_repositories")
pip_repositories()
```

To depend on a particular unreleased version (not recommended), you can do:

```python
Expand Down
31 changes: 31 additions & 0 deletions experimental/examples/wheel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ py_library(
],
)

py_library(
name = "main_with_gen_data",
srcs = ["main.py"],
data = [
":gen_dir",
],
)

genrule(
name = "gen_dir",
outs = ["someDir"],
cmd = "mkdir -p $@ && touch $@/foo.py",
)

# Package just a specific py_libraries, without their dependencies
py_wheel(
name = "minimal_with_py_library",
Expand All @@ -53,6 +67,12 @@ py_package(
deps = [":main"],
)

py_package(
name = "example_pkg_with_data",
packages = ["experimental.examples.wheel"],
deps = [":main_with_gen_data"]
)

py_wheel(
name = "minimal_with_py_package",
# Package data. We're building "example_minimal_package-0.0.1-py3-none-any.whl"
Expand Down Expand Up @@ -146,6 +166,16 @@ py_wheel(
],
)

py_wheel(
name = "use_genrule_with_dir_in_outs",
distribution = "use_genrule_with_dir_in_outs",
python_tag = "py3",
version = "0.0.1",
deps = [
":example_pkg_with_data"
]
)

py_wheel(
name = "python_abi3_binary_wheel",
abi = "abi3",
Expand All @@ -168,5 +198,6 @@ py_test(
":minimal_with_py_package",
":python_abi3_binary_wheel",
":python_requires_in_a_package",
":use_genrule_with_dir_in_outs",
],
)
15 changes: 15 additions & 0 deletions experimental/examples/wheel/wheel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ def test_python_abi3_binary_wheel(self):
""",
)

def test_genrule_creates_directory_and_is_included_in_wheel(self):
filename = os.path.join(os.environ['TEST_SRCDIR'],
'rules_python', 'experimental',
'examples', 'wheel',
'use_genrule_with_dir_in_outs-0.0.1-py3-none-any.whl')

with zipfile.ZipFile(filename) as zf:
self.assertEquals(
zf.namelist(),
['experimental/examples/wheel/main.py',
'experimental/examples/wheel/someDir/foo.py',
'use_genrule_with_dir_in_outs-0.0.1.dist-info/WHEEL',
'use_genrule_with_dir_in_outs-0.0.1.dist-info/METADATA',
'use_genrule_with_dir_in_outs-0.0.1.dist-info/RECORD'])


if __name__ == '__main__':
unittest.main()
7 changes: 7 additions & 0 deletions experimental/tools/wheelmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ def arcname_from(name):

return normalized_arcname

if os.path.isdir(real_filename):
directory_contents = os.listdir(real_filename)
for file_ in directory_contents:
self.add_file("{}/{}".format(package_filename, file_),
"{}/{}".format(real_filename, file_))
return

arcname = arcname_from(package_filename)

self._zipfile.write(real_filename, arcname=arcname)
Expand Down

0 comments on commit b12e6e8

Please sign in to comment.