Skip to content

Commit 70cce26

Browse files
authored
Refactor and separate concerns of external python package handling code (#953)
1 parent 9022291 commit 70cce26

31 files changed

+181
-119
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See https://pre-commit.com/hooks.html for more hooks
44
repos:
55
- repo: https://github.com/keith/pre-commit-buildifier
6-
rev: 5.1.0.1
6+
rev: 6.0.0
77
hooks:
88
- id: buildifier
99
args: &args

MODULE.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
module(
22
name = "rules_python",
3-
compatibility_level = 1,
43
version = "0.0.0",
4+
compatibility_level = 1,
55
)
66

77
bazel_dep(name = "platforms", version = "0.0.4")
88

99
internal_deps = use_extension("@rules_python//python:extensions.bzl", "internal_deps")
10-
1110
internal_deps.install()
12-
1311
use_repo(
1412
internal_deps,
1513
"pypi__build",

examples/bzlmod/MODULE.bazel

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
11
module(
22
name = "example_bzlmod",
3-
compatibility_level = 1,
43
version = "0.0.0",
4+
compatibility_level = 1,
55
)
66

77
bazel_dep(name = "rules_python", version = "0.0.0")
8-
98
local_path_override(
109
module_name = "rules_python",
1110
path = "../..",
1211
)
1312

1413
python = use_extension("@rules_python//python:extensions.bzl", "python")
15-
1614
python.toolchain(
1715
name = "python3_9",
1816
python_version = "3.9",
1917
)
20-
2118
use_repo(python, "python3_9_toolchains")
2219

2320
register_toolchains(
2421
"@python3_9_toolchains//:all",
2522
)
2623

2724
pip = use_extension("@rules_python//python:extensions.bzl", "pip")
28-
2925
pip.parse(
3026
name = "pip",
3127
requirements_lock = "//:requirements_lock.txt",
3228
requirements_windows = "//:requirements_windows.txt",
3329
)
34-
3530
use_repo(pip, "pip")

python/extensions.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _pip_impl(module_ctx):
7878
environment = attr.environment,
7979
)
8080

81-
# Keep in sync with python/pip_install/extract_wheels/bazel.py
81+
# Keep in sync with python/pip_install/tools/bazel.py
8282
def _sanitize_name(name):
8383
return name.replace("-", "_").replace(".", "_").lower()
8484

python/pip_install/BUILD.bazel

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
exports_files(["pip_compile.py"])
2-
31
filegroup(
42
name = "distribution",
53
srcs = glob(["*.bzl"]) + [
64
"BUILD.bazel",
7-
"pip_compile.py",
8-
"//python/pip_install/extract_wheels:distribution",
5+
"//python/pip_install/tools/dependency_resolver:distribution",
6+
"//python/pip_install/tools/lib:distribution",
7+
"//python/pip_install/tools/lock_file_generator:distribution",
8+
"//python/pip_install/tools/wheel_installer:distribution",
99
"//python/pip_install/private:distribution",
1010
],
1111
visibility = ["//:__pkg__"],
@@ -22,7 +22,10 @@ filegroup(
2222
filegroup(
2323
name = "py_srcs",
2424
srcs = [
25-
"//python/pip_install/extract_wheels:py_srcs",
25+
"//python/pip_install/tools/dependency_resolver:py_srcs",
26+
"//python/pip_install/tools/lib:py_srcs",
27+
"//python/pip_install/tools/lock_file_generator:py_srcs",
28+
"//python/pip_install/tools/wheel_installer:py_srcs",
2629
],
2730
visibility = ["//python/pip_install/private:__pkg__"],
2831
)

python/pip_install/pip_repository.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def _pip_repository_impl(rctx):
307307
args = [
308308
python_interpreter,
309309
"-m",
310-
"python.pip_install.extract_wheels.parse_requirements_to_bzl",
310+
"python.pip_install.tools.lock_file_generator.lock_file_generator",
311311
"--requirements_lock",
312312
rctx.path(requirements_txt),
313313
"--requirements_lock_label",
@@ -524,7 +524,7 @@ def _whl_library_impl(rctx):
524524
args = [
525525
python_interpreter,
526526
"-m",
527-
"python.pip_install.extract_wheels.wheel_installer",
527+
"python.pip_install.tools.wheel_installer.wheel_installer",
528528
"--requirement",
529529
rctx.attr.requirement,
530530
"--repo",

python/pip_install/private/pip_install_utils.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Utilities for `rules_python` pip rules"""
22

33
_SRCS_TEMPLATE = """\
4-
\"\"\"A generate file containing all source files used for `@rules_python//python/pip_install:pip_repository.bzl` rules
4+
\"\"\"A generated file containing all source files used for `@rules_python//python/pip_install:pip_repository.bzl` rules
55
6-
This file is auto-generated from the `@rules_python//python/pip_install/private:srcs_module.install` target. Please
6+
This file is auto-generated from the `@rules_python//python/pip_install/private:srcs_module.update` target. Please
77
`bazel run` this target to apply any updates. Note that doing so will discard any local modifications.
88
"\"\"
99
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
"""A generate file containing all source files used for `@rules_python//python/pip_install:pip_repository.bzl` rules
1+
"""A generated file containing all source files used for `@rules_python//python/pip_install:pip_repository.bzl` rules
22
3-
This file is auto-generated from the `@rules_python//python/pip_install/private:srcs_module.install` target. Please
3+
This file is auto-generated from the `@rules_python//python/pip_install/private:srcs_module.update` target. Please
44
`bazel run` this target to apply any updates. Note that doing so will discard any local modifications.
55
"""
66

77
# Each source file is tracked as a target so `pip_repository` rules will know to automatically rebuild if any of the
88
# sources changed.
99
PIP_INSTALL_PY_SRCS = [
10-
"@rules_python//python/pip_install/extract_wheels:__init__.py",
11-
"@rules_python//python/pip_install/extract_wheels:annotation.py",
12-
"@rules_python//python/pip_install/extract_wheels:arguments.py",
13-
"@rules_python//python/pip_install/extract_wheels:bazel.py",
14-
"@rules_python//python/pip_install/extract_wheels:namespace_pkgs.py",
15-
"@rules_python//python/pip_install/extract_wheels:parse_requirements_to_bzl.py",
16-
"@rules_python//python/pip_install/extract_wheels:wheel.py",
17-
"@rules_python//python/pip_install/extract_wheels:wheel_installer.py",
10+
"@rules_python//python/pip_install/tools/dependency_resolver:__init__.py",
11+
"@rules_python//python/pip_install/tools/dependency_resolver:dependency_resolver.py",
12+
"@rules_python//python/pip_install/tools/lib:__init__.py",
13+
"@rules_python//python/pip_install/tools/lib:annotation.py",
14+
"@rules_python//python/pip_install/tools/lib:arguments.py",
15+
"@rules_python//python/pip_install/tools/lib:bazel.py",
16+
"@rules_python//python/pip_install/tools/lock_file_generator:__init__.py",
17+
"@rules_python//python/pip_install/tools/lock_file_generator:lock_file_generator.py",
18+
"@rules_python//python/pip_install/tools/wheel_installer:namespace_pkgs.py",
19+
"@rules_python//python/pip_install/tools/wheel_installer:wheel.py",
20+
"@rules_python//python/pip_install/tools/wheel_installer:wheel_installer.py",
1821
]

python/pip_install/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ py_library(
8989
srcs = glob(["**/*.py"]),
9090
data = glob(["**/*"], exclude=[
9191
# These entries include those put into user-installed dependencies by
92-
# data_exclude in /python/pip_install/extract_wheels/bazel.py
92+
# data_exclude in /python/pip_install/tools/bazel.py
9393
# to avoid non-determinism following pip install's behavior.
9494
"**/*.py",
9595
"**/*.pyc",

python/pip_install/requirements.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def compile_pip_requirements(
5757

5858
# Use the Label constructor so this is expanded in the context of the file
5959
# where it appears, which is to say, in @rules_python
60-
pip_compile = Label("//python/pip_install:pip_compile.py")
60+
pip_compile = Label("//python/pip_install/tools/dependency_resolver:dependency_resolver.py")
6161

6262
loc = "$(rootpath {})"
6363

0 commit comments

Comments
 (0)