Skip to content

Commit 2980e96

Browse files
committed
refactor: pip-compile requirements for tools/publish
1 parent a282930 commit 2980e96

File tree

9 files changed

+2665
-701
lines changed

9 files changed

+2665
-701
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ pip.parse(
5959
hub_name = "rules_python_publish_deps",
6060
python_version = "3.11",
6161
requirements_by_platform = {
62-
"//tools/publish:requirements.txt": "linux_*",
6362
"//tools/publish:requirements_darwin.txt": "osx_*",
63+
"//tools/publish:requirements_linux.txt": "linux_*",
6464
"//tools/publish:requirements_windows.txt": "windows_*",
6565
},
6666
)

examples/bzlmod/MODULE.bazel.lock

Lines changed: 1634 additions & 686 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/private/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@rules_multirun//:defs.bzl", "multirun")
2+
3+
multirun(
4+
name = "requirements_publish.update",
5+
commands = [
6+
"//tools/publish:{}.update".format(r)
7+
for r in [
8+
"requirements_universal",
9+
"requirements",
10+
"requirements_darwin",
11+
"requirements_windows",
12+
"requirements_linux",
13+
]
14+
],
15+
)

tools/private/publish_deps.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2024 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+
"""A simple macro to lock the requirements for twine
16+
"""
17+
18+
load("//python/uv/private:lock.bzl", "lock") # buildifier: disable=bzl-visibility
19+
20+
def publish_deps(*, name, outs, **kwargs):
21+
"""Generate all of the requirements files for all platforms."""
22+
for out, platform in outs.items():
23+
lock(
24+
name = out.replace(".txt", ""),
25+
out = out,
26+
universal = platform == "",
27+
args = [] if not platform else ["--python-platform=" + platform],
28+
**kwargs
29+
)

tools/publish/BUILD.bazel

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
load("//python:pip.bzl", "compile_pip_requirements")
21
load("//python/config_settings:transition.bzl", "py_binary")
32
load("//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
4-
5-
compile_pip_requirements(
6-
name = "requirements",
7-
src = "requirements.in",
8-
requirements_darwin = "requirements_darwin.txt",
9-
requirements_windows = "requirements_windows.txt",
10-
)
3+
load("//tools/private:publish_deps.bzl", "publish_deps")
114

125
py_console_script_binary(
136
name = "twine",
@@ -28,7 +21,24 @@ filegroup(
2821
"BUILD.bazel",
2922
"requirements.txt",
3023
"requirements_darwin.txt",
24+
"requirements_linux.txt",
25+
"requirements_universal.txt",
3126
"requirements_windows.txt",
3227
],
33-
visibility = ["//tools:__pkg__"],
28+
visibility = ["//tools:__subpackages__"],
29+
)
30+
31+
# Run bazel run //tools/private:requirements_publish.update to update the outs
32+
publish_deps(
33+
name = "requirements",
34+
srcs = ["requirements.in"],
35+
outs = {
36+
"requirements.txt": "linux", # TODO: maybe deprecate
37+
"requirements_darwin.txt": "macos",
38+
"requirements_linux.txt": "linux",
39+
"requirements_universal.txt": "", # universal
40+
"requirements_windows.txt": "windows",
41+
},
42+
upgrade = False,
43+
visibility = ["//tools:__subpackages__"],
3444
)

tools/publish/requirements.txt

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/publish/requirements_linux.txt

Lines changed: 306 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/publish/requirements_universal.txt

Lines changed: 306 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/publish/requirementslinux.txt

Lines changed: 352 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)