Skip to content

Commit ed2d65f

Browse files
committed
Adding variable support for distribution in py_wheel
1 parent 28e15c2 commit ed2d65f

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

docs/packaging.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/private/py_wheel.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ Name of the distribution.
4040
4141
This should match the project name onm PyPI. It's also the name that is used to
4242
refer to the package in other packages' dependencies.
43+
44+
Note that this attribute supports 'make variables'.
45+
For example:
46+
- `distribution = "package.{CLASSIFIER}"`
47+
- `distribution = "{DISTRIBUTION}"`
48+
- `distribution = "$(PACKAGE_NAME)"`
4349
""",
4450
),
4551
"platform": attr.string(

tools/wheelmaker.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ def add_wheelfile(self):
167167
wheel_contents += "Tag: %s\n" % tag
168168
self.add_string(self.distinfo_path("WHEEL"), wheel_contents)
169169

170-
def add_metadata(self, metadata, description, version):
170+
def add_metadata(self, metadata, name, description, version):
171171
"""Write METADATA file to the distribution."""
172172
# https://www.python.org/dev/peps/pep-0566/
173173
# https://packaging.python.org/specifications/core-metadata/
174-
metadata += "Version: " + version
175-
metadata += "\n\n"
174+
metadata = re.sub("^Name: .*$", "Name: %s" % name, metadata, flags=re.MULTILINE)
175+
metadata += "Version: %s\n\n" % version
176176
# setuptools seems to insert UNKNOWN as description when none is
177177
# provided.
178178
metadata += description if description else "UNKNOWN"
@@ -207,18 +207,18 @@ def get_files_to_package(input_files):
207207
return files
208208

209209

210-
def resolve_version_stamp(
211-
version: str, volatile_status_stamp: Path, stable_status_stamp: Path
210+
def resolve_argument_stamp(
211+
argument: str, volatile_status_stamp: Path, stable_status_stamp: Path
212212
) -> str:
213-
"""Resolve workspace status stamps format strings found in the version string
213+
"""Resolve workspace status stamps format strings found in the argument string
214214
215215
Args:
216-
version (str): The raw version represenation for the wheel (may include stamp variables)
216+
argument (str): The raw argument represenation for the wheel (may include stamp variables)
217217
volatile_status_stamp (Path): The path to a volatile workspace status file
218218
stable_status_stamp (Path): The path to a stable workspace status file
219219
220220
Returns:
221-
str: A resolved version string
221+
str: A resolved argument string
222222
"""
223223
lines = (
224224
volatile_status_stamp.read_text().splitlines()
@@ -229,9 +229,9 @@ def resolve_version_stamp(
229229
continue
230230
key, value = line.split(" ", maxsplit=1)
231231
stamp = "{" + key + "}"
232-
version = version.replace(stamp, value)
232+
argument = argument.replace(stamp, value)
233233

234-
return version
234+
return argument
235235

236236

237237
def parse_args() -> argparse.Namespace:
@@ -357,7 +357,16 @@ def main() -> None:
357357
strip_prefixes = [p for p in arguments.strip_path_prefix]
358358

359359
if arguments.volatile_status_file and arguments.stable_status_file:
360-
version = resolve_version_stamp(
360+
name = resolve_argument_stamp(
361+
arguments.name,
362+
arguments.volatile_status_file,
363+
arguments.stable_status_file,
364+
)
365+
else:
366+
name = arguments.name
367+
368+
if arguments.volatile_status_file and arguments.stable_status_file:
369+
version = resolve_argument_stamp(
361370
arguments.version,
362371
arguments.volatile_status_file,
363372
arguments.stable_status_file,
@@ -366,7 +375,7 @@ def main() -> None:
366375
version = arguments.version
367376

368377
with WheelMaker(
369-
name=arguments.name,
378+
name=name,
370379
version=version,
371380
build_tag=arguments.build_tag,
372381
python_tag=arguments.python_tag,
@@ -398,7 +407,9 @@ def main() -> None:
398407
with open(arguments.metadata_file, "rt", encoding="utf-8") as metadata_file:
399408
metadata = metadata_file.read()
400409

401-
maker.add_metadata(metadata=metadata, description=description, version=version)
410+
maker.add_metadata(
411+
metadata=metadata, name=name, description=description, version=version
412+
)
402413

403414
if arguments.entry_points_file:
404415
maker.add_file(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy