Skip to content

Commit

Permalink
Resolve wheel props from user defined properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
mgosk committed Mar 15, 2024
1 parent 9bc3aa8 commit e79fea6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ tasks:
name: "examples/pip_repository_annotations: Windows, workspace"
working_directory: examples/pip_repository_annotations
platform: windows
integration_test_py_wheel_vendored_ubuntu:
<<: *reusable_build_test_all
name: "examples/wheel: Ubuntu"
working_directory: examples/wheel
platform: ubuntu2004

integration_test_bazelinbazel_ubuntu:
<<: *common_bazelinbazel_config
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ A brief description of the categories of changes:
https://github.com/indygreg/python-build-standalone/releases/tag/20240224.
* (gazelle) Added a new `python_visibility` directive to control visibility
of generated targets by appending additional visibility labels.
* (py_wheel) Added `custom_properties` param. Properties from this file are
resolved in similar way to stable_status and volatile_status props

[0.XX.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.XX.0

Expand Down
12 changes: 12 additions & 0 deletions examples/wheel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ py_wheel(
],
)

py_wheel(
name = "version_from_other_target",
custom_properties = ":user_defined_properties.txt",
distribution = "example_minimal_library",
python_tag = "py3",
version = "{GENERATED_WHEEL_VERSION}",
deps = [
"//examples/wheel/lib:module_with_data",
"//examples/wheel/lib:simple_module",
],
)

# Use py_package to collect all transitive dependencies of a target,
# selecting just the files within a specific python package.
py_package(
Expand Down
1 change: 1 addition & 0 deletions examples/wheel/user_defined_properties.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GENERATED_WHEEL_VERSION 8.8.8
13 changes: 13 additions & 0 deletions python/private/py_wheel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ _distribution_attrs = {
default = "none",
doc = "Python ABI tag. 'none' for pure-Python wheels.",
),
"custom_properties": attr.label(
allow_single_file = True,
doc = """\
File containing user defined properties. This file is usually produced by other target.
Format:
FOO BAR
""",
),
"distribution": attr.string(
mandatory = True,
doc = """\
Expand Down Expand Up @@ -341,6 +350,10 @@ def _py_wheel_impl(ctx):
args.add("--stable_status_file", ctx.info_file)
other_inputs.extend([ctx.version_file, ctx.info_file])

if ctx.attr.custom_properties:
args.add("--custom_properties", ctx.file.custom_properties)
other_inputs.extend([ctx.file.custom_properties])

args.add("--input_file_list", packageinputfile)

# Note: Description file and version are not embedded into metadata.txt yet,
Expand Down
48 changes: 27 additions & 21 deletions tools/wheelmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,22 +327,27 @@ def get_files_to_package(input_files):


def resolve_argument_stamp(
argument: str, volatile_status_stamp: Path, stable_status_stamp: Path
argument: str, volatile_status_stamp: Path, stable_status_stamp: Path, custom_properties: Path
) -> str:
"""Resolve workspace status stamps format strings found in the argument string
Args:
argument (str): The raw argument represenation for the wheel (may include stamp variables)
volatile_status_stamp (Path): The path to a volatile workspace status file
stable_status_stamp (Path): The path to a stable workspace status file
custom_properties (Path): The path to custom properties file. eg: file containing generated version variable
Returns:
str: A resolved argument string
"""
lines = (
volatile_status_stamp.read_text().splitlines()
+ stable_status_stamp.read_text().splitlines()
)
lines = []
if volatile_status_stamp:
lines.extend(volatile_status_stamp.read_text().splitlines())
if stable_status_stamp:
lines.extend(stable_status_stamp.read_text().splitlines())
if custom_properties:
lines.extend(custom_properties.read_text().splitlines())

for line in lines:
if not line:
continue
Expand All @@ -362,6 +367,11 @@ def parse_args() -> argparse.Namespace:
metadata_group.add_argument(
"--version", required=True, type=str, help="Version of the distribution"
)
metadata_group.add_argument(
"--custom_properties",
type=Path,
help="A file containing user defined properties",
)
metadata_group.add_argument(
"--build_tag",
type=str,
Expand Down Expand Up @@ -478,23 +488,19 @@ def main() -> None:

strip_prefixes = [p for p in arguments.strip_path_prefix]

if arguments.volatile_status_file and arguments.stable_status_file:
name = resolve_argument_stamp(
arguments.name,
arguments.volatile_status_file,
arguments.stable_status_file,
)
else:
name = arguments.name
name = resolve_argument_stamp(
arguments.name,
arguments.volatile_status_file,
arguments.stable_status_file,
arguments.custom_properties
)

if arguments.volatile_status_file and arguments.stable_status_file:
version = resolve_argument_stamp(
arguments.version,
arguments.volatile_status_file,
arguments.stable_status_file,
)
else:
version = arguments.version
version = resolve_argument_stamp(
arguments.version,
arguments.volatile_status_file,
arguments.stable_status_file,
arguments.custom_properties
)

with WheelMaker(
name=name,
Expand Down

0 comments on commit e79fea6

Please sign in to comment.