Skip to content

Commit af354c2

Browse files
kormidealexeagle
authored andcommitted
Create a pip_parse bzlmod extension
1 parent ba69aec commit af354c2

19 files changed

+472
-58
lines changed

MODULE.bazel

Lines 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

Lines 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

Lines 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

Lines 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

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

examples/bzlmod/BUILD.bazel

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

0 commit comments

Comments
 (0)