Skip to content
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
7 changes: 6 additions & 1 deletion pycross/private/lock_resolver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,12 @@ def resolve(
raw_pins = lock_model_data.get("pins", {})
pins = {}
for k, v in raw_pins.items():
name = parse_package_key(k).name
parts = parse_package_key(k)

if parts.extra:
name = "{}[{}]".format(parts.name, parts.extra)
else:
name = parts.name
if type(v) == "string":
pins[name] = {"": v}
else:
Expand Down
9 changes: 6 additions & 3 deletions pycross/private/thin_package_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _requirements_bzl(rctx, pins, packages):
]
for pin in sorted(pins.keys()):
pin_target_dict = pins[pin]
pin_parts = parse_package_key(pin)

# Check if ANY variant of this pin is platform-specific.
is_conditional = False
Expand All @@ -55,11 +56,13 @@ def _requirements_bzl(rctx, pins, packages):
is_conditional = True
break

if is_conditional:
us_pin = underscore_name(pin)
us_pin = underscore_name(pin_parts.name)
if pin_parts.extra:
lines.append(' "@@{repo_name}//{pin}:[{extra}]",'.format(repo_name = rctx.name, pin = us_pin, extra = pin_parts.extra))
elif is_conditional:
lines.append(' "@@{repo_name}//{pin}:{maybe}",'.format(repo_name = rctx.name, pin = us_pin, maybe = _safe_name(us_pin, "maybe")))
else:
lines.append(' "@@{repo_name}//{pin}",'.format(repo_name = rctx.name, pin = underscore_name(pin)))
lines.append(' "@@{repo_name}//{pin}",'.format(repo_name = rctx.name, pin = us_pin))
lines.append("]")
return "\n".join(lines) + "\n"

Expand Down
23 changes: 23 additions & 0 deletions tests/unit/test_lock_resolver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,28 @@ def _test_synthesized_deps(name):
util.helper_target(native.filegroup, name = name + "_subject", srcs = [])
analysis_test(name = name, target = name + "_subject", impl = _test_synthesized_deps_impl)

# buildifier: disable=unused-variable
def _test_multi_extra_pins_impl(env, target):
lock_model_data = {
"packages": {
"[email protected]": _make_pkg("foo", "1.0", [_make_file("foo-1.0.tar.gz")]),
},
"pins": {
"foo[bar]": "foo[bar]@1.0",
"foo[baz]": "foo[baz]@1.0",
},
}

res = resolve(lock_model_data)

# Both extras survive as distinct pins rather than collapsing to a single
# "foo" entry, which would silently drop all but the last extra.
env.expect.that_collection(res.pins.keys()).contains_at_least(["foo[bar]", "foo[baz]"])

def _test_multi_extra_pins(name):
util.helper_target(native.filegroup, name = name + "_subject", srcs = [])
analysis_test(name = name, target = name + "_subject", impl = _test_multi_extra_pins_impl)

# buildifier: disable=unused-variable
def _test_cycle_two_nodes_impl(env, target):
lock_model_data = {
Expand Down Expand Up @@ -2100,6 +2122,7 @@ def lock_resolver_test_suite(name):
_test_create_transitive_aliases_with_extras,
_test_extra_build_tools_override,
_test_synthesized_deps,
_test_multi_extra_pins,
_test_cycle_two_nodes,
_test_cycle_via_extra,
_test_cycle_three_nodes,
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/test_thin_package_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,32 @@ def _test_requirements_bzl_all_unconditional(name):
util.helper_target(native.filegroup, name = name + "_subject", srcs = [])
analysis_test(name = name, target = name + "_subject", impl = _test_requirements_bzl_all_unconditional_impl)

# ── Test: _requirements_bzl with extra-bearing pins ────────────────

# buildifier: disable=unused-variable
def _test_requirements_bzl_extra_pins_impl(env, target):
"""Extra-bearing pins produce distinct :[extra] entries in all_requirements."""
mock_rctx = struct(name = "my_repo")
pins = {
"foo[bar]": {"": "foo[bar]@1.0"},
"foo[baz]": {"": "foo[baz]@1.0"},
}
packages = {
"[email protected]": {
"wheel_candidates": [{"filename": "foo-1.0-py3-none-any.whl"}],
"sdist_file": {"key": "foo_sdist"},
},
}
res = requirements_bzl_for_testing(mock_rctx, pins, packages)

# Both extras should appear as separate entries.
env.expect.that_bool("@@my_repo//foo:[bar]" in res).equals(True)
env.expect.that_bool("@@my_repo//foo:[baz]" in res).equals(True)

def _test_requirements_bzl_extra_pins(name):
util.helper_target(native.filegroup, name = name + "_subject", srcs = [])
analysis_test(name = name, target = name + "_subject", impl = _test_requirements_bzl_extra_pins_impl)

# ── Test suite ─────────────────────────────────────────────────────

def thin_package_repo_test_suite(name):
Expand All @@ -450,5 +476,6 @@ def thin_package_repo_test_suite(name):
_test_is_platform_specific,
_test_requirements_bzl_maybe_aliases,
_test_requirements_bzl_all_unconditional,
_test_requirements_bzl_extra_pins,
],
)
Loading