diff options
| author | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-12-25 14:58:07 +0200 |
|---|---|---|
| committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-12-25 14:58:07 +0200 |
| commit | 4c87d582dd09af927ede6ff9b86ddd745f4393e7 (patch) | |
| tree | dad7b320dff09b264090e8e8c95469ceeea21474 /src | |
| parent | 0c061c3b3478ae2ebefa178fbf7624860eb231e9 (diff) | |
| download | wheel-git-4c87d582dd09af927ede6ff9b86ddd745f4393e7.tar.gz | |
Eliminated the pkg_info module
The two functions previously contained within the module were inline to the only places where they were used.
We also now assume PKG-INFO is UTF-8 encoded, as distutils has done since 2012.
Diffstat (limited to 'src')
| -rw-r--r-- | src/wheel/bdist_wheel.py | 7 | ||||
| -rw-r--r-- | src/wheel/metadata.py | 7 | ||||
| -rw-r--r-- | src/wheel/pkginfo.py | 17 |
3 files changed, 8 insertions, 23 deletions
diff --git a/src/wheel/bdist_wheel.py b/src/wheel/bdist_wheel.py index cdea46d..feddd38 100644 --- a/src/wheel/bdist_wheel.py +++ b/src/wheel/bdist_wheel.py @@ -14,7 +14,7 @@ import warnings from collections import OrderedDict from distutils import log as logger from distutils.core import Command -from email.generator import BytesGenerator +from email.generator import BytesGenerator, Generator from glob import iglob from io import BytesIO from shutil import rmtree @@ -26,7 +26,6 @@ import pkg_resources from . import __version__ as wheel_version from .macosx_libfile import calculate_macosx_platform_tag from .metadata import pkginfo_to_metadata -from .pkginfo import write_pkg_info from .vendored.packaging import tags from .wheelfile import WheelFile @@ -522,7 +521,9 @@ class bdist_wheel(Command): if not dependency_links: adios(dependency_links_path) - write_pkg_info(os.path.join(distinfo_path, "METADATA"), pkg_info) + pkg_info_path = os.path.join(distinfo_path, "METADATA") + with open(pkg_info_path, "w", encoding="utf-8") as out: + Generator(out, mangle_from_=False, maxheaderlen=0).flatten(pkg_info) for license_path in self.license_paths: filename = os.path.basename(license_path) diff --git a/src/wheel/metadata.py b/src/wheel/metadata.py index ace796d..23ccea1 100644 --- a/src/wheel/metadata.py +++ b/src/wheel/metadata.py @@ -4,11 +4,10 @@ Tools for converting old- to new-style metadata. import os.path import textwrap +from email.parser import Parser import pkg_resources -from .pkginfo import read_pkg_info - def requires_to_requires_dist(requirement): """Return the version specifier for a requirement in PEP 345/566 fashion.""" @@ -66,7 +65,9 @@ def pkginfo_to_metadata(egg_info_path, pkginfo_path): """ Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format """ - pkg_info = read_pkg_info(pkginfo_path) + with open(pkginfo_path, encoding="utf-8") as headers: + pkg_info = Parser().parse(headers) + pkg_info.replace_header("Metadata-Version", "2.1") # Those will be regenerated from `requires.txt`. del pkg_info["Provides-Extra"] diff --git a/src/wheel/pkginfo.py b/src/wheel/pkginfo.py deleted file mode 100644 index 9ca2a54..0000000 --- a/src/wheel/pkginfo.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Tools for reading and writing PKG-INFO / METADATA without caring -about the encoding.""" - -from email.generator import BytesGenerator -from email.parser import Parser - - -def read_pkg_info(path): - with open(path, encoding="ascii", errors="surrogateescape") as headers: - message = Parser().parse(headers) - - return message - - -def write_pkg_info(path, message): - with open(path, "wb") as out: - BytesGenerator(out, mangle_from_=False, maxheaderlen=0).flatten(message) |
