xref: /aosp_15_r20/external/bazelbuild-rules_python/examples/pip_parse_vendored/requirements.bzl (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1"""Starlark representation of locked requirements.
2
3@generated by rules_python pip_parse repository rule.
4"""
5
6load("@rules_python//python:pip.bzl", "pip_utils")
7load("@rules_python//python/pip_install:pip_repository.bzl", "group_library", "whl_library")
8
9all_requirements = [
10    "@my_project_pip_deps_vendored_certifi//:pkg",
11    "@my_project_pip_deps_vendored_charset_normalizer//:pkg",
12    "@my_project_pip_deps_vendored_idna//:pkg",
13    "@my_project_pip_deps_vendored_requests//:pkg",
14    "@my_project_pip_deps_vendored_urllib3//:pkg",
15]
16
17all_whl_requirements_by_package = {
18    "certifi": "@my_project_pip_deps_vendored_certifi//:whl",
19    "charset_normalizer": "@my_project_pip_deps_vendored_charset_normalizer//:whl",
20    "idna": "@my_project_pip_deps_vendored_idna//:whl",
21    "requests": "@my_project_pip_deps_vendored_requests//:whl",
22    "urllib3": "@my_project_pip_deps_vendored_urllib3//:whl",
23}
24
25all_whl_requirements = all_whl_requirements_by_package.values()
26
27all_data_requirements = [
28    "@my_project_pip_deps_vendored_certifi//:data",
29    "@my_project_pip_deps_vendored_charset_normalizer//:data",
30    "@my_project_pip_deps_vendored_idna//:data",
31    "@my_project_pip_deps_vendored_requests//:data",
32    "@my_project_pip_deps_vendored_urllib3//:data",
33]
34
35_packages = [
36    ("my_project_pip_deps_vendored_certifi", "certifi==2023.7.22     --hash=sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082     --hash=sha256:92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9"),
37    ("my_project_pip_deps_vendored_charset_normalizer", "charset-normalizer==2.1.1     --hash=sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845     --hash=sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f"),
38    ("my_project_pip_deps_vendored_idna", "idna==3.4     --hash=sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4     --hash=sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"),
39    ("my_project_pip_deps_vendored_requests", "requests==2.28.1     --hash=sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983     --hash=sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"),
40    ("my_project_pip_deps_vendored_urllib3", "urllib3==1.26.13     --hash=sha256:47cc05d99aaa09c9e72ed5809b60e7ba354e64b59c9c173ac3018642d8bb41fc     --hash=sha256:c083dd0dce68dbfbe1129d5271cb90f9447dea7d52097c6e0126120c521ddea8"),
41]
42_config = {
43    "download_only": False,
44    "enable_implicit_namespace_pkgs": False,
45    "environment": {},
46    "envsubst": ["PIP_RETRIES"],
47    "extra_pip_args": ["--retries=${PIP_RETRIES:-5}"],
48    "isolated": True,
49    "pip_data_exclude": [],
50    "python_interpreter": "python3",
51    "python_interpreter_target": "@python39_host//:python",
52    "quiet": True,
53    "repo": "my_project_pip_deps_vendored",
54    "repo_prefix": "my_project_pip_deps_vendored_",
55    "timeout": 600,
56}
57_annotations = {}
58
59def requirement(name):
60    return "@my_project_pip_deps_vendored_{}//:{}".format(pip_utils.normalize_name(name), "pkg")
61
62def whl_requirement(name):
63    return "@my_project_pip_deps_vendored_{}//:{}".format(pip_utils.normalize_name(name), "whl")
64
65def data_requirement(name):
66    return "@my_project_pip_deps_vendored_{}//:{}".format(pip_utils.normalize_name(name), "data")
67
68def dist_info_requirement(name):
69    return "@my_project_pip_deps_vendored_{}//:{}".format(pip_utils.normalize_name(name), "dist_info")
70
71def _get_annotation(requirement):
72    # This expects to parse `setuptools==58.2.0     --hash=sha256:2551203ae6955b9876741a26ab3e767bb3242dafe86a32a749ea0d78b6792f11`
73    # down to `setuptools`.
74    name = requirement.split(" ")[0].split("=")[0].split("[")[0]
75    return _annotations.get(name)
76
77def install_deps(**whl_library_kwargs):
78    """Repository rule macro. Install dependencies from `pip_parse`.
79
80    Args:
81       **whl_library_kwargs: Additional arguments which will flow to underlying
82         `whl_library` calls. See pip_repository.bzl for details.
83    """
84
85    # Set up the requirement groups
86    all_requirement_groups = {}
87
88    requirement_group_mapping = {
89        requirement: group_name
90        for group_name, group_requirements in all_requirement_groups.items()
91        for requirement in group_requirements
92    }
93
94    group_repo = "my_project_pip_deps_vendored__groups"
95    group_library(
96        name = group_repo,
97        repo_prefix = "my_project_pip_deps_vendored_",
98        groups = all_requirement_groups,
99    )
100
101    # Install wheels which may be participants in a group
102    whl_config = dict(_config)
103    whl_config.update(whl_library_kwargs)
104
105    for name, requirement in _packages:
106        group_name = requirement_group_mapping.get(name.replace("my_project_pip_deps_vendored_", ""))
107        group_deps = all_requirement_groups.get(group_name, [])
108
109        whl_library(
110            name = name,
111            requirement = requirement,
112            group_name = group_name,
113            group_deps = group_deps,
114            annotation = _get_annotation(requirement),
115            **whl_config
116        )
117