Skip to content

Commit 08ba406

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

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-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

+7
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ def _whl_library_impl(rctx):
193193
# Manually construct the PYTHONPATH since we cannot use the toolchain here
194194
environment = _create_repository_execution_environment(rctx, python_interpreter, logger = logger)
195195

196+
# Add a PROJECT_ROOT environment variable
197+
if rctx.attr.project_root:
198+
environment["PROJECT_ROOT"] = str(rctx.path(rctx.attr.project_root).dirname)
199+
196200
whl_path = None
197201
if rctx.attr.whl_file:
198202
whl_path = rctx.path(rctx.attr.whl_file)
@@ -404,6 +408,9 @@ and the target that we need respectively.
404408
"group_name": attr.string(
405409
doc = "Name of the group, if any.",
406410
),
411+
"project_root": attr.label(
412+
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.",
413+
),
407414
"repo": attr.string(
408415
mandatory = True,
409416
doc = "Pointer to parent repo name. Used to make these rules rerun if the parent repo changes.",

tests/pypi/extension/extension_tests.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def _parse(
9191
netrc = None,
9292
parse_all_requirements_files = True,
9393
pip_data_exclude = None,
94+
project_root = None,
9495
python_interpreter = None,
9596
python_interpreter_target = None,
9697
quiet = True,
@@ -119,6 +120,7 @@ def _parse(
119120
netrc = netrc,
120121
parse_all_requirements_files = parse_all_requirements_files,
121122
pip_data_exclude = pip_data_exclude,
123+
project_root = project_root,
122124
python_interpreter = python_interpreter,
123125
python_interpreter_target = python_interpreter_target,
124126
python_version = python_version,

0 commit comments

Comments
 (0)