-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move pip_compile macro to public API file (#114)
Allows the underlying rule to have a matching name with the macro. Demo: ``` alexeagle@aspect-build bazel-examples % bazel print requirements:all pip_compile( name = "runtime", requirements_in = "//:pyproject.toml", requirements_txt = "runtime.txt", ) alexeagle@aspect-build bazel-examples % bazel query --output=label_kind requirements:all pip_compile rule //requirements:runtime alias rule //requirements:runtime.update pip_compile_test rule //requirements:runtime_test ``` Fixes #113
- Loading branch information
Showing
2 changed files
with
70 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,71 @@ | ||
"uv based pip compile rules" | ||
|
||
load("//uv/private:pip.bzl", _pip_compile = "pip_compile") | ||
load("//uv/private:pip.bzl", "pip_compile_test", _pip_compile = "pip_compile") | ||
|
||
pip_compile = _pip_compile | ||
def pip_compile( | ||
name, | ||
requirements_in = None, | ||
requirements_txt = None, | ||
target_compatible_with = None, | ||
python_platform = None, | ||
args = None, | ||
data = None, | ||
tags = None, | ||
**kwargs): | ||
""" | ||
Produce targets to compile a requirements.in or pyproject.toml file into a requirements.txt file. | ||
Args: | ||
name: name of the primary compilation target. | ||
requirements_in: (optional, default "//:requirements.in") a label for the requirements.in file. | ||
requirements_txt: (optional, default "//:requirements.txt") a label for the requirements.txt file. | ||
python_platform: (optional) a uv pip compile compatible value for --python-platform. | ||
target_compatible_with: (optional) specify that a particular target is compatible only with certain | ||
Bazel platforms. | ||
args: (optional) override the default arguments passed to uv pip compile, default arguments are: | ||
--generate-hashes (Include distribution hashes in the output file) | ||
--emit-index-url (Include `--index-url` and `--extra-index-url` entries in the generated output file) | ||
--no-strip-extras (Include extras in the output file) | ||
data: (optional) a list of labels of additional files to include | ||
tags: (optional) tags to apply to the generated test target | ||
**kwargs: (optional) other fields passed through to all underlying rules | ||
Targets produced by this macro are: | ||
[name]: a runnable target that will use requirements_in to generate and overwrite requirements_txt | ||
[name].update: an alias for [name] | ||
[name]_test: a testable target that will check that requirements_txt is up to date with requirements_in | ||
""" | ||
requirements_in = requirements_in or "//:requirements.in" | ||
requirements_txt = requirements_txt or "//:requirements.txt" | ||
tags = tags or [] | ||
|
||
_pip_compile( | ||
name = name, | ||
requirements_in = requirements_in, | ||
requirements_txt = requirements_txt, | ||
python_platform = python_platform, | ||
target_compatible_with = target_compatible_with, | ||
data = data, | ||
uv_args = args, | ||
**kwargs | ||
) | ||
|
||
# Also allow 'bazel run' with a "custom verb" https://bazel.build/rules/verbs-tutorial | ||
# Provides compatibility with rules_python's compile_pip_requirements [name].update target. | ||
native.alias( | ||
name = name + ".update", | ||
actual = name, | ||
) | ||
|
||
pip_compile_test( | ||
name = name + "_test", | ||
generator_label = name, | ||
requirements_in = requirements_in, | ||
requirements_txt = requirements_txt, | ||
python_platform = python_platform or "", | ||
target_compatible_with = target_compatible_with, | ||
data = data, | ||
uv_args = args, | ||
tags = ["requires-network"] + tags, | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters