Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit af354c2

Browse filesBrowse files
kormidealexeagle
authored andcommitted
Create a pip_parse bzlmod extension
1 parent ba69aec commit af354c2
Copy full SHA for af354c2
Expand file treeCollapse file tree

19 files changed

+472
-58
lines changed

‎MODULE.bazel

Copy file name to clipboardExpand all lines: MODULE.bazel
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,27 @@ module(
44
version = "0.0.0",
55
)
66

7-
pip_install = use_extension("@rules_python//python:extensions.bzl", "pip_install")
7+
bazel_dep(name = "platforms", version = "0.0.4")
8+
9+
internal_deps = use_extension("@rules_python//python:extensions.bzl", "internal_deps")
10+
11+
internal_deps.install()
812

913
use_repo(
10-
pip_install,
14+
internal_deps,
15+
"pypi__build",
1116
"pypi__click",
17+
"pypi__colorama",
18+
"pypi__importlib_metadata",
19+
"pypi__installer",
20+
"pypi__more_itertools",
21+
"pypi__packaging",
22+
"pypi__pep517",
1223
"pypi__pip",
1324
"pypi__pip_tools",
25+
"pypi__pyparsing",
1426
"pypi__setuptools",
27+
"pypi__tomli",
1528
"pypi__wheel",
29+
"pypi__zipp",
1630
)

‎docs/BUILD

Copy file name to clipboardExpand all lines: docs/BUILD
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ bzl_library(
7070
],
7171
)
7272

73+
bzl_library(
74+
name = "requirements_parser_bzl",
75+
srcs = [
76+
"//python/pip_install:requirements_parser.bzl",
77+
],
78+
)
79+
7380
bzl_library(
7481
name = "packaging_bzl",
7582
srcs = [
@@ -114,6 +121,7 @@ stardoc(
114121
deps = [
115122
":bazel_repo_tools",
116123
":pip_install_bzl",
124+
":requirements_parser_bzl",
117125
"//third_party/github.com/bazelbuild/bazel-skylib/lib:versions",
118126
],
119127
)

‎docs/pip.md

Copy file name to clipboardExpand all lines: docs/pip.md
+2-1Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/pip_repository.md

Copy file name to clipboardExpand all lines: docs/pip_repository.md
+41-2Lines changed: 41 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/bzlmod/.bazelversion

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.0.0rc1

‎examples/bzlmod/BUILD.bazel

Copy file name to clipboardExpand all lines: examples/bzlmod/BUILD.bazel
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1+
load("@pip//:requirements.bzl", "requirement")
12
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
3+
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
4+
5+
compile_pip_requirements(
6+
name = "requirements",
7+
extra_args = ["--allow-unsafe"],
8+
requirements_in = "requirements.in",
9+
requirements_txt = "requirements_lock.txt",
10+
)
211

312
py_library(
413
name = "lib",
514
srcs = ["__init__.py"],
15+
deps = [
16+
requirement("tabulate"),
17+
],
618
)
719

820
py_binary(
921
name = "bzlmod",
1022
srcs = ["__main__.py"],
1123
main = "__main__.py",
1224
visibility = ["//:__subpackages__"],
13-
deps = [":lib"],
25+
deps = [
26+
":lib",
27+
],
1428
)
1529

1630
py_test(

‎examples/bzlmod/MODULE.bazel

Copy file name to clipboardExpand all lines: examples/bzlmod/MODULE.bazel
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,25 @@ local_path_override(
1010
module_name = "rules_python",
1111
path = "../..",
1212
)
13+
14+
python = use_extension("@rules_python//python:extensions.bzl", "python")
15+
16+
python.toolchain(
17+
name = "python3_9",
18+
python_version = "3.9",
19+
)
20+
21+
use_repo(python, "python3_9_toolchains")
22+
23+
register_toolchains(
24+
"@python3_9_toolchains//:all",
25+
)
26+
27+
pip = use_extension("@rules_python//python:extensions.bzl", "pip")
28+
29+
pip.parse(
30+
name = "pip",
31+
requirements_lock = "//:requirements_lock.txt",
32+
)
33+
34+
use_repo(pip, "pip")

‎examples/bzlmod/__init__.py

Copy file name to clipboard
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# TODO: bzlmod should grant access to pip_install dependencies as well
2-
# import requests
1+
from tabulate import tabulate
32

43

5-
def main(url):
6-
# r = requests.get(url)
7-
# return r.text
8-
return url
4+
def main(table):
5+
return tabulate(table)

‎examples/bzlmod/__main__.py

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from __init__ import main
22

33
if __name__ == "__main__":
4-
print(main("https://example.com"))
4+
print(main([["A", 1], ["B", 2]]))

‎examples/bzlmod/requirements.in

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
requests~=2.25.1
2+
s3cmd~=2.1.0
3+
yamllint~=1.26.3
4+
tabulate~=0.9.0

‎examples/bzlmod/requirements_lock.txt

Copy file name to clipboard
+94Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#
2+
# This file is autogenerated by pip-compile with python 3.9
3+
# To update, run:
4+
#
5+
# bazel run //:requirements.update
6+
#
7+
certifi==2021.10.8 \
8+
--hash=sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872 \
9+
--hash=sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569
10+
# via requests
11+
chardet==4.0.0 \
12+
--hash=sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa \
13+
--hash=sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5
14+
# via requests
15+
idna==2.10 \
16+
--hash=sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6 \
17+
--hash=sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0
18+
# via requests
19+
pathspec==0.9.0 \
20+
--hash=sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a \
21+
--hash=sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1
22+
# via yamllint
23+
python-dateutil==2.8.2 \
24+
--hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \
25+
--hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9
26+
# via s3cmd
27+
python-magic==0.4.24 \
28+
--hash=sha256:4fec8ee805fea30c07afccd1592c0f17977089895bdfaae5fec870a84e997626 \
29+
--hash=sha256:de800df9fb50f8ec5974761054a708af6e4246b03b4bdaee993f948947b0ebcf
30+
# via s3cmd
31+
pyyaml==6.0 \
32+
--hash=sha256:0283c35a6a9fbf047493e3a0ce8d79ef5030852c51e9d911a27badfde0605293 \
33+
--hash=sha256:055d937d65826939cb044fc8c9b08889e8c743fdc6a32b33e2390f66013e449b \
34+
--hash=sha256:07751360502caac1c067a8132d150cf3d61339af5691fe9e87803040dbc5db57 \
35+
--hash=sha256:0b4624f379dab24d3725ffde76559cff63d9ec94e1736b556dacdfebe5ab6d4b \
36+
--hash=sha256:0ce82d761c532fe4ec3f87fc45688bdd3a4c1dc5e0b4a19814b9009a29baefd4 \
37+
--hash=sha256:1e4747bc279b4f613a09eb64bba2ba602d8a6664c6ce6396a4d0cd413a50ce07 \
38+
--hash=sha256:213c60cd50106436cc818accf5baa1aba61c0189ff610f64f4a3e8c6726218ba \
39+
--hash=sha256:231710d57adfd809ef5d34183b8ed1eeae3f76459c18fb4a0b373ad56bedcdd9 \
40+
--hash=sha256:277a0ef2981ca40581a47093e9e2d13b3f1fbbeffae064c1d21bfceba2030287 \
41+
--hash=sha256:2cd5df3de48857ed0544b34e2d40e9fac445930039f3cfe4bcc592a1f836d513 \
42+
--hash=sha256:40527857252b61eacd1d9af500c3337ba8deb8fc298940291486c465c8b46ec0 \
43+
--hash=sha256:473f9edb243cb1935ab5a084eb238d842fb8f404ed2193a915d1784b5a6b5fc0 \
44+
--hash=sha256:48c346915c114f5fdb3ead70312bd042a953a8ce5c7106d5bfb1a5254e47da92 \
45+
--hash=sha256:50602afada6d6cbfad699b0c7bb50d5ccffa7e46a3d738092afddc1f9758427f \
46+
--hash=sha256:68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2 \
47+
--hash=sha256:77f396e6ef4c73fdc33a9157446466f1cff553d979bd00ecb64385760c6babdc \
48+
--hash=sha256:819b3830a1543db06c4d4b865e70ded25be52a2e0631ccd2f6a47a2822f2fd7c \
49+
--hash=sha256:897b80890765f037df3403d22bab41627ca8811ae55e9a722fd0392850ec4d86 \
50+
--hash=sha256:98c4d36e99714e55cfbaaee6dd5badbc9a1ec339ebfc3b1f52e293aee6bb71a4 \
51+
--hash=sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c \
52+
--hash=sha256:9fa600030013c4de8165339db93d182b9431076eb98eb40ee068700c9c813e34 \
53+
--hash=sha256:a80a78046a72361de73f8f395f1f1e49f956c6be882eed58505a15f3e430962b \
54+
--hash=sha256:b3d267842bf12586ba6c734f89d1f5b871df0273157918b0ccefa29deb05c21c \
55+
--hash=sha256:b5b9eccad747aabaaffbc6064800670f0c297e52c12754eb1d976c57e4f74dcb \
56+
--hash=sha256:c5687b8d43cf58545ade1fe3e055f70eac7a5a1a0bf42824308d868289a95737 \
57+
--hash=sha256:cba8c411ef271aa037d7357a2bc8f9ee8b58b9965831d9e51baf703280dc73d3 \
58+
--hash=sha256:d15a181d1ecd0d4270dc32edb46f7cb7733c7c508857278d3d378d14d606db2d \
59+
--hash=sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53 \
60+
--hash=sha256:d4eccecf9adf6fbcc6861a38015c2a64f38b9d94838ac1810a9023a0609e1b78 \
61+
--hash=sha256:d67d839ede4ed1b28a4e8909735fc992a923cdb84e618544973d7dfc71540803 \
62+
--hash=sha256:daf496c58a8c52083df09b80c860005194014c3698698d1a57cbcfa182142a3a \
63+
--hash=sha256:e61ceaab6f49fb8bdfaa0f92c4b57bcfbea54c09277b1b4f7ac376bfb7a7c174 \
64+
--hash=sha256:f84fbc98b019fef2ee9a1cb3ce93e3187a6df0b2538a651bfb890254ba9f90b5
65+
# via yamllint
66+
requests==2.25.1 \
67+
--hash=sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804 \
68+
--hash=sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e
69+
# via -r ./requirements.in
70+
s3cmd==2.1.0 \
71+
--hash=sha256:49cd23d516b17974b22b611a95ce4d93fe326feaa07320bd1d234fed68cbccfa \
72+
--hash=sha256:966b0a494a916fc3b4324de38f089c86c70ee90e8e1cae6d59102103a4c0cc03
73+
# via -r ./requirements.in
74+
six==1.16.0 \
75+
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
76+
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
77+
# via python-dateutil
78+
tabulate==0.9.0 \
79+
--hash=sha256:0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c \
80+
--hash=sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f
81+
# via -r ./requirements.in
82+
urllib3==1.26.7 \
83+
--hash=sha256:4987c65554f7a2dbf30c18fd48778ef124af6fab771a377103da0585e2336ece \
84+
--hash=sha256:c4fdf4019605b6e5423637e01bc9fe4daef873709a7973e195ceba0a62bbc844
85+
# via requests
86+
yamllint==1.26.3 \
87+
--hash=sha256:3934dcde484374596d6b52d8db412929a169f6d9e52e20f9ade5bf3523d9b96e
88+
# via -r ./requirements.in
89+
90+
# The following packages are considered to be unsafe in a requirements file:
91+
setuptools==59.6.0 \
92+
--hash=sha256:22c7348c6d2976a52632c67f7ab0cdf40147db7789f9aed18734643fe9cf3373 \
93+
--hash=sha256:4ce92f1e1f8f01233ee9952c04f6b81d1e02939d6e1b488428154974a4d0783e
94+
# via yamllint

‎examples/bzlmod/test.py

Copy file name to clipboardExpand all lines: examples/bzlmod/test.py
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55

66
class ExampleTest(unittest.TestCase):
77
def test_main(self):
8-
self.assertEquals("http://google.com", main("http://google.com"))
8+
self.assertEquals(
9+
"""\
10+
- -
11+
A 1
12+
B 2
13+
- -""",
14+
main([["A", 1], ["B", 2]]),
15+
)
916

1017

1118
if __name__ == "__main__":

‎examples/pip_parse_vendored/requirements.bzl

Copy file name to clipboardExpand all lines: examples/pip_parse_vendored/requirements.bzl
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,29 @@ all_whl_requirements = ["@pip_certifi//:whl", "@pip_charset_normalizer//:whl", "
1414
_packages = [("pip_certifi", "certifi==2021.10.8 --hash=sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872 --hash=sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"), ("pip_charset_normalizer", "charset-normalizer==2.0.12 --hash=sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597 --hash=sha256:6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df"), ("pip_idna", "idna==3.3 --hash=sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff --hash=sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"), ("pip_requests", "requests==2.27.1 --hash=sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61 --hash=sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"), ("pip_urllib3", "urllib3==1.26.9 --hash=sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14 --hash=sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e")]
1515
_config = {"download_only": False, "enable_implicit_namespace_pkgs": False, "environment": {}, "extra_pip_args": [], "isolated": True, "pip_data_exclude": [], "python_interpreter": "python3", "python_interpreter_target": interpreter, "quiet": True, "repo": "pip", "repo_prefix": "pip_", "timeout": 600}
1616
_annotations = {}
17+
_bzlmod = False
1718

1819
def _clean_name(name):
1920
return name.replace("-", "_").replace(".", "_").lower()
2021

2122
def requirement(name):
23+
if _bzlmod:
24+
return "@@pip//:" + _clean_name(name) + "_pkg"
2225
return "@pip_" + _clean_name(name) + "//:pkg"
2326

2427
def whl_requirement(name):
28+
if _bzlmod:
29+
return "@@pip//:" + _clean_name(name) + "_whl"
2530
return "@pip_" + _clean_name(name) + "//:whl"
2631

2732
def data_requirement(name):
33+
if _bzlmod:
34+
return "@@pip//:" + _clean_name(name) + "_data"
2835
return "@pip_" + _clean_name(name) + "//:data"
2936

3037
def dist_info_requirement(name):
38+
if _bzlmod:
39+
return "@@pip//:" + _clean_name(name) + "_dist_info"
3140
return "@pip_" + _clean_name(name) + "//:dist_info"
3241

3342
def entry_point(pkg, script = None):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.