Skip to content

Commit 71dbb10

Browse files
committed
feat: add support for expanding PROJECT_ROOT in requirement files
Signed-off-by: Amaury Pouly <[email protected]>
1 parent 66a8b5b commit 71dbb10

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

python/private/pypi/extension.bzl

+4
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def _create_whl_repos(
241241
group_deps = group_deps,
242242
group_name = group_name,
243243
pip_data_exclude = pip_attr.pip_data_exclude,
244+
project_root = pip_attr.project_root,
244245
python_interpreter = pip_attr.python_interpreter,
245246
python_interpreter_target = python_interpreter_target,
246247
whl_patches = {
@@ -732,6 +733,9 @@ find in case extra indexes are specified.
732733
""",
733734
default = True,
734735
),
736+
"project_root": attr.label(
737+
doc = "Label of the file defining the project root. If present, this label will be passed to all `whl_library` created from the requirement file. It will then expanded to a path and its parent directory will be made available in the PROJECT_ROOT environment variable when building the wheel.",
738+
),
735739
"python_version": attr.string(
736740
mandatory = True,
737741
doc = """

python/private/pypi/whl_library.bzl

+6
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ def _whl_library_impl(rctx):
192192

193193
# Manually construct the PYTHONPATH since we cannot use the toolchain here
194194
environment = _create_repository_execution_environment(rctx, python_interpreter, logger = logger)
195+
# Add a PROJECT_ROOT environment variable
196+
if rctx.attr.project_root:
197+
environment["PROJECT_ROOT"] = str(rctx.path(rctx.attr.project_root).dirname)
195198

196199
whl_path = None
197200
if rctx.attr.whl_file:
@@ -404,6 +407,9 @@ and the target that we need respectively.
404407
"group_name": attr.string(
405408
doc = "Name of the group, if any.",
406409
),
410+
"project_root": attr.label(
411+
doc = "Label of the file defining the project root. If present, this label will be expanded to a path and its parent directory will be made available in the PROJECT_ROOT environment variable when building the wheel.",
412+
),
407413
"repo": attr.string(
408414
mandatory = True,
409415
doc = "Pointer to parent repo name. Used to make these rules rerun if the parent repo changes.",

0 commit comments

Comments
 (0)