-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a public API #472
Closed
Add a public API #472
Changes from 53 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
d5969f0
Replaced old WheelFile with the proposed new one
agronholm a388212
Added support for using WheelFile with existing file handles
agronholm 376cf99
Use posixpath.join() to put together archive names
agronholm b03dde9
Removed PathLike support from write_file and added the timestamp argu…
agronholm 0fd872d
Don't test on Python 2.7
agronholm eb0e459
Removed the write_files_from_directory() method
agronholm fac7e16
Renamed write_metadata_file() to write_distinfo_file()
agronholm fe39329
Renamed read_metadata_file() to read_distinfo_file()
agronholm 96b88b5
Reverted the use of posixpath.join()
agronholm 3a3d731
Removed more Python 2 configuration
agronholm a975348
Added special support for the METADATA file
agronholm f79c25e
Removed the test workflow trigger for PRs
agronholm b2d7029
Refactored bdist_wheel to use the new WheelFile API
agronholm e7fe9bb
Refactored test suite and CLI tools to use tmp_path
agronholm d7b1f1d
Added the py.typed marker
agronholm 4654492
Removed obsolete modules
agronholm 6591155
Added type annotations to macosx_libfile
agronholm 3667709
Fixed a few WheelFile tests
agronholm 9e63bec
Restored Python 3.5 compatibility to WheelFile
agronholm cbca67e
Added Python 3.7 to the testing matrix
agronholm bf0afca
Updated the Github publish workflow
agronholm 71474a5
Updated the Github codeqa/test workflow
agronholm da30173
Merge branch 'master' into publicapi
agronholm ec0aded
Removed Python 3.5 support
agronholm f1a5fd4
WIP refactored the Wheel API
agronholm fa01be4
Merge branch 'main' into publicapi
agronholm a2a53de
Improved the API and dropped bdist_wininst convert support
agronholm 34f05ae
Removed install dependency on setuptools
agronholm 85ac7c5
Updated version number
agronholm e3934a9
Switched to running coverage using "python -m"
agronholm 946f7f9
Fixed no files beside .egg-info being added by bdist_wheel
agronholm b69c2bc
Fixed test_write_file
agronholm a2ca178
Added setuptools as test dependency
agronholm c7167fe
Fixed deprecated pytest imports
agronholm f4aff15
Made most wheel modules private
agronholm 29a5dfc
Made all remaining modules private
agronholm 9f268c3
Changed the default value for amount in WheelArchiveFile.read() to -1
agronholm c85a333
Fixed import in wheel.__main__
agronholm 31d0dc9
Fixed the most critical type issues and added a MyPy check to CI (#473)
HexDecimal 81471ec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ef1425d
Removed unused module
agronholm 71efa9b
Updated the docs for "wheel convert"
agronholm c2171c2
Updated CLI help, type annotations and string interpolation
agronholm 122f456
Made WheelContentElement into a named tuple
agronholm d14b5fc
Removed obsolete options
agronholm 9f2bfc6
Fixed mypy error
agronholm edcb325
Added tests to type checking and finish annotations. (#477)
HexDecimal 914cc81
Merged the license_paths property back to run()
agronholm cad0948
Merge branch 'main' into publicapi
agronholm ea9086a
Removed obsolete test
agronholm 13ae2b6
Re-added test accidentally removed during merge
agronholm 21256df
Merge branch 'main' into publicapi
agronholm b432977
Moved the bdist_wheel module back to its original location
agronholm 14ca7de
Renamed test() to validate_record()
agronholm ee91735
Merge branch 'main' into publicapi
agronholm d5c7dc3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] eb12145
Added a fix for #489
agronholm 91d0e2e
Fixed cache not being used on Windows and macOS in the test workflow
agronholm 9a18f66
Merge branch 'main' into publicapi
agronholm d783f6b
Added compatibility shim for wheel.wheelfile
agronholm ff85f76
Added automatic detection of .dist-info directory
agronholm 6892de4
Refactored code to make mypy happy
agronholm 513f1f7
Refactored pkg_resources imports
agronholm 09c5f64
Fixed the rest of mypy errors
agronholm 59fd006
Added a standalone function for writing a WHEEL file
agronholm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
__version__ = "0.38.2" | ||
__all__ = ["WheelError", "WheelReader", "WheelWriter", "make_filename"] | ||
__version__ = "1.0.0a1" | ||
|
||
from ._wheelfile import WheelError, WheelReader, WheelWriter, make_filename |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import re | ||
import zipfile | ||
from collections.abc import Generator, Iterable | ||
from email.message import Message | ||
from email.parser import HeaderParser | ||
from os import PathLike | ||
from pathlib import Path, PurePath | ||
from typing import IO, Any | ||
|
||
from .. import WheelWriter, make_filename | ||
from . import WheelError | ||
|
||
egg_info_re = re.compile( | ||
r""" | ||
(?P<name>.+?)-(?P<ver>.+?) | ||
(-(?P<pyver>py\d\.\d+) | ||
(-(?P<arch>.+?))? | ||
)?.egg$""", | ||
re.VERBOSE, | ||
) | ||
|
||
|
||
def egg2wheel(egg_path: Path, dest_dir: Path) -> None: | ||
def egg_file_source() -> Generator[tuple[PurePath, IO[bytes]], Any, None]: | ||
with zipfile.ZipFile(egg_path) as zf: | ||
for zinfo in zf.infolist(): | ||
with zf.open(zinfo) as fp: | ||
yield PurePath(zinfo.filename), fp | ||
|
||
def egg_dir_source() -> Generator[tuple[PurePath, IO[bytes]], Any, None]: | ||
for root, _dirs, files in os.walk(egg_path, followlinks=False): | ||
root_path = Path(root) | ||
for fname in files: | ||
file_path = root_path / fname | ||
with file_path.open("rb") as fp: | ||
yield file_path, fp | ||
|
||
match = egg_info_re.match(egg_path.name) | ||
if not match: | ||
raise WheelError(f"Invalid egg file name: {egg_path.name}") | ||
|
||
# Assume pure Python if there is no specified architecture | ||
# Assume all binary eggs are for CPython | ||
egg_info = match.groupdict() | ||
pyver = egg_info["pyver"].replace(".", "") | ||
arch = (egg_info["arch"] or "any").replace(".", "_").replace("-", "_") | ||
abi = "cp" + pyver[2:] if arch != "any" else "none" | ||
root_is_purelib = arch is None | ||
|
||
if egg_path.is_dir(): | ||
# buildout-style installed eggs directory | ||
source = egg_dir_source() | ||
else: | ||
source = egg_file_source() | ||
|
||
wheel_name = make_filename( | ||
egg_info["name"], egg_info["ver"], impl_tag=pyver, abi_tag=abi, plat_tag=arch | ||
) | ||
metadata = Message() | ||
with WheelWriter( | ||
dest_dir / wheel_name, generator="egg2wheel", root_is_purelib=root_is_purelib | ||
) as wf: | ||
for path, fp in source: | ||
if path.parts[0] == "EGG-INFO": | ||
if path.parts[1] == "requires.txt": | ||
requires = fp.read().decode("utf-8") | ||
extra = specifier = "" | ||
for line in requires.splitlines(): | ||
line = line.strip() | ||
if line.startswith("[") and line.endswith("]"): | ||
extra, _, specifier = line[1:-1].strip().partition(":") | ||
metadata["Provides-Extra"] = extra | ||
elif line: | ||
specifiers: list[str] = [] | ||
if extra: | ||
specifiers += f"extra == {extra!r}" | ||
|
||
if specifier: | ||
specifiers += specifier | ||
|
||
if specifiers: | ||
line = line + " ; " + " and ".join(specifiers) | ||
|
||
metadata["Requires-Dist"] = line | ||
elif path.parts[1] in ("entry_points.txt", "top_level.txt"): | ||
wf.write_distinfo_file(path.parts[1], fp) | ||
elif path.parts[1] == "PKG-INFO": | ||
pkg_info = HeaderParser().parsestr(fp.read().decode("utf-8")) | ||
pkg_info.replace_header("Metadata-Version", "2.1") | ||
del pkg_info["Provides-Extra"] | ||
del pkg_info["Requires-Dist"] | ||
for header, value in pkg_info.items(): | ||
metadata[header] = value | ||
else: | ||
wf.write_file(path, fp) | ||
|
||
if metadata: | ||
wf.write_metadata(metadata.items()) | ||
|
||
|
||
def convert( | ||
files: Iterable[str | PathLike[str]], dest_dir: str | PathLike[str], verbose: bool | ||
) -> None: | ||
dest_path = Path(dest_dir) | ||
paths: list[Path] = [] | ||
for fname in files: | ||
path = Path(fname) | ||
if path.is_file(): | ||
paths.append(path) | ||
elif path.is_dir(): | ||
paths.extend(path.iterdir()) | ||
|
||
for path in paths: | ||
if path.suffix != ".egg": | ||
continue | ||
|
||
if verbose: | ||
print(f"{path}... ", flush=True) | ||
|
||
egg2wheel(path, dest_path) | ||
|
||
if verbose: | ||
print("OK") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logically it makes sense to separate these out but is is necessarily worth it? The additional install time is so trivial for the small amount of dependencies so I'm just not sure its really worth the split. It also makes the CI caching harder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you talking about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you mean the separation of test and typing dependencies? That wasn't actually done by me, and I'm still not 100% convinced that we shouldn't be using pre-commit for that. It's not critical either way, and I don't see any particular issues that it would cause for caching. I could of course be convinced otherwise.