Skip to content

Commit 5f59c06

Browse files
committed
Rename pycross_wheel_library to py_wheel_library and make it work
This patch changes the name of the rule to reflect the fact that it's not exactly the same as the one in rules_pycross. I also took this opportunity to delete the superfluous `namespace_pkgs.py` library (plus test) since we have a nearly identical version already in the main repo. I added a test to validate that the rule functions at a basic level. References: #1360
1 parent 4250824 commit 5f59c06

File tree

10 files changed

+134
-336
lines changed

10 files changed

+134
-336
lines changed

WORKSPACE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,16 @@ pip_parse(
8686
load("@publish_deps//:requirements.bzl", "install_deps")
8787

8888
install_deps()
89+
90+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
91+
92+
# This wheel is purely here to validate the wheel extraction code. It's not
93+
# intended for anything else.
94+
http_file(
95+
name = "wheel_for_testing",
96+
urls = [
97+
"https://files.pythonhosted.org/packages/50/67/3e966d99a07d60a21a21d7ec016e9e4c2642a86fea251ec68677daf71d4d/numpy-1.25.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
98+
],
99+
downloaded_file_path = "numpy-1.25.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
100+
sha256 = "0d60fbae8e0019865fc4784745814cff1c421df5afee233db6d88ab4f14655a2",
101+
)

python/pip_install/tools/wheel_installer/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ py_library(
1414
requirement("pip"),
1515
requirement("setuptools"),
1616
],
17+
visibility = ["//third_party/rules_pycross/pycross/private:__subpackages__"],
1718
)
1819

1920
py_binary(
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2023 Jeremy Volkman. All rights reserved.
2+
# Copyright 2023 The Bazel Authors. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
load(":wheel_library.bzl", "py_wheel_library")
17+
load("//python:defs.bzl", "py_test")
18+
19+
py_wheel_library(
20+
name = "extracted_wheel_for_testing",
21+
wheel = "@wheel_for_testing//file",
22+
)
23+
24+
py_test(
25+
name = "py_wheel_library_test",
26+
srcs = [
27+
"py_wheel_library_test.py",
28+
],
29+
deps = [
30+
"//python/runfiles",
31+
],
32+
data = [
33+
":extracted_wheel_for_testing",
34+
],
35+
)

third_party/rules_pycross/pycross/private/providers.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
"""Pycross providers."""
16+
"""Python providers."""
1717

18-
PycrossWheelInfo = provider(
18+
PyWheelInfo = provider(
1919
doc = "Information about a Python wheel.",
2020
fields = {
2121
"name_file": "File: A file containing the canonical name of the wheel.",
2222
"wheel_file": "File: The wheel file itself.",
2323
},
2424
)
2525

26-
PycrossTargetEnvironmentInfo = provider(
26+
PyTargetEnvironmentInfo = provider(
2727
doc = "A target environment description.",
2828
fields = {
2929
"file": "The JSON file containing target environment information.",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
from pathlib import Path
17+
18+
from rules_python.python.runfiles import runfiles
19+
20+
RUNFILES = runfiles.Create()
21+
22+
23+
class TestPyWheelLibrary(unittest.TestCase):
24+
def setUp(self):
25+
self.extraction_dir = Path(
26+
RUNFILES.Rlocation(
27+
"rules_python/third_party/rules_pycross/pycross/private/extracted_wheel_for_testing"
28+
)
29+
)
30+
self.assertTrue(self.extraction_dir.exists(), self.extraction_dir)
31+
self.assertTrue(self.extraction_dir.is_dir(), self.extraction_dir)
32+
33+
def test_file_presence(self):
34+
"""Validate that the basic file layout looks good."""
35+
for path in (
36+
"bin/f2py",
37+
"site-packages/numpy.libs/libgfortran-daac5196.so.5.0.0",
38+
"site-packages/numpy/dtypes.py",
39+
"site-packages/numpy/core/_umath_tests.cpython-311-aarch64-linux-gnu.so",
40+
):
41+
print(self.extraction_dir / path)
42+
self.assertTrue(
43+
(self.extraction_dir / path).exists(), f"{path} does not exist"
44+
)
45+
46+
47+
if __name__ == "__main__":
48+
unittest.main()

third_party/rules_pycross/pycross/private/tools/BUILD.bazel

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,14 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
17-
18-
package(default_visibility = ["//visibility:private"])
19-
20-
py_library(
21-
name = "namespace_pkgs",
22-
srcs = [
23-
"namespace_pkgs.py",
24-
],
25-
)
26-
27-
py_test(
28-
name = "namespace_pkgs_test",
29-
size = "small",
30-
srcs = [
31-
"namespace_pkgs_test.py",
32-
],
33-
tags = [
34-
"unit",
35-
# TODO(philsc): Make this work.
36-
"manual",
37-
],
38-
deps = [
39-
":namespace_pkgs",
40-
],
41-
)
16+
load("//python:defs.bzl", "py_binary")
4217

4318
py_binary(
4419
name = "wheel_installer",
4520
srcs = ["wheel_installer.py"],
4621
visibility = ["//visibility:public"],
4722
deps = [
48-
":namespace_pkgs",
49-
# TODO(philsc): Make this work with what's available in rules_python.
50-
#"@rules_pycross_pypi_deps_absl_py//:pkg",
51-
#"@rules_pycross_pypi_deps_installer//:pkg",
23+
"//python/pip_install/tools/wheel_installer:lib",
24+
"@pypi__installer//:lib",
5225
],
5326
)

third_party/rules_pycross/pycross/private/tools/namespace_pkgs.py

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)