1- load ("@aspect_rules_py//py:defs.bzl" , "py_binary" , "py_pex_binary" , "py_test" )
1+ load ("@aspect_rules_py//py:defs.bzl" , "py_binary" , "py_pex_binary" , "py_test" , "py_unpacked_wheel" )
22
33py_binary (
44 name = "app" ,
@@ -27,6 +27,63 @@ py_pex_binary(
2727 python_interpreter_constraints = [],
2828)
2929
30+ # Default constraints are stamped from the binary's version (3.13), not the pex
31+ # rule's toolchain (workspace default 3.11).
32+ py_pex_binary (
33+ name = "app_mismatch_constrained_pex" ,
34+ binary = ":app_mismatch" ,
35+ )
36+
37+ # A wheel reached only through a `filegroup(srcs = [...])` data wrapper. The
38+ # closure aspect walks data → filegroup but not the filegroup's `srcs`, so the
39+ # wheel must still be recognized as a distribution (--dependency) rather than
40+ # shipped as loose --source content.
41+ #
42+ # A hand-built wheel (not a uv-hub wheel): its py_unpacked_wheel carries no
43+ # dep_group constraint, so it survives the data edge's dep_group reset — a uv
44+ # wheel would be pruned there before the packaging logic is even exercised.
45+ genrule (
46+ name = "distfg_whl" ,
47+ srcs = [
48+ "wheel/distfg/__init__.py" ,
49+ "wheel/METADATA" ,
50+ ],
51+ outs = ["distfg-1.0-py3-none-any.whl" ],
52+ cmd = " " .join ([
53+ "$(execpath @bazel_tools//tools/zip:zipper) c $@" ,
54+ "distfg/__init__.py=$(execpath wheel/distfg/__init__.py)" ,
55+ "distfg-1.0.dist-info/METADATA=$(execpath wheel/METADATA)" ,
56+ ]),
57+ tools = ["@bazel_tools//tools/zip:zipper" ],
58+ )
59+
60+ py_unpacked_wheel (
61+ name = "distfg" ,
62+ src = ":distfg-1.0-py3-none-any.whl" ,
63+ top_levels = [
64+ "distfg" ,
65+ "distfg-1.0.dist-info" ,
66+ ],
67+ )
68+
69+ filegroup (
70+ name = "wrapped_wheel" ,
71+ srcs = [":distfg" ],
72+ )
73+
74+ py_binary (
75+ name = "app_wrapped_wheel" ,
76+ srcs = ["app.py" ],
77+ data = [":wrapped_wheel" ],
78+ main = "app.py" ,
79+ )
80+
81+ py_pex_binary (
82+ name = "app_wrapped_wheel_pex" ,
83+ binary = ":app_wrapped_wheel" ,
84+ python_interpreter_constraints = [],
85+ )
86+
3087py_test (
3188 name = "test_pex_excludes_interpreter" ,
3289 srcs = ["test_pex_excludes_interpreter.py" ],
@@ -36,3 +93,17 @@ py_test(
3693 ],
3794 main = "test_pex_excludes_interpreter.py" ,
3895)
96+
97+ py_test (
98+ name = "test_pex_constraint_version" ,
99+ srcs = ["test_pex_constraint_version.py" ],
100+ data = [":app_mismatch_constrained_pex" ],
101+ main = "test_pex_constraint_version.py" ,
102+ )
103+
104+ py_test (
105+ name = "test_pex_wheel_under_filegroup" ,
106+ srcs = ["test_pex_wheel_under_filegroup.py" ],
107+ data = [":app_wrapped_wheel_pex" ],
108+ main = "test_pex_wheel_under_filegroup.py" ,
109+ )
0 commit comments