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 35391d9

Browse filesBrowse files
authored
chore: support bzlmod (bazel-contrib#744)
1 parent ab6940a commit 35391d9
Copy full SHA for 35391d9

File tree

Expand file treeCollapse file tree

13 files changed

+94
-2
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+94
-2
lines changed

‎.bazelrc

Copy file name to clipboardExpand all lines: .bazelrc
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# This lets us glob() up all the files inside the examples to make them inputs to tests
44
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
55
# To update these lines, run tools/bazel_integration_test/update_deleted_packages.sh
6-
build --deleted_packages=examples/build_file_generation,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points,tests/pip_deps
7-
query --deleted_packages=examples/build_file_generation,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points,tests/pip_deps
6+
build --deleted_packages=examples/build_file_generation,examples/bzlmod,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points,tests/pip_deps
7+
query --deleted_packages=examples/build_file_generation,examples/bzlmod,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points,tests/pip_deps
88

99
test --test_output=errors
1010

‎BUILD

Copy file name to clipboardExpand all lines: BUILD
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ filegroup(
2626
name = "distribution",
2727
srcs = [
2828
"BUILD",
29+
"MODULE.bazel",
2930
"WORKSPACE",
3031
"internal_deps.bzl",
3132
"internal_setup.bzl",

‎MODULE.bazel

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module(
2+
name = "rules_python",
3+
compatibility_level = 1,
4+
version = "0.0.0",
5+
)
6+
7+
pip_install = use_extension("@rules_python//python:extensions.bzl", "pip_install")
8+
9+
use_repo(
10+
pip_install,
11+
"pypi__click",
12+
"pypi__pip",
13+
"pypi__pip_tools",
14+
"pypi__pkginfo",
15+
"pypi__setuptools",
16+
"pypi__wheel",
17+
)

‎examples/BUILD

Copy file name to clipboardExpand all lines: examples/BUILD
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ bazel_integration_test(
4242
name = "relative_requirements_example",
4343
timeout = "long",
4444
)
45+
46+
bazel_integration_test(
47+
name = "bzlmod_example",
48+
)

‎examples/bzlmod/.bazelrc

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

‎examples/bzlmod/.gitignore

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

‎examples/bzlmod/BUILD.bazel

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
2+
3+
py_library(
4+
name = "lib",
5+
srcs = ["__init__.py"],
6+
)
7+
8+
py_binary(
9+
name = "bzlmod",
10+
srcs = ["__main__.py"],
11+
main = "__main__.py",
12+
visibility = ["//:__subpackages__"],
13+
deps = [":lib"],
14+
)
15+
16+
py_test(
17+
name = "test",
18+
srcs = ["test.py"],
19+
deps = [":lib"],
20+
)

‎examples/bzlmod/MODULE.bazel

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module(
2+
name = "example_bzlmod",
3+
compatibility_level = 1,
4+
version = "0.0.0",
5+
)
6+
7+
bazel_dep(name = "rules_python", version = "0.0.0")
8+
9+
local_path_override(
10+
module_name = "rules_python",
11+
path = "../..",
12+
)

‎examples/bzlmod/WORKSPACE

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Empty file indicating the root of a Bazel workspace.
2+
# Dependencies and setup are in MODULE.bazel.

‎examples/bzlmod/__init__.py

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# TODO: bzlmod should grant access to pip_install dependencies as well
2+
# import requests
3+
4+
5+
def main(url):
6+
# r = requests.get(url)
7+
# return r.text
8+
return url

‎examples/bzlmod/__main__.py

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from __init__ import main
2+
3+
if __name__ == "__main__":
4+
print(main("https://example.com"))

‎examples/bzlmod/test.py

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
3+
from __init__ import main
4+
5+
6+
class ExampleTest(unittest.TestCase):
7+
def test_main(self):
8+
self.assertEquals("http://google.com", main("http://google.com"))
9+
10+
11+
if __name__ == "__main__":
12+
unittest.main()

‎python/extensions.bzl

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"Module extensions for use with bzlmod"
2+
3+
load("@rules_python//python/pip_install:repositories.bzl", "pip_install_dependencies")
4+
5+
def _pip_install_impl(_):
6+
pip_install_dependencies()
7+
8+
pip_install = module_extension(
9+
implementation = _pip_install_impl,
10+
)

0 commit comments

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