Skip to content

Commit c9dacd5

Browse files
authored
Merge pull request #1103 from pulp/patchback/backports/3.25/13e60a9e99e2135e9ab80d53fd198ae59fb880ee/pr-1102
[PR #1102/13e60a9e backport][3.25] [PULP-1200] Fix edge case when creating metadata file
2 parents e81e927 + 37d040c commit c9dacd5

File tree

7 files changed

+24
-10
lines changed

7 files changed

+24
-10
lines changed

CHANGES/1101.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed edge case where metadata file did not match wheel metadata.

pulp_python/app/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,12 @@ def extract_wheel_metadata(filename: str) -> bytes | None:
220220
return None
221221
try:
222222
with zipfile.ZipFile(filename, "r") as f:
223-
for file_path in f.namelist():
224-
if file_path.endswith(".dist-info/METADATA"):
225-
return f.read(file_path)
223+
metadata_paths = [p for p in f.namelist() if p.endswith("METADATA")]
224+
sorted_paths = sorted(metadata_paths, key=lambda s: s.count("/"))
225+
for metadata_path in sorted_paths:
226+
file = f.read(metadata_path)
227+
if b"Metadata-Version" in file:
228+
return file
226229
except (zipfile.BadZipFile, KeyError, OSError) as e:
227230
log.warning(f"Failed to extract metadata file from {filename}: {e}")
228231
return None

pulp_python/tests/functional/api/test_crud_content_unit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,6 @@ def test_package_creation_with_metadata(
200200
distro = python_distribution_factory(repository=python_repo)
201201

202202
# Test that metadata is accessible
203-
ensure_metadata(pulp_content_url, distro.base_path, PYTHON_WHEEL_FILENAME)
203+
ensure_metadata(
204+
pulp_content_url, distro.base_path, PYTHON_WHEEL_FILENAME, "shelf-reader", "0.1"
205+
)

pulp_python/tests/functional/api/test_pypi_apis.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ def test_package_upload_with_metadata(
165165
assert summary.added["python.python"]["count"] == 1
166166

167167
# Test that metadata is accessible
168-
ensure_metadata(pulp_content_url, distro.base_path, PYTHON_WHEEL_FILENAME)
168+
ensure_metadata(
169+
pulp_content_url, distro.base_path, PYTHON_WHEEL_FILENAME, "shelf-reader", "0.1"
170+
)
169171

170172

171173
@pytest.mark.parallel

pulp_python/tests/functional/api/test_sync.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,6 @@ def test_package_sync_with_metadata(
354354
distro = python_distribution_factory(repository=repo)
355355

356356
# Test that metadata is accessible
357-
ensure_metadata(pulp_content_url, distro.base_path, "pytz-2023.2-py2.py3-none-any.whl")
357+
ensure_metadata(
358+
pulp_content_url, distro.base_path, "pytz-2023.2-py2.py3-none-any.whl", "pytz", "2023.2"
359+
)

pulp_python/tests/functional/api/test_upload.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pulp_python.tests.functional.constants import (
44
PYTHON_EGG_FILENAME,
55
PYTHON_EGG_URL,
6+
PYTHON_FIXTURES_URL,
67
PYTHON_WHEEL_FILENAME,
78
PYTHON_WHEEL_URL,
89
PYTHON_EGG_SHA256,
@@ -61,7 +62,9 @@ def test_synchronous_package_upload_with_metadata(
6162
"""
6263
Test that the synchronous upload of a Python wheel package creates a metadata artifact.
6364
"""
64-
python_file = download_python_file(PYTHON_WHEEL_FILENAME, PYTHON_WHEEL_URL)
65+
wheel_filename = "setuptools-80.9.0-py3-none-any.whl"
66+
wheel_url = urljoin(urljoin(PYTHON_FIXTURES_URL, "packages/"), wheel_filename)
67+
python_file = download_python_file(wheel_filename, wheel_url)
6568
content_body = {"file": python_file}
6669
content = python_bindings.ContentPackagesApi.upload(**content_body)
6770

@@ -70,7 +73,7 @@ def test_synchronous_package_upload_with_metadata(
7073
distro = python_distribution_factory(repository=python_repo)
7174

7275
# Test that metadata is accessible
73-
ensure_metadata(pulp_content_url, distro.base_path, PYTHON_WHEEL_FILENAME)
76+
ensure_metadata(pulp_content_url, distro.base_path, wheel_filename, "setuptools", "80.9.0")
7477

7578

7679
@pytest.mark.parallel

pulp_python/tests/functional/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def explore_links(page_url, page_name, links_found, msgs):
123123
return len(msgs) == 0, msgs
124124

125125

126-
def ensure_metadata(pulp_content_url, distro_base_path, filename):
126+
def ensure_metadata(pulp_content_url, distro_base_path, filename, name, version):
127127
"""
128128
Tests that metadata is accessible for a given wheel package filename.
129129
"""
@@ -132,4 +132,5 @@ def ensure_metadata(pulp_content_url, distro_base_path, filename):
132132
metadata_response = requests.get(metadata_url)
133133
assert metadata_response.status_code == 200
134134
assert len(metadata_response.content) > 0
135-
assert "Name: " in metadata_response.text
135+
assert f"Name: {name}" in metadata_response.text
136+
assert f"Version: {version}" in metadata_response.text

0 commit comments

Comments
 (0)