From 7351614c4850398689055ab3056b937d1abb1012 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Mon, 21 Apr 2025 23:09:13 +0000 Subject: [PATCH 1/3] fix: parsing metadata with inline licenses Fixes https://github.com/bazel-contrib/rules_python/issues/2796 --- python/private/pypi/whl_metadata.bzl | 2 +- .../pypi/whl_metadata/whl_metadata_tests.bzl | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/python/private/pypi/whl_metadata.bzl b/python/private/pypi/whl_metadata.bzl index 8a86ffbff1..cf2d51afda 100644 --- a/python/private/pypi/whl_metadata.bzl +++ b/python/private/pypi/whl_metadata.bzl @@ -52,7 +52,7 @@ def parse_whl_metadata(contents): "version": "", } for line in contents.strip().split("\n"): - if not line.strip(): + if not line: # Stop parsing on first empty line, which marks the end of the # headers containing the metadata. break diff --git a/tests/pypi/whl_metadata/whl_metadata_tests.bzl b/tests/pypi/whl_metadata/whl_metadata_tests.bzl index 4acbc9213d..329423a26c 100644 --- a/tests/pypi/whl_metadata/whl_metadata_tests.bzl +++ b/tests/pypi/whl_metadata/whl_metadata_tests.bzl @@ -140,6 +140,37 @@ Requires-Dist: this will be ignored _tests.append(_test_parse_metadata_all) +def _test_parse_metadata_multiline_license(env): + got = _parse_whl_metadata( + env, + # NOTE: The trailing whitespace here is meaningful as an empty line + # denotes the end of the header. + contents = """\ +Name: foo +Version: 0.0.1 +License: some License + + some line + + another line + +Requires-Dist: bar; extra == "all" +Provides-Extra: all + +Requires-Dist: this will be ignored +""", + ) + got.name().equals("foo") + got.version().equals("0.0.1") + got.requires_dist().contains_exactly([ + "bar; extra == \"all\"", + ]) + got.provides_extra().contains_exactly([ + "all", + ]) + +_tests.append(_test_parse_metadata_multiline_license) + def whl_metadata_test_suite(name): # buildifier: disable=function-docstring test_suite( name = name, From 167131bb13d5ce8b3dc26ca6ecf30318a9ba774f Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Tue, 22 Apr 2025 21:21:12 +0900 Subject: [PATCH 2/3] parse the whole METADATA file for Requires-Dist entries --- python/private/pypi/whl_metadata.bzl | 5 ----- tests/pypi/whl_metadata/whl_metadata_tests.bzl | 6 ++++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/python/private/pypi/whl_metadata.bzl b/python/private/pypi/whl_metadata.bzl index cf2d51afda..febaa51158 100644 --- a/python/private/pypi/whl_metadata.bzl +++ b/python/private/pypi/whl_metadata.bzl @@ -52,11 +52,6 @@ def parse_whl_metadata(contents): "version": "", } for line in contents.strip().split("\n"): - if not line: - # Stop parsing on first empty line, which marks the end of the - # headers containing the metadata. - break - if line.startswith(_NAME): _, _, value = line.partition(_NAME) parsed["name"] = value.strip() diff --git a/tests/pypi/whl_metadata/whl_metadata_tests.bzl b/tests/pypi/whl_metadata/whl_metadata_tests.bzl index 329423a26c..f64e98a467 100644 --- a/tests/pypi/whl_metadata/whl_metadata_tests.bzl +++ b/tests/pypi/whl_metadata/whl_metadata_tests.bzl @@ -126,13 +126,14 @@ Version: 0.0.1 Requires-Dist: bar; extra == "all" Provides-Extra: all -Requires-Dist: this will be ignored +Requires-Dist: baz """, ) got.name().equals("foo") got.version().equals("0.0.1") got.requires_dist().contains_exactly([ "bar; extra == \"all\"", + "baz", ]) got.provides_extra().contains_exactly([ "all", @@ -157,13 +158,14 @@ License: some License Requires-Dist: bar; extra == "all" Provides-Extra: all -Requires-Dist: this will be ignored +Requires-Dist: baz """, ) got.name().equals("foo") got.version().equals("0.0.1") got.requires_dist().contains_exactly([ "bar; extra == \"all\"", + "baz", ]) got.provides_extra().contains_exactly([ "all", From 889f80c31c91f76a8157c908087f9924c0ab1699 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Tue, 22 Apr 2025 21:40:12 +0900 Subject: [PATCH 3/3] Revert "parse the whole METADATA file for Requires-Dist entries" This reverts commit 167131bb13d5ce8b3dc26ca6ecf30318a9ba774f. --- python/private/pypi/whl_metadata.bzl | 5 +++++ tests/pypi/whl_metadata/whl_metadata_tests.bzl | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/python/private/pypi/whl_metadata.bzl b/python/private/pypi/whl_metadata.bzl index febaa51158..cf2d51afda 100644 --- a/python/private/pypi/whl_metadata.bzl +++ b/python/private/pypi/whl_metadata.bzl @@ -52,6 +52,11 @@ def parse_whl_metadata(contents): "version": "", } for line in contents.strip().split("\n"): + if not line: + # Stop parsing on first empty line, which marks the end of the + # headers containing the metadata. + break + if line.startswith(_NAME): _, _, value = line.partition(_NAME) parsed["name"] = value.strip() diff --git a/tests/pypi/whl_metadata/whl_metadata_tests.bzl b/tests/pypi/whl_metadata/whl_metadata_tests.bzl index f64e98a467..329423a26c 100644 --- a/tests/pypi/whl_metadata/whl_metadata_tests.bzl +++ b/tests/pypi/whl_metadata/whl_metadata_tests.bzl @@ -126,14 +126,13 @@ Version: 0.0.1 Requires-Dist: bar; extra == "all" Provides-Extra: all -Requires-Dist: baz +Requires-Dist: this will be ignored """, ) got.name().equals("foo") got.version().equals("0.0.1") got.requires_dist().contains_exactly([ "bar; extra == \"all\"", - "baz", ]) got.provides_extra().contains_exactly([ "all", @@ -158,14 +157,13 @@ License: some License Requires-Dist: bar; extra == "all" Provides-Extra: all -Requires-Dist: baz +Requires-Dist: this will be ignored """, ) got.name().equals("foo") got.version().equals("0.0.1") got.requires_dist().contains_exactly([ "bar; extra == \"all\"", - "baz", ]) got.provides_extra().contains_exactly([ "all", 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