-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from HexDecimal/fix-135
MRG: Replicate the to-be-removed `wheel.pkginfo` module. The plans to remove the `wheel.pkginfo` module can be negotiated with the `wheel` devs, but this PR should cause less drama. Adds `delocate.pkginfo` to read/write these files, based on the original module. Removes code supporting `wheel<0.32.0`. Adds code to support the unreleased versions of `wheel>0.37.1`. Adds type hinting to the relevant functions. Closes #135
- Loading branch information
Showing
5 changed files
with
42 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Tools for reading and writing PKG-INFO / METADATA without caring | ||
about the encoding. | ||
This is based on a copy of the old wheel.pkginfo module. | ||
""" | ||
from email.generator import Generator | ||
from email.message import Message | ||
from email.parser import Parser | ||
from os import PathLike | ||
from typing import Union | ||
|
||
|
||
def read_pkg_info_bytes(bytestr: Union[bytes, str]) -> Message: | ||
"""Parse a PKG-INFO or METADATA data string.""" | ||
if isinstance(bytestr, bytes): | ||
bytestr = bytestr.decode("utf-8") | ||
return Parser().parsestr(bytestr) | ||
|
||
|
||
def read_pkg_info(path: Union[bytes, str, PathLike]) -> Message: | ||
"""Read a PKG-INFO or METADATA file.""" | ||
with open(path, encoding="utf-8") as headers: | ||
return Parser().parse(headers) | ||
|
||
|
||
def write_pkg_info(path: Union[bytes, str, PathLike], message: Message) -> None: | ||
"""Write to a PKG-INFO or METADATA file.""" | ||
with open(path, "w", encoding="utf-8") as out: | ||
Generator(out, mangle_from_=False, maxheaderlen=0).flatten(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters