Skip to content

Commit

Permalink
Add all_whl_requirements similar to rules_python (#93)
Browse files Browse the repository at this point in the history
This is needed to generated the gazelle_manifest.yaml
  • Loading branch information
ewianda authored Apr 29, 2024
1 parent 9f7c160 commit 4d18870
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions e2e/bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ exports_files([
"test_regex.py",
"test_zstandard.py",
"testlib.bzl",
"test_all_whl_requirements.py",
])
12 changes: 11 additions & 1 deletion e2e/bzlmod/pdm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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")

Expand Down Expand Up @@ -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",
)
12 changes: 12 additions & 0 deletions e2e/bzlmod/test_all_whl_requirements.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 8 additions & 0 deletions pycross/private/package_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 4d18870

Please sign in to comment.