Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Copy Markdown
Contributor

@hrfuller hrfuller Jan 20, 2021

Choose a reason for hiding this comment

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

I'd be curious to know your rationale for doing this here instead of in the starlark rules here as @aaliddell discussed in the comments.

Edit: I realized the starlark api doesn't give a way to iterate through a directories children, except with Args.add_all which isn't useful here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was about to say, I couldn't do it there.

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