Skip to content
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

pycross: Rename pycross_wheel_library and make it work #1413

Merged
merged 6 commits into from
Sep 27, 2023
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
13 changes: 12 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ python_register_multi_toolchains(
python_versions = MINOR_MAPPING.values(),
)

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

# Used for Bazel CI
http_archive(
Expand Down Expand Up @@ -86,3 +86,14 @@ pip_parse(
load("@publish_deps//:requirements.bzl", "install_deps")

install_deps()

# This wheel is purely here to validate the wheel extraction code. It's not
# intended for anything else.
http_file(
name = "wheel_for_testing",
downloaded_file_path = "numpy-1.25.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
sha256 = "0d60fbae8e0019865fc4784745814cff1c421df5afee233db6d88ab4f14655a2",
urls = [
"https://files.pythonhosted.org/packages/50/67/3e966d99a07d60a21a21d7ec016e9e4c2642a86fea251ec68677daf71d4d/numpy-1.25.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
],
)
1 change: 1 addition & 0 deletions python/pip_install/tools/wheel_installer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ py_library(
"wheel.py",
"wheel_installer.py",
],
visibility = ["//third_party/rules_pycross/pycross/private:__subpackages__"],
deps = [
requirement("installer"),
requirement("pip"),
Expand Down
34 changes: 34 additions & 0 deletions tests/pycross/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2023 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.

load("//python:defs.bzl", "py_test")
load("//third_party/rules_pycross/pycross/private:wheel_library.bzl", "py_wheel_library") # buildifier: disable=bzl-visibility
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suppressing the buildifier warning here because the test is outside of the directory. This will get resolved once the code moves into the main part of the source tree.

https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#bzl-visibility


py_wheel_library(
name = "extracted_wheel_for_testing",
wheel = "@wheel_for_testing//file",
)

py_test(
name = "py_wheel_library_test",
srcs = [
"py_wheel_library_test.py",
],
data = [
":extracted_wheel_for_testing",
],
deps = [
"//python/runfiles",
],
)
48 changes: 48 additions & 0 deletions tests/pycross/py_wheel_library_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2023 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 unittest
from pathlib import Path

from python.runfiles import runfiles

RUNFILES = runfiles.Create()


class TestPyWheelLibrary(unittest.TestCase):
def setUp(self):
self.extraction_dir = Path(
RUNFILES.Rlocation(
"rules_python/tests/pycross/extracted_wheel_for_testing"
)
)
self.assertTrue(self.extraction_dir.exists(), self.extraction_dir)
self.assertTrue(self.extraction_dir.is_dir(), self.extraction_dir)

def test_file_presence(self):
"""Validate that the basic file layout looks good."""
for path in (
"bin/f2py",
"site-packages/numpy.libs/libgfortran-daac5196.so.5.0.0",
"site-packages/numpy/dtypes.py",
"site-packages/numpy/core/_umath_tests.cpython-311-aarch64-linux-gnu.so",
):
print(self.extraction_dir / path)
self.assertTrue(
(self.extraction_dir / path).exists(), f"{path} does not exist"
)


if __name__ == "__main__":
unittest.main()
14 changes: 14 additions & 0 deletions third_party/rules_pycross/pycross/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 Jeremy Volkman. All rights reserved.
# Copyright 2023 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.
6 changes: 3 additions & 3 deletions third_party/rules_pycross/pycross/private/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Pycross providers."""
"""Python providers."""

PycrossWheelInfo = provider(
PyWheelInfo = provider(
doc = "Information about a Python wheel.",
fields = {
"name_file": "File: A file containing the canonical name of the wheel.",
"wheel_file": "File: The wheel file itself.",
},
)

PycrossTargetEnvironmentInfo = provider(
PyTargetEnvironmentInfo = provider(
doc = "A target environment description.",
fields = {
"file": "The JSON file containing target environment information.",
Expand Down
33 changes: 3 additions & 30 deletions third_party/rules_pycross/pycross/private/tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")

package(default_visibility = ["//visibility:private"])

py_library(
name = "namespace_pkgs",
srcs = [
"namespace_pkgs.py",
],
)

py_test(
name = "namespace_pkgs_test",
size = "small",
srcs = [
"namespace_pkgs_test.py",
],
tags = [
"unit",
# TODO(philsc): Make this work.
"manual",
],
deps = [
":namespace_pkgs",
],
)
load("//python:defs.bzl", "py_binary")

py_binary(
name = "wheel_installer",
srcs = ["wheel_installer.py"],
visibility = ["//visibility:public"],
deps = [
":namespace_pkgs",
# TODO(philsc): Make this work with what's available in rules_python.
#"@rules_pycross_pypi_deps_absl_py//:pkg",
#"@rules_pycross_pypi_deps_installer//:pkg",
"//python/pip_install/tools/wheel_installer:lib",
"@pypi__installer//:lib",
],
)
109 changes: 0 additions & 109 deletions third_party/rules_pycross/pycross/private/tools/namespace_pkgs.py

This file was deleted.

Loading