Skip to content

Commit fbbfbfb

Browse files
committed
Preserve original PKG-INFO as METADATA in bdist_wheel
1 parent 48fd9ba commit fbbfbfb

File tree

1 file changed

+24
-38
lines changed

1 file changed

+24
-38
lines changed

setuptools/command/bdist_wheel.py

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
import sysconfig
1515
import warnings
1616
from collections.abc import Iterable, Sequence
17-
from email.generator import BytesGenerator, Generator
18-
from email.policy import EmailPolicy
17+
from email.generator import BytesGenerator
1918
from glob import iglob
2019
from typing import Literal, cast
2120
from zipfile import ZIP_DEFLATED, ZIP_STORED
2221

2322
from packaging import tags, version as _packaging_version
24-
from wheel.metadata import pkginfo_to_metadata
2523
from wheel.wheelfile import WheelFile
2624

2725
from .. import Command, __version__, _shutil
@@ -569,42 +567,30 @@ def adios(p: str) -> None:
569567

570568
raise ValueError(err)
571569

572-
if os.path.isfile(egginfo_path):
573-
# .egg-info is a single file
574-
pkg_info = pkginfo_to_metadata(egginfo_path, egginfo_path)
575-
os.mkdir(distinfo_path)
576-
else:
577-
# .egg-info is a directory
578-
pkginfo_path = os.path.join(egginfo_path, "PKG-INFO")
579-
pkg_info = pkginfo_to_metadata(egginfo_path, pkginfo_path)
580-
581-
# ignore common egg metadata that is useless to wheel
582-
shutil.copytree(
583-
egginfo_path,
584-
distinfo_path,
585-
ignore=lambda x, y: {
586-
"PKG-INFO",
587-
"requires.txt",
588-
"SOURCES.txt",
589-
"not-zip-safe",
590-
},
591-
)
592-
593-
# delete dependency_links if it is only whitespace
594-
dependency_links_path = os.path.join(distinfo_path, "dependency_links.txt")
595-
with open(dependency_links_path, encoding="utf-8") as dependency_links_file:
596-
dependency_links = dependency_links_file.read().strip()
597-
if not dependency_links:
598-
adios(dependency_links_path)
599-
600-
pkg_info_path = os.path.join(distinfo_path, "METADATA")
601-
serialization_policy = EmailPolicy(
602-
utf8=True,
603-
mangle_from_=False,
604-
max_line_length=0,
570+
# .egg-info is a directory
571+
pkginfo_path = os.path.join(egginfo_path, "PKG-INFO")
572+
573+
# ignore common egg metadata that is useless to wheel
574+
shutil.copytree(
575+
egginfo_path,
576+
distinfo_path,
577+
ignore=lambda x, y: {
578+
"PKG-INFO",
579+
"requires.txt",
580+
"SOURCES.txt",
581+
"not-zip-safe",
582+
},
605583
)
606-
with open(pkg_info_path, "w", encoding="utf-8") as out:
607-
Generator(out, policy=serialization_policy).flatten(pkg_info)
584+
585+
# delete dependency_links if it is only whitespace
586+
dependency_links_path = os.path.join(distinfo_path, "dependency_links.txt")
587+
with open(dependency_links_path, encoding="utf-8") as dependency_links_file:
588+
dependency_links = dependency_links_file.read().strip()
589+
if not dependency_links:
590+
adios(dependency_links_path)
591+
592+
metadata_path = os.path.join(distinfo_path, "METADATA")
593+
shutil.copy(pkginfo_path, metadata_path)
608594

609595
for license_path in self.license_paths:
610596
filename = os.path.basename(license_path)

0 commit comments

Comments
 (0)