|
17 | 17 | load("@rules_testing//lib:test_suite.bzl", "test_suite")
|
18 | 18 | load("//python/private/pypi:parse_requirements.bzl", "parse_requirements", "select_requirement") # buildifier: disable=bzl-visibility
|
19 | 19 | load("//python/private/pypi:pep508_env.bzl", pep508_env = "env") # buildifier: disable=bzl-visibility
|
| 20 | +load("//python/private/pypi:evaluate_markers.bzl", "evaluate_markers") # buildifier: disable=bzl-visibility |
20 | 21 |
|
21 | 22 | def _mock_ctx():
|
22 | 23 | testdata = {
|
@@ -65,6 +66,12 @@ foo[extra]==0.0.1 --hash=sha256:deadbeef
|
65 | 66 | "requirements_marker": """\
|
66 | 67 | foo[extra]==0.0.1 ;marker --hash=sha256:deadbeef
|
67 | 68 | bar==0.0.1 --hash=sha256:deadbeef
|
| 69 | +""", |
| 70 | + "requirements_multi_version": """\ |
| 71 | +foo==0.0.1; python_full_version < '3.10.0' \ |
| 72 | + --hash=sha256:deadbeef |
| 73 | +foo==0.0.2; python_full_version >= '3.10.0' \ |
| 74 | + --hash=sha256:deadb11f |
68 | 75 | """,
|
69 | 76 | "requirements_optional_hash": """
|
70 | 77 | foo==0.0.4 @ https://example.org/foo-0.0.4.whl
|
@@ -587,10 +594,9 @@ def _test_overlapping_shas_with_index_results(env):
|
587 | 594 |
|
588 | 595 | env.expect.that_collection(got).contains_exactly([
|
589 | 596 | struct(
|
590 |
| - name = "foo", |
591 | 597 | is_exposed = True,
|
592 |
| - # TODO @aignas 2025-05-25: how do we rename this? |
593 | 598 | is_multiple_versions = True,
|
| 599 | + name = "foo", |
594 | 600 | srcs = [
|
595 | 601 | struct(
|
596 | 602 | distribution = "foo",
|
@@ -618,6 +624,99 @@ def _test_overlapping_shas_with_index_results(env):
|
618 | 624 |
|
619 | 625 | _tests.append(_test_overlapping_shas_with_index_results)
|
620 | 626 |
|
| 627 | +def _test_get_index_urls_different_versions(env): |
| 628 | + got = parse_requirements( |
| 629 | + ctx = _mock_ctx(), |
| 630 | + requirements_by_platform = { |
| 631 | + "requirements_multi_version": [ |
| 632 | + "cp39_linux_x86_64", |
| 633 | + "cp310_linux_x86_64", |
| 634 | + ], |
| 635 | + }, |
| 636 | + platforms = { |
| 637 | + "cp310_linux_x86_64": struct( |
| 638 | + env = pep508_env( |
| 639 | + python_version = "3.9.0", |
| 640 | + os = "linux", |
| 641 | + arch = "x86_64", |
| 642 | + ), |
| 643 | + whl_abi_tags = ["none"], |
| 644 | + whl_platform_tags = ["any"], |
| 645 | + ), |
| 646 | + "cp39_linux_x86_64": struct( |
| 647 | + env = pep508_env( |
| 648 | + python_version = "3.9.0", |
| 649 | + os = "linux", |
| 650 | + arch = "x86_64", |
| 651 | + ), |
| 652 | + whl_abi_tags = ["none"], |
| 653 | + whl_platform_tags = ["any"], |
| 654 | + ), |
| 655 | + }, |
| 656 | + get_index_urls = lambda _, __: { |
| 657 | + "foo": struct( |
| 658 | + sdists = {}, |
| 659 | + whls = { |
| 660 | + "deadb11f": struct( |
| 661 | + url = "super2", |
| 662 | + sha256 = "deadb11f", |
| 663 | + filename = "foo-0.0.2-py3-none-any.whl", |
| 664 | + yanked = False, |
| 665 | + ), |
| 666 | + "deadbaaf": struct( |
| 667 | + url = "super2", |
| 668 | + sha256 = "deadbaaf", |
| 669 | + filename = "foo-0.0.1-py3-none-any.whl", |
| 670 | + yanked = False, |
| 671 | + ), |
| 672 | + }, |
| 673 | + ), |
| 674 | + }, |
| 675 | + evaluate_markers = lambda _, requirements: evaluate_markers( |
| 676 | + requirements = requirements, |
| 677 | + platforms = { |
| 678 | + "cp39_linux_x86_64": struct( |
| 679 | + env = {"python_full_version": "3.9.0"}, |
| 680 | + ), |
| 681 | + "cp310_linux_x86_64": struct( |
| 682 | + env = {"python_full_version": "3.10.0"}, |
| 683 | + ), |
| 684 | + }, |
| 685 | + ) |
| 686 | + ) |
| 687 | + |
| 688 | + env.expect.that_collection(got).contains_exactly([ |
| 689 | + struct( |
| 690 | + is_exposed = True, |
| 691 | + is_multiple_versions = True, |
| 692 | + name = "foo", |
| 693 | + srcs = [ |
| 694 | + struct( |
| 695 | + distribution = "foo", |
| 696 | + extra_pip_args = [], |
| 697 | + filename = "", |
| 698 | + requirement_line = "foo==0.0.1 --hash=sha256:deadbeef", |
| 699 | + sha256 = "", |
| 700 | + target_platforms = ["cp39_linux_x86_64"], |
| 701 | + url = "", |
| 702 | + yanked = False, |
| 703 | + ), |
| 704 | + struct( |
| 705 | + distribution = "foo", |
| 706 | + extra_pip_args = [], |
| 707 | + filename = "foo-0.0.2-py3-none-any.whl", |
| 708 | + requirement_line = "foo==0.0.2", |
| 709 | + sha256 = "deadb11f", |
| 710 | + target_platforms = ["cp310_linux_x86_64"], |
| 711 | + url = "super2", |
| 712 | + yanked = False, |
| 713 | + ), |
| 714 | + ], |
| 715 | + ), |
| 716 | + ]) |
| 717 | + |
| 718 | +_tests.append(_test_get_index_urls_different_versions) |
| 719 | + |
621 | 720 | def parse_requirements_test_suite(name):
|
622 | 721 | """Create the test suite.
|
623 | 722 |
|
|
0 commit comments