From 4d1887099e4b5b32ac1864a4fcee1184468d7b3b Mon Sep 17 00:00:00 2001 From: "Elvis M. Wianda" <7077790+ewianda@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:26:36 -0400 Subject: [PATCH] Add all_whl_requirements similar to rules_python (#93) This is needed to generated the gazelle_manifest.yaml --- e2e/bzlmod/BUILD.bazel | 1 + e2e/bzlmod/pdm/BUILD.bazel | 12 +++++++++++- e2e/bzlmod/test_all_whl_requirements.py | 12 ++++++++++++ pycross/private/package_repo.bzl | 8 ++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 e2e/bzlmod/test_all_whl_requirements.py diff --git a/e2e/bzlmod/BUILD.bazel b/e2e/bzlmod/BUILD.bazel index 5c0e9941..1d9932a3 100644 --- a/e2e/bzlmod/BUILD.bazel +++ b/e2e/bzlmod/BUILD.bazel @@ -9,4 +9,5 @@ exports_files([ "test_regex.py", "test_zstandard.py", "testlib.bzl", + "test_all_whl_requirements.py", ]) diff --git a/e2e/bzlmod/pdm/BUILD.bazel b/e2e/bzlmod/pdm/BUILD.bazel index 80f7664f..eb2afec8 100644 --- a/e2e/bzlmod/pdm/BUILD.bazel +++ b/e2e/bzlmod/pdm/BUILD.bazel @@ -1,5 +1,5 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file") -load("@pdm//:requirements.bzl", "all_requirements", "requirement") +load("@pdm//:requirements.bzl", "all_requirements", "all_whl_requirements", "requirement") load("@rules_pycross//pycross:defs.bzl", "pycross_wheel_build") load("@rules_python//python:defs.bzl", "py_test") @@ -91,3 +91,13 @@ py_test( main = "test_regex.py", deps = all_requirements, ) + +# Test using `all_whl_requirements` +py_test( + name = "test_all_whl_requirements", + srcs = ["//:test_all_whl_requirements.py"], + env = { + "ALL_WHL_REQUIREMENTS": ",".join(all_whl_requirements), + }, + main = "test_all_whl_requirements.py", +) diff --git a/e2e/bzlmod/test_all_whl_requirements.py b/e2e/bzlmod/test_all_whl_requirements.py new file mode 100644 index 00000000..bdb4c40b --- /dev/null +++ b/e2e/bzlmod/test_all_whl_requirements.py @@ -0,0 +1,12 @@ +import os +import unittest + + +class TestAllWhlRequirements(unittest.TestCase): + def test_all_whl_requirements(self): + self.maxDiff = None + self.assertNotEqual(os.environ["ALL_WHL_REQUIREMENTS"], "") + + +if __name__ == "__main__": + unittest.main() diff --git a/pycross/private/package_repo.bzl b/pycross/private/package_repo.bzl index 37ffab2c..e835d4af 100644 --- a/pycross/private/package_repo.bzl +++ b/pycross/private/package_repo.bzl @@ -147,6 +147,14 @@ def _requirements_bzl(rctx, pins): for pin in pins: lines.append(' "@@{repo_name}//:{pin}",'.format(repo_name = rctx.name, pin = pin)) lines.append("]") + lines.extend([ + "", + "# All wheel requirements", + "all_whl_requirements = [", + ]) + for pin in pins.values(): + lines.append(' "@@{repo_name}//_wheel:{pin}",'.format(repo_name = rctx.name, pin = pin)) + lines.append("]") return "\n".join(lines) + "\n"