• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15""
16
17load("@bazel_skylib//lib:versions.bzl", "versions")
18load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
19load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
20load("//:version.bzl", "MINIMUM_BAZEL_VERSION")
21
22_RULE_DEPS = [
23    # START: maintained by 'bazel run //tools/private:update_pip_deps'
24    (
25        "pypi__build",
26        "https://files.pythonhosted.org/packages/03/97/f58c723ff036a8d8b4d3115377c0a37ed05c1f68dd9a0d66dab5e82c5c1c/build-0.9.0-py3-none-any.whl",
27        "38a7a2b7a0bdc61a42a0a67509d88c71ecfc37b393baba770fae34e20929ff69",
28    ),
29    (
30        "pypi__click",
31        "https://files.pythonhosted.org/packages/76/0a/b6c5f311e32aeb3b406e03c079ade51e905ea630fc19d1262a46249c1c86/click-8.0.1-py3-none-any.whl",
32        "fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6",
33    ),
34    (
35        "pypi__colorama",
36        "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl",
37        "4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6",
38    ),
39    (
40        "pypi__importlib_metadata",
41        "https://files.pythonhosted.org/packages/d7/31/74dcb59a601b95fce3b0334e8fc9db758f78e43075f22aeb3677dfb19f4c/importlib_metadata-1.4.0-py2.py3-none-any.whl",
42        "bdd9b7c397c273bcc9a11d6629a38487cd07154fa255a467bf704cd2c258e359",
43    ),
44    (
45        "pypi__installer",
46        "https://files.pythonhosted.org/packages/e5/ca/1172b6638d52f2d6caa2dd262ec4c811ba59eee96d54a7701930726bce18/installer-0.7.0-py3-none-any.whl",
47        "05d1933f0a5ba7d8d6296bb6d5018e7c94fa473ceb10cf198a92ccea19c27b53",
48    ),
49    (
50        "pypi__more_itertools",
51        "https://files.pythonhosted.org/packages/bd/3f/c4b3dbd315e248f84c388bd4a72b131a29f123ecacc37ffb2b3834546e42/more_itertools-8.13.0-py3-none-any.whl",
52        "c5122bffc5f104d37c1626b8615b511f3427aa5389b94d61e5ef8236bfbc3ddb",
53    ),
54    (
55        "pypi__packaging",
56        "https://files.pythonhosted.org/packages/8f/7b/42582927d281d7cb035609cd3a543ffac89b74f3f4ee8e1c50914bcb57eb/packaging-22.0-py3-none-any.whl",
57        "957e2148ba0e1a3b282772e791ef1d8083648bc131c8ab0c1feba110ce1146c3",
58    ),
59    (
60        "pypi__pep517",
61        "https://files.pythonhosted.org/packages/ee/2f/ef63e64e9429111e73d3d6cbee80591672d16f2725e648ebc52096f3d323/pep517-0.13.0-py3-none-any.whl",
62        "4ba4446d80aed5b5eac6509ade100bff3e7943a8489de249654a5ae9b33ee35b",
63    ),
64    (
65        "pypi__pip",
66        "https://files.pythonhosted.org/packages/09/bd/2410905c76ee14c62baf69e3f4aa780226c1bbfc9485731ad018e35b0cb5/pip-22.3.1-py3-none-any.whl",
67        "908c78e6bc29b676ede1c4d57981d490cb892eb45cd8c214ab6298125119e077",
68    ),
69    (
70        "pypi__pip_tools",
71        "https://files.pythonhosted.org/packages/5e/e8/f6d7d1847c7351048da870417724ace5c4506e816b38db02f4d7c675c189/pip_tools-6.12.1-py3-none-any.whl",
72        "f0c0c0ec57b58250afce458e2e6058b1f30a4263db895b7d72fd6311bf1dc6f7",
73    ),
74    (
75        "pypi__setuptools",
76        "https://files.pythonhosted.org/packages/7c/5b/3d92b9f0f7ca1645cba48c080b54fe7d8b1033a4e5720091d1631c4266db/setuptools-60.10.0-py3-none-any.whl",
77        "782ef48d58982ddb49920c11a0c5c9c0b02e7d7d1c2ad0aa44e1a1e133051c96",
78    ),
79    (
80        "pypi__tomli",
81        "https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl",
82        "939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc",
83    ),
84    (
85        "pypi__wheel",
86        "https://files.pythonhosted.org/packages/bd/7c/d38a0b30ce22fc26ed7dbc087c6d00851fb3395e9d0dac40bec1f905030c/wheel-0.38.4-py3-none-any.whl",
87        "b60533f3f5d530e971d6737ca6d58681ee434818fab630c83a734bb10c083ce8",
88    ),
89    (
90        "pypi__zipp",
91        "https://files.pythonhosted.org/packages/f4/50/cc72c5bcd48f6e98219fc4a88a5227e9e28b81637a99c49feba1d51f4d50/zipp-1.0.0-py2.py3-none-any.whl",
92        "8dda78f06bd1674bd8720df8a50bb47b6e1233c503a4eed8e7810686bde37656",
93    ),
94    # END: maintained by 'bazel run //tools/private:update_pip_deps'
95]
96
97_GENERIC_WHEEL = """\
98package(default_visibility = ["//visibility:public"])
99
100load("@rules_python//python:defs.bzl", "py_library")
101
102py_library(
103    name = "lib",
104    srcs = glob(["**/*.py"]),
105    data = glob(["**/*"], exclude=[
106        # These entries include those put into user-installed dependencies by
107        # data_exclude in /python/pip_install/tools/bazel.py
108        # to avoid non-determinism following pip install's behavior.
109        "**/*.py",
110        "**/*.pyc",
111        "**/*.pyc.*",  # During pyc creation, temp files named *.pyc.NNN are created
112        "**/* *",
113        "**/*.dist-info/RECORD",
114        "BUILD",
115        "WORKSPACE",
116    ]),
117    # This makes this directory a top-level in the python import
118    # search path for anything that depends on this.
119    imports = ["."],
120)
121"""
122
123# Collate all the repository names so they can be easily consumed
124all_requirements = [name for (name, _, _) in _RULE_DEPS]
125
126def requirement(pkg):
127    return Label("@pypi__" + pkg + "//:lib")
128
129def pip_install_dependencies():
130    """
131    Fetch dependencies these rules depend on. Workspaces that use the pip_install rule can call this.
132
133    (However we call it from pip_install, making it optional for users to do so.)
134    """
135
136    # We only support Bazel LTS and rolling releases.
137    # Give the user an obvious error to upgrade rather than some obscure missing symbol later.
138    # It's not guaranteed that users call this function, but it's used by all the pip fetch
139    # repository rules so it's likely that most users get the right error.
140    versions.check(MINIMUM_BAZEL_VERSION)
141
142    for (name, url, sha256) in _RULE_DEPS:
143        maybe(
144            http_archive,
145            name,
146            url = url,
147            sha256 = sha256,
148            type = "zip",
149            build_file_content = _GENERIC_WHEEL,
150        )
151