Skip to content

Commit f4b62fc

Browse files
authored
pycross: Rename pycross_wheel_library and make it work (#1413)
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 6726875 commit f4b62fc

File tree

11 files changed

+147
-338
lines changed

11 files changed

+147
-338
lines changed

WORKSPACE

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ python_register_multi_toolchains(
3434
python_versions = MINOR_MAPPING.values(),
3535
)
3636

37-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
37+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
3838

3939
# Used for Bazel CI
4040
http_archive(
@@ -86,3 +86,14 @@ pip_parse(
8686
load("@publish_deps//:requirements.bzl", "install_deps")
8787

8888
install_deps()
89+
90+
# This wheel is purely here to validate the wheel extraction code. It's not
91+
# intended for anything else.
92+
http_file(
93+
name = "wheel_for_testing",
94+
downloaded_file_path = "numpy-1.25.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
95+
sha256 = "0d60fbae8e0019865fc4784745814cff1c421df5afee233db6d88ab4f14655a2",
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+
)

python/pip_install/tools/wheel_installer/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ py_library(
99
"wheel.py",
1010
"wheel_installer.py",
1111
],
12+
visibility = ["//third_party/rules_pycross/pycross/private:__subpackages__"],
1213
deps = [
1314
requirement("installer"),
1415
requirement("pip"),

tests/pycross/BUILD.bazel

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
load("//python:defs.bzl", "py_test")
16+
load("//third_party/rules_pycross/pycross/private:wheel_library.bzl", "py_wheel_library") # buildifier: disable=bzl-visibility
17+
18+
py_wheel_library(
19+
name = "extracted_wheel_for_testing",
20+
wheel = "@wheel_for_testing//file",
21+
)
22+
23+
py_test(
24+
name = "py_wheel_library_test",
25+
srcs = [
26+
"py_wheel_library_test.py",
27+
],
28+
data = [
29+
":extracted_wheel_for_testing",
30+
],
31+
deps = [
32+
"//python/runfiles",
33+
],
34+
)
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 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/tests/pycross/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()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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.

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.",

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)