py2docfx 0.1.11.dev1824276__py3-none-any.whl → 0.1.11.dev1827111__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py2docfx/convert_prepare/environment.py +1 -1
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/_collections.py +0 -145
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/bcppcompiler.py +1 -2
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/ccompiler.py +7 -11
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/bdist.py +4 -3
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/build_ext.py +1 -4
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/check.py +3 -4
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/install_data.py +39 -29
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/install_lib.py +1 -3
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/sdist.py +4 -4
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/compat/py38.py +1 -0
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/cygwinccompiler.py +21 -42
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/dist.py +3 -12
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/extension.py +9 -4
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/msvc9compiler.py +1 -3
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/msvccompiler.py +1 -3
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/spawn.py +0 -1
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/sysconfig.py +44 -25
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_archive_util.py +1 -1
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_build.py +1 -2
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_build_ext.py +1 -1
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_cygwinccompiler.py +0 -42
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_dist.py +1 -1
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_extension.py +4 -1
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_install_data.py +17 -9
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_mingwccompiler.py +5 -4
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_spawn.py +1 -1
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_sysconfig.py +6 -3
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_unixccompiler.py +35 -1
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_util.py +4 -24
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/unixccompiler.py +19 -20
- py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/util.py +20 -26
- py2docfx/venv/0/Lib/site-packages/wheel/__init__.py +3 -0
- py2docfx/venv/0/Lib/site-packages/wheel/__main__.py +23 -0
- py2docfx/venv/0/Lib/site-packages/wheel/_bdist_wheel.py +604 -0
- py2docfx/venv/0/Lib/site-packages/wheel/_setuptools_logging.py +26 -0
- py2docfx/venv/0/Lib/site-packages/wheel/bdist_wheel.py +11 -0
- py2docfx/venv/0/Lib/site-packages/wheel/cli/__init__.py +155 -0
- py2docfx/venv/0/Lib/site-packages/wheel/cli/convert.py +273 -0
- py2docfx/venv/0/Lib/site-packages/wheel/cli/pack.py +85 -0
- py2docfx/venv/0/Lib/site-packages/wheel/cli/tags.py +139 -0
- py2docfx/venv/0/Lib/site-packages/wheel/cli/unpack.py +30 -0
- py2docfx/venv/0/Lib/site-packages/wheel/macosx_libfile.py +482 -0
- py2docfx/venv/0/Lib/site-packages/wheel/metadata.py +183 -0
- py2docfx/venv/0/Lib/site-packages/wheel/util.py +26 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/__init__.py +0 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/__init__.py +0 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_elffile.py +108 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_manylinux.py +260 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_musllinux.py +83 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_parser.py +356 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_structures.py +61 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_tokenizer.py +192 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/markers.py +253 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/requirements.py +90 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/specifiers.py +1011 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/tags.py +571 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/utils.py +172 -0
- py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/version.py +561 -0
- py2docfx/venv/0/Lib/site-packages/wheel/wheelfile.py +227 -0
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/_collections.py +0 -145
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/bcppcompiler.py +1 -2
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/ccompiler.py +7 -11
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/bdist.py +4 -3
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/build_ext.py +1 -4
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/check.py +3 -4
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/install_data.py +39 -29
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/install_lib.py +1 -3
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/sdist.py +4 -4
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/compat/py38.py +1 -0
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/cygwinccompiler.py +21 -42
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/dist.py +3 -12
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/extension.py +9 -4
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/msvc9compiler.py +1 -3
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/msvccompiler.py +1 -3
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/spawn.py +0 -1
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/sysconfig.py +44 -25
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_archive_util.py +1 -1
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_build.py +1 -2
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_build_ext.py +1 -1
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_cygwinccompiler.py +0 -42
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_dist.py +1 -1
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_extension.py +4 -1
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_install_data.py +17 -9
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_mingwccompiler.py +5 -4
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_spawn.py +1 -1
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_sysconfig.py +6 -3
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_unixccompiler.py +35 -1
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_util.py +4 -24
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/unixccompiler.py +19 -20
- py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/util.py +20 -26
- py2docfx/venv/template/Lib/site-packages/wheel/__init__.py +3 -0
- py2docfx/venv/template/Lib/site-packages/wheel/__main__.py +23 -0
- py2docfx/venv/template/Lib/site-packages/wheel/_bdist_wheel.py +604 -0
- py2docfx/venv/template/Lib/site-packages/wheel/_setuptools_logging.py +26 -0
- py2docfx/venv/template/Lib/site-packages/wheel/bdist_wheel.py +11 -0
- py2docfx/venv/template/Lib/site-packages/wheel/cli/__init__.py +155 -0
- py2docfx/venv/template/Lib/site-packages/wheel/cli/convert.py +273 -0
- py2docfx/venv/template/Lib/site-packages/wheel/cli/pack.py +85 -0
- py2docfx/venv/template/Lib/site-packages/wheel/cli/tags.py +139 -0
- py2docfx/venv/template/Lib/site-packages/wheel/cli/unpack.py +30 -0
- py2docfx/venv/template/Lib/site-packages/wheel/macosx_libfile.py +482 -0
- py2docfx/venv/template/Lib/site-packages/wheel/metadata.py +183 -0
- py2docfx/venv/template/Lib/site-packages/wheel/util.py +26 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/__init__.py +0 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/__init__.py +0 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_elffile.py +108 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_manylinux.py +260 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_musllinux.py +83 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_parser.py +356 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_structures.py +61 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_tokenizer.py +192 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/markers.py +253 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/requirements.py +90 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/specifiers.py +1011 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/tags.py +571 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/utils.py +172 -0
- py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/version.py +561 -0
- py2docfx/venv/template/Lib/site-packages/wheel/wheelfile.py +227 -0
- {py2docfx-0.1.11.dev1824276.dist-info → py2docfx-0.1.11.dev1827111.dist-info}/METADATA +1 -1
- {py2docfx-0.1.11.dev1824276.dist-info → py2docfx-0.1.11.dev1827111.dist-info}/RECORD +123 -67
- {py2docfx-0.1.11.dev1824276.dist-info → py2docfx-0.1.11.dev1827111.dist-info}/WHEEL +0 -0
- {py2docfx-0.1.11.dev1824276.dist-info → py2docfx-0.1.11.dev1827111.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,155 @@
|
|
1
|
+
"""
|
2
|
+
Wheel command-line utility.
|
3
|
+
"""
|
4
|
+
|
5
|
+
from __future__ import annotations
|
6
|
+
|
7
|
+
import argparse
|
8
|
+
import os
|
9
|
+
import sys
|
10
|
+
from argparse import ArgumentTypeError
|
11
|
+
|
12
|
+
|
13
|
+
class WheelError(Exception):
|
14
|
+
pass
|
15
|
+
|
16
|
+
|
17
|
+
def unpack_f(args: argparse.Namespace) -> None:
|
18
|
+
from .unpack import unpack
|
19
|
+
|
20
|
+
unpack(args.wheelfile, args.dest)
|
21
|
+
|
22
|
+
|
23
|
+
def pack_f(args: argparse.Namespace) -> None:
|
24
|
+
from .pack import pack
|
25
|
+
|
26
|
+
pack(args.directory, args.dest_dir, args.build_number)
|
27
|
+
|
28
|
+
|
29
|
+
def convert_f(args: argparse.Namespace) -> None:
|
30
|
+
from .convert import convert
|
31
|
+
|
32
|
+
convert(args.files, args.dest_dir, args.verbose)
|
33
|
+
|
34
|
+
|
35
|
+
def tags_f(args: argparse.Namespace) -> None:
|
36
|
+
from .tags import tags
|
37
|
+
|
38
|
+
names = (
|
39
|
+
tags(
|
40
|
+
wheel,
|
41
|
+
args.python_tag,
|
42
|
+
args.abi_tag,
|
43
|
+
args.platform_tag,
|
44
|
+
args.build,
|
45
|
+
args.remove,
|
46
|
+
)
|
47
|
+
for wheel in args.wheel
|
48
|
+
)
|
49
|
+
|
50
|
+
for name in names:
|
51
|
+
print(name)
|
52
|
+
|
53
|
+
|
54
|
+
def version_f(args: argparse.Namespace) -> None:
|
55
|
+
from .. import __version__
|
56
|
+
|
57
|
+
print(f"wheel {__version__}")
|
58
|
+
|
59
|
+
|
60
|
+
def parse_build_tag(build_tag: str) -> str:
|
61
|
+
if build_tag and not build_tag[0].isdigit():
|
62
|
+
raise ArgumentTypeError("build tag must begin with a digit")
|
63
|
+
elif "-" in build_tag:
|
64
|
+
raise ArgumentTypeError("invalid character ('-') in build tag")
|
65
|
+
|
66
|
+
return build_tag
|
67
|
+
|
68
|
+
|
69
|
+
TAGS_HELP = """\
|
70
|
+
Make a new wheel with given tags. Any tags unspecified will remain the same.
|
71
|
+
Starting the tags with a "+" will append to the existing tags. Starting with a
|
72
|
+
"-" will remove a tag (use --option=-TAG syntax). Multiple tags can be
|
73
|
+
separated by ".". The original file will remain unless --remove is given. The
|
74
|
+
output filename(s) will be displayed on stdout for further processing.
|
75
|
+
"""
|
76
|
+
|
77
|
+
|
78
|
+
def parser():
|
79
|
+
p = argparse.ArgumentParser()
|
80
|
+
s = p.add_subparsers(help="commands")
|
81
|
+
|
82
|
+
unpack_parser = s.add_parser("unpack", help="Unpack wheel")
|
83
|
+
unpack_parser.add_argument(
|
84
|
+
"--dest", "-d", help="Destination directory", default="."
|
85
|
+
)
|
86
|
+
unpack_parser.add_argument("wheelfile", help="Wheel file")
|
87
|
+
unpack_parser.set_defaults(func=unpack_f)
|
88
|
+
|
89
|
+
repack_parser = s.add_parser("pack", help="Repack wheel")
|
90
|
+
repack_parser.add_argument("directory", help="Root directory of the unpacked wheel")
|
91
|
+
repack_parser.add_argument(
|
92
|
+
"--dest-dir",
|
93
|
+
"-d",
|
94
|
+
default=os.path.curdir,
|
95
|
+
help="Directory to store the wheel (default %(default)s)",
|
96
|
+
)
|
97
|
+
repack_parser.add_argument(
|
98
|
+
"--build-number", help="Build tag to use in the wheel name"
|
99
|
+
)
|
100
|
+
repack_parser.set_defaults(func=pack_f)
|
101
|
+
|
102
|
+
convert_parser = s.add_parser("convert", help="Convert egg or wininst to wheel")
|
103
|
+
convert_parser.add_argument("files", nargs="*", help="Files to convert")
|
104
|
+
convert_parser.add_argument(
|
105
|
+
"--dest-dir",
|
106
|
+
"-d",
|
107
|
+
default=os.path.curdir,
|
108
|
+
help="Directory to store wheels (default %(default)s)",
|
109
|
+
)
|
110
|
+
convert_parser.add_argument("--verbose", "-v", action="store_true")
|
111
|
+
convert_parser.set_defaults(func=convert_f)
|
112
|
+
|
113
|
+
tags_parser = s.add_parser(
|
114
|
+
"tags", help="Add or replace the tags on a wheel", description=TAGS_HELP
|
115
|
+
)
|
116
|
+
tags_parser.add_argument("wheel", nargs="*", help="Existing wheel(s) to retag")
|
117
|
+
tags_parser.add_argument(
|
118
|
+
"--remove",
|
119
|
+
action="store_true",
|
120
|
+
help="Remove the original files, keeping only the renamed ones",
|
121
|
+
)
|
122
|
+
tags_parser.add_argument(
|
123
|
+
"--python-tag", metavar="TAG", help="Specify an interpreter tag(s)"
|
124
|
+
)
|
125
|
+
tags_parser.add_argument("--abi-tag", metavar="TAG", help="Specify an ABI tag(s)")
|
126
|
+
tags_parser.add_argument(
|
127
|
+
"--platform-tag", metavar="TAG", help="Specify a platform tag(s)"
|
128
|
+
)
|
129
|
+
tags_parser.add_argument(
|
130
|
+
"--build", type=parse_build_tag, metavar="BUILD", help="Specify a build tag"
|
131
|
+
)
|
132
|
+
tags_parser.set_defaults(func=tags_f)
|
133
|
+
|
134
|
+
version_parser = s.add_parser("version", help="Print version and exit")
|
135
|
+
version_parser.set_defaults(func=version_f)
|
136
|
+
|
137
|
+
help_parser = s.add_parser("help", help="Show this help")
|
138
|
+
help_parser.set_defaults(func=lambda args: p.print_help())
|
139
|
+
|
140
|
+
return p
|
141
|
+
|
142
|
+
|
143
|
+
def main():
|
144
|
+
p = parser()
|
145
|
+
args = p.parse_args()
|
146
|
+
if not hasattr(args, "func"):
|
147
|
+
p.print_help()
|
148
|
+
else:
|
149
|
+
try:
|
150
|
+
args.func(args)
|
151
|
+
return 0
|
152
|
+
except WheelError as e:
|
153
|
+
print(e, file=sys.stderr)
|
154
|
+
|
155
|
+
return 1
|
@@ -0,0 +1,273 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import os.path
|
4
|
+
import re
|
5
|
+
import shutil
|
6
|
+
import tempfile
|
7
|
+
import zipfile
|
8
|
+
from glob import iglob
|
9
|
+
|
10
|
+
from .._bdist_wheel import bdist_wheel
|
11
|
+
from ..wheelfile import WheelFile
|
12
|
+
from . import WheelError
|
13
|
+
|
14
|
+
try:
|
15
|
+
from setuptools import Distribution
|
16
|
+
except ImportError:
|
17
|
+
from distutils.dist import Distribution
|
18
|
+
|
19
|
+
egg_info_re = re.compile(
|
20
|
+
r"""
|
21
|
+
(?P<name>.+?)-(?P<ver>.+?)
|
22
|
+
(-(?P<pyver>py\d\.\d+)
|
23
|
+
(-(?P<arch>.+?))?
|
24
|
+
)?.egg$""",
|
25
|
+
re.VERBOSE,
|
26
|
+
)
|
27
|
+
|
28
|
+
|
29
|
+
class _bdist_wheel_tag(bdist_wheel):
|
30
|
+
# allow the client to override the default generated wheel tag
|
31
|
+
# The default bdist_wheel implementation uses python and abi tags
|
32
|
+
# of the running python process. This is not suitable for
|
33
|
+
# generating/repackaging prebuild binaries.
|
34
|
+
|
35
|
+
full_tag_supplied = False
|
36
|
+
full_tag = None # None or a (pytag, soabitag, plattag) triple
|
37
|
+
|
38
|
+
def get_tag(self):
|
39
|
+
if self.full_tag_supplied and self.full_tag is not None:
|
40
|
+
return self.full_tag
|
41
|
+
else:
|
42
|
+
return bdist_wheel.get_tag(self)
|
43
|
+
|
44
|
+
|
45
|
+
def egg2wheel(egg_path: str, dest_dir: str) -> None:
|
46
|
+
filename = os.path.basename(egg_path)
|
47
|
+
match = egg_info_re.match(filename)
|
48
|
+
if not match:
|
49
|
+
raise WheelError(f"Invalid egg file name: {filename}")
|
50
|
+
|
51
|
+
egg_info = match.groupdict()
|
52
|
+
dir = tempfile.mkdtemp(suffix="_e2w")
|
53
|
+
if os.path.isfile(egg_path):
|
54
|
+
# assume we have a bdist_egg otherwise
|
55
|
+
with zipfile.ZipFile(egg_path) as egg:
|
56
|
+
egg.extractall(dir)
|
57
|
+
else:
|
58
|
+
# support buildout-style installed eggs directories
|
59
|
+
for pth in os.listdir(egg_path):
|
60
|
+
src = os.path.join(egg_path, pth)
|
61
|
+
if os.path.isfile(src):
|
62
|
+
shutil.copy2(src, dir)
|
63
|
+
else:
|
64
|
+
shutil.copytree(src, os.path.join(dir, pth))
|
65
|
+
|
66
|
+
pyver = egg_info["pyver"]
|
67
|
+
if pyver:
|
68
|
+
pyver = egg_info["pyver"] = pyver.replace(".", "")
|
69
|
+
|
70
|
+
arch = (egg_info["arch"] or "any").replace(".", "_").replace("-", "_")
|
71
|
+
|
72
|
+
# assume all binary eggs are for CPython
|
73
|
+
abi = "cp" + pyver[2:] if arch != "any" else "none"
|
74
|
+
|
75
|
+
root_is_purelib = egg_info["arch"] is None
|
76
|
+
if root_is_purelib:
|
77
|
+
bw = bdist_wheel(Distribution())
|
78
|
+
else:
|
79
|
+
bw = _bdist_wheel_tag(Distribution())
|
80
|
+
|
81
|
+
bw.root_is_pure = root_is_purelib
|
82
|
+
bw.python_tag = pyver
|
83
|
+
bw.plat_name_supplied = True
|
84
|
+
bw.plat_name = egg_info["arch"] or "any"
|
85
|
+
if not root_is_purelib:
|
86
|
+
bw.full_tag_supplied = True
|
87
|
+
bw.full_tag = (pyver, abi, arch)
|
88
|
+
|
89
|
+
dist_info_dir = os.path.join(dir, "{name}-{ver}.dist-info".format(**egg_info))
|
90
|
+
bw.egg2dist(os.path.join(dir, "EGG-INFO"), dist_info_dir)
|
91
|
+
bw.write_wheelfile(dist_info_dir, generator="egg2wheel")
|
92
|
+
wheel_name = "{name}-{ver}-{pyver}-{}-{}.whl".format(abi, arch, **egg_info)
|
93
|
+
with WheelFile(os.path.join(dest_dir, wheel_name), "w") as wf:
|
94
|
+
wf.write_files(dir)
|
95
|
+
|
96
|
+
shutil.rmtree(dir)
|
97
|
+
|
98
|
+
|
99
|
+
def parse_wininst_info(wininfo_name: str, egginfo_name: str | None):
|
100
|
+
"""Extract metadata from filenames.
|
101
|
+
|
102
|
+
Extracts the 4 metadataitems needed (name, version, pyversion, arch) from
|
103
|
+
the installer filename and the name of the egg-info directory embedded in
|
104
|
+
the zipfile (if any).
|
105
|
+
|
106
|
+
The egginfo filename has the format::
|
107
|
+
|
108
|
+
name-ver(-pyver)(-arch).egg-info
|
109
|
+
|
110
|
+
The installer filename has the format::
|
111
|
+
|
112
|
+
name-ver.arch(-pyver).exe
|
113
|
+
|
114
|
+
Some things to note:
|
115
|
+
|
116
|
+
1. The installer filename is not definitive. An installer can be renamed
|
117
|
+
and work perfectly well as an installer. So more reliable data should
|
118
|
+
be used whenever possible.
|
119
|
+
2. The egg-info data should be preferred for the name and version, because
|
120
|
+
these come straight from the distutils metadata, and are mandatory.
|
121
|
+
3. The pyver from the egg-info data should be ignored, as it is
|
122
|
+
constructed from the version of Python used to build the installer,
|
123
|
+
which is irrelevant - the installer filename is correct here (even to
|
124
|
+
the point that when it's not there, any version is implied).
|
125
|
+
4. The architecture must be taken from the installer filename, as it is
|
126
|
+
not included in the egg-info data.
|
127
|
+
5. Architecture-neutral installers still have an architecture because the
|
128
|
+
installer format itself (being executable) is architecture-specific. We
|
129
|
+
should therefore ignore the architecture if the content is pure-python.
|
130
|
+
"""
|
131
|
+
|
132
|
+
egginfo = None
|
133
|
+
if egginfo_name:
|
134
|
+
egginfo = egg_info_re.search(egginfo_name)
|
135
|
+
if not egginfo:
|
136
|
+
raise ValueError(f"Egg info filename {egginfo_name} is not valid")
|
137
|
+
|
138
|
+
# Parse the wininst filename
|
139
|
+
# 1. Distribution name (up to the first '-')
|
140
|
+
w_name, sep, rest = wininfo_name.partition("-")
|
141
|
+
if not sep:
|
142
|
+
raise ValueError(f"Installer filename {wininfo_name} is not valid")
|
143
|
+
|
144
|
+
# Strip '.exe'
|
145
|
+
rest = rest[:-4]
|
146
|
+
# 2. Python version (from the last '-', must start with 'py')
|
147
|
+
rest2, sep, w_pyver = rest.rpartition("-")
|
148
|
+
if sep and w_pyver.startswith("py"):
|
149
|
+
rest = rest2
|
150
|
+
w_pyver = w_pyver.replace(".", "")
|
151
|
+
else:
|
152
|
+
# Not version specific - use py2.py3. While it is possible that
|
153
|
+
# pure-Python code is not compatible with both Python 2 and 3, there
|
154
|
+
# is no way of knowing from the wininst format, so we assume the best
|
155
|
+
# here (the user can always manually rename the wheel to be more
|
156
|
+
# restrictive if needed).
|
157
|
+
w_pyver = "py2.py3"
|
158
|
+
# 3. Version and architecture
|
159
|
+
w_ver, sep, w_arch = rest.rpartition(".")
|
160
|
+
if not sep:
|
161
|
+
raise ValueError(f"Installer filename {wininfo_name} is not valid")
|
162
|
+
|
163
|
+
if egginfo:
|
164
|
+
w_name = egginfo.group("name")
|
165
|
+
w_ver = egginfo.group("ver")
|
166
|
+
|
167
|
+
return {"name": w_name, "ver": w_ver, "arch": w_arch, "pyver": w_pyver}
|
168
|
+
|
169
|
+
|
170
|
+
def wininst2wheel(path: str, dest_dir: str) -> None:
|
171
|
+
with zipfile.ZipFile(path) as bdw:
|
172
|
+
# Search for egg-info in the archive
|
173
|
+
egginfo_name = None
|
174
|
+
for filename in bdw.namelist():
|
175
|
+
if ".egg-info" in filename:
|
176
|
+
egginfo_name = filename
|
177
|
+
break
|
178
|
+
|
179
|
+
info = parse_wininst_info(os.path.basename(path), egginfo_name)
|
180
|
+
|
181
|
+
root_is_purelib = True
|
182
|
+
for zipinfo in bdw.infolist():
|
183
|
+
if zipinfo.filename.startswith("PLATLIB"):
|
184
|
+
root_is_purelib = False
|
185
|
+
break
|
186
|
+
if root_is_purelib:
|
187
|
+
paths = {"purelib": ""}
|
188
|
+
else:
|
189
|
+
paths = {"platlib": ""}
|
190
|
+
|
191
|
+
dist_info = "{name}-{ver}".format(**info)
|
192
|
+
datadir = f"{dist_info}.data/"
|
193
|
+
|
194
|
+
# rewrite paths to trick ZipFile into extracting an egg
|
195
|
+
# XXX grab wininst .ini - between .exe, padding, and first zip file.
|
196
|
+
members: list[str] = []
|
197
|
+
egginfo_name = ""
|
198
|
+
for zipinfo in bdw.infolist():
|
199
|
+
key, basename = zipinfo.filename.split("/", 1)
|
200
|
+
key = key.lower()
|
201
|
+
basepath = paths.get(key, None)
|
202
|
+
if basepath is None:
|
203
|
+
basepath = datadir + key.lower() + "/"
|
204
|
+
oldname = zipinfo.filename
|
205
|
+
newname = basepath + basename
|
206
|
+
zipinfo.filename = newname
|
207
|
+
del bdw.NameToInfo[oldname]
|
208
|
+
bdw.NameToInfo[newname] = zipinfo
|
209
|
+
# Collect member names, but omit '' (from an entry like "PLATLIB/"
|
210
|
+
if newname:
|
211
|
+
members.append(newname)
|
212
|
+
# Remember egg-info name for the egg2dist call below
|
213
|
+
if not egginfo_name:
|
214
|
+
if newname.endswith(".egg-info"):
|
215
|
+
egginfo_name = newname
|
216
|
+
elif ".egg-info/" in newname:
|
217
|
+
egginfo_name, sep, _ = newname.rpartition("/")
|
218
|
+
dir = tempfile.mkdtemp(suffix="_b2w")
|
219
|
+
bdw.extractall(dir, members)
|
220
|
+
|
221
|
+
# egg2wheel
|
222
|
+
abi = "none"
|
223
|
+
pyver = info["pyver"]
|
224
|
+
arch = (info["arch"] or "any").replace(".", "_").replace("-", "_")
|
225
|
+
# Wininst installers always have arch even if they are not
|
226
|
+
# architecture-specific (because the format itself is).
|
227
|
+
# So, assume the content is architecture-neutral if root is purelib.
|
228
|
+
if root_is_purelib:
|
229
|
+
arch = "any"
|
230
|
+
# If the installer is architecture-specific, it's almost certainly also
|
231
|
+
# CPython-specific.
|
232
|
+
if arch != "any":
|
233
|
+
pyver = pyver.replace("py", "cp")
|
234
|
+
wheel_name = "-".join((dist_info, pyver, abi, arch))
|
235
|
+
if root_is_purelib:
|
236
|
+
bw = bdist_wheel(Distribution())
|
237
|
+
else:
|
238
|
+
bw = _bdist_wheel_tag(Distribution())
|
239
|
+
|
240
|
+
bw.root_is_pure = root_is_purelib
|
241
|
+
bw.python_tag = pyver
|
242
|
+
bw.plat_name_supplied = True
|
243
|
+
bw.plat_name = info["arch"] or "any"
|
244
|
+
|
245
|
+
if not root_is_purelib:
|
246
|
+
bw.full_tag_supplied = True
|
247
|
+
bw.full_tag = (pyver, abi, arch)
|
248
|
+
|
249
|
+
dist_info_dir = os.path.join(dir, f"{dist_info}.dist-info")
|
250
|
+
bw.egg2dist(os.path.join(dir, egginfo_name), dist_info_dir)
|
251
|
+
bw.write_wheelfile(dist_info_dir, generator="wininst2wheel")
|
252
|
+
|
253
|
+
wheel_path = os.path.join(dest_dir, wheel_name)
|
254
|
+
with WheelFile(wheel_path, "w") as wf:
|
255
|
+
wf.write_files(dir)
|
256
|
+
|
257
|
+
shutil.rmtree(dir)
|
258
|
+
|
259
|
+
|
260
|
+
def convert(files: list[str], dest_dir: str, verbose: bool) -> None:
|
261
|
+
for pat in files:
|
262
|
+
for installer in iglob(pat):
|
263
|
+
if os.path.splitext(installer)[1] == ".egg":
|
264
|
+
conv = egg2wheel
|
265
|
+
else:
|
266
|
+
conv = wininst2wheel
|
267
|
+
|
268
|
+
if verbose:
|
269
|
+
print(f"{installer}... ", flush=True)
|
270
|
+
|
271
|
+
conv(installer, dest_dir)
|
272
|
+
if verbose:
|
273
|
+
print("OK")
|
@@ -0,0 +1,85 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import email.policy
|
4
|
+
import os.path
|
5
|
+
import re
|
6
|
+
from email.generator import BytesGenerator
|
7
|
+
from email.parser import BytesParser
|
8
|
+
|
9
|
+
from wheel.cli import WheelError
|
10
|
+
from wheel.wheelfile import WheelFile
|
11
|
+
|
12
|
+
DIST_INFO_RE = re.compile(r"^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))\.dist-info$")
|
13
|
+
|
14
|
+
|
15
|
+
def pack(directory: str, dest_dir: str, build_number: str | None) -> None:
|
16
|
+
"""Repack a previously unpacked wheel directory into a new wheel file.
|
17
|
+
|
18
|
+
The .dist-info/WHEEL file must contain one or more tags so that the target
|
19
|
+
wheel file name can be determined.
|
20
|
+
|
21
|
+
:param directory: The unpacked wheel directory
|
22
|
+
:param dest_dir: Destination directory (defaults to the current directory)
|
23
|
+
"""
|
24
|
+
# Find the .dist-info directory
|
25
|
+
dist_info_dirs = [
|
26
|
+
fn
|
27
|
+
for fn in os.listdir(directory)
|
28
|
+
if os.path.isdir(os.path.join(directory, fn)) and DIST_INFO_RE.match(fn)
|
29
|
+
]
|
30
|
+
if len(dist_info_dirs) > 1:
|
31
|
+
raise WheelError(f"Multiple .dist-info directories found in {directory}")
|
32
|
+
elif not dist_info_dirs:
|
33
|
+
raise WheelError(f"No .dist-info directories found in {directory}")
|
34
|
+
|
35
|
+
# Determine the target wheel filename
|
36
|
+
dist_info_dir = dist_info_dirs[0]
|
37
|
+
name_version = DIST_INFO_RE.match(dist_info_dir).group("namever")
|
38
|
+
|
39
|
+
# Read the tags and the existing build number from .dist-info/WHEEL
|
40
|
+
wheel_file_path = os.path.join(directory, dist_info_dir, "WHEEL")
|
41
|
+
with open(wheel_file_path, "rb") as f:
|
42
|
+
info = BytesParser(policy=email.policy.compat32).parse(f)
|
43
|
+
tags: list[str] = info.get_all("Tag", [])
|
44
|
+
existing_build_number = info.get("Build")
|
45
|
+
|
46
|
+
if not tags:
|
47
|
+
raise WheelError(
|
48
|
+
f"No tags present in {dist_info_dir}/WHEEL; cannot determine target "
|
49
|
+
f"wheel filename"
|
50
|
+
)
|
51
|
+
|
52
|
+
# Set the wheel file name and add/replace/remove the Build tag in .dist-info/WHEEL
|
53
|
+
build_number = build_number if build_number is not None else existing_build_number
|
54
|
+
if build_number is not None:
|
55
|
+
del info["Build"]
|
56
|
+
if build_number:
|
57
|
+
info["Build"] = build_number
|
58
|
+
name_version += "-" + build_number
|
59
|
+
|
60
|
+
if build_number != existing_build_number:
|
61
|
+
with open(wheel_file_path, "wb") as f:
|
62
|
+
BytesGenerator(f, maxheaderlen=0).flatten(info)
|
63
|
+
|
64
|
+
# Reassemble the tags for the wheel file
|
65
|
+
tagline = compute_tagline(tags)
|
66
|
+
|
67
|
+
# Repack the wheel
|
68
|
+
wheel_path = os.path.join(dest_dir, f"{name_version}-{tagline}.whl")
|
69
|
+
with WheelFile(wheel_path, "w") as wf:
|
70
|
+
print(f"Repacking wheel as {wheel_path}...", end="", flush=True)
|
71
|
+
wf.write_files(directory)
|
72
|
+
|
73
|
+
print("OK")
|
74
|
+
|
75
|
+
|
76
|
+
def compute_tagline(tags: list[str]) -> str:
|
77
|
+
"""Compute a tagline from a list of tags.
|
78
|
+
|
79
|
+
:param tags: A list of tags
|
80
|
+
:return: A tagline
|
81
|
+
"""
|
82
|
+
impls = sorted({tag.split("-")[0] for tag in tags})
|
83
|
+
abivers = sorted({tag.split("-")[1] for tag in tags})
|
84
|
+
platforms = sorted({tag.split("-")[2] for tag in tags})
|
85
|
+
return "-".join([".".join(impls), ".".join(abivers), ".".join(platforms)])
|
@@ -0,0 +1,139 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import email.policy
|
4
|
+
import itertools
|
5
|
+
import os
|
6
|
+
from collections.abc import Iterable
|
7
|
+
from email.parser import BytesParser
|
8
|
+
|
9
|
+
from ..wheelfile import WheelFile
|
10
|
+
|
11
|
+
|
12
|
+
def _compute_tags(original_tags: Iterable[str], new_tags: str | None) -> set[str]:
|
13
|
+
"""Add or replace tags. Supports dot-separated tags"""
|
14
|
+
if new_tags is None:
|
15
|
+
return set(original_tags)
|
16
|
+
|
17
|
+
if new_tags.startswith("+"):
|
18
|
+
return {*original_tags, *new_tags[1:].split(".")}
|
19
|
+
|
20
|
+
if new_tags.startswith("-"):
|
21
|
+
return set(original_tags) - set(new_tags[1:].split("."))
|
22
|
+
|
23
|
+
return set(new_tags.split("."))
|
24
|
+
|
25
|
+
|
26
|
+
def tags(
|
27
|
+
wheel: str,
|
28
|
+
python_tags: str | None = None,
|
29
|
+
abi_tags: str | None = None,
|
30
|
+
platform_tags: str | None = None,
|
31
|
+
build_tag: str | None = None,
|
32
|
+
remove: bool = False,
|
33
|
+
) -> str:
|
34
|
+
"""Change the tags on a wheel file.
|
35
|
+
|
36
|
+
The tags are left unchanged if they are not specified. To specify "none",
|
37
|
+
use ["none"]. To append to the previous tags, a tag should start with a
|
38
|
+
"+". If a tag starts with "-", it will be removed from existing tags.
|
39
|
+
Processing is done left to right.
|
40
|
+
|
41
|
+
:param wheel: The paths to the wheels
|
42
|
+
:param python_tags: The Python tags to set
|
43
|
+
:param abi_tags: The ABI tags to set
|
44
|
+
:param platform_tags: The platform tags to set
|
45
|
+
:param build_tag: The build tag to set
|
46
|
+
:param remove: Remove the original wheel
|
47
|
+
"""
|
48
|
+
with WheelFile(wheel, "r") as f:
|
49
|
+
assert f.filename, f"{f.filename} must be available"
|
50
|
+
|
51
|
+
wheel_info = f.read(f.dist_info_path + "/WHEEL")
|
52
|
+
info = BytesParser(policy=email.policy.compat32).parsebytes(wheel_info)
|
53
|
+
|
54
|
+
original_wheel_name = os.path.basename(f.filename)
|
55
|
+
namever = f.parsed_filename.group("namever")
|
56
|
+
build = f.parsed_filename.group("build")
|
57
|
+
original_python_tags = f.parsed_filename.group("pyver").split(".")
|
58
|
+
original_abi_tags = f.parsed_filename.group("abi").split(".")
|
59
|
+
original_plat_tags = f.parsed_filename.group("plat").split(".")
|
60
|
+
|
61
|
+
tags: list[str] = info.get_all("Tag", [])
|
62
|
+
existing_build_tag = info.get("Build")
|
63
|
+
|
64
|
+
impls = {tag.split("-")[0] for tag in tags}
|
65
|
+
abivers = {tag.split("-")[1] for tag in tags}
|
66
|
+
platforms = {tag.split("-")[2] for tag in tags}
|
67
|
+
|
68
|
+
if impls != set(original_python_tags):
|
69
|
+
msg = f"Wheel internal tags {impls!r} != filename tags {original_python_tags!r}"
|
70
|
+
raise AssertionError(msg)
|
71
|
+
|
72
|
+
if abivers != set(original_abi_tags):
|
73
|
+
msg = f"Wheel internal tags {abivers!r} != filename tags {original_abi_tags!r}"
|
74
|
+
raise AssertionError(msg)
|
75
|
+
|
76
|
+
if platforms != set(original_plat_tags):
|
77
|
+
msg = (
|
78
|
+
f"Wheel internal tags {platforms!r} != filename tags {original_plat_tags!r}"
|
79
|
+
)
|
80
|
+
raise AssertionError(msg)
|
81
|
+
|
82
|
+
if existing_build_tag != build:
|
83
|
+
msg = (
|
84
|
+
f"Incorrect filename '{build}' "
|
85
|
+
f"& *.dist-info/WHEEL '{existing_build_tag}' build numbers"
|
86
|
+
)
|
87
|
+
raise AssertionError(msg)
|
88
|
+
|
89
|
+
# Start changing as needed
|
90
|
+
if build_tag is not None:
|
91
|
+
build = build_tag
|
92
|
+
|
93
|
+
final_python_tags = sorted(_compute_tags(original_python_tags, python_tags))
|
94
|
+
final_abi_tags = sorted(_compute_tags(original_abi_tags, abi_tags))
|
95
|
+
final_plat_tags = sorted(_compute_tags(original_plat_tags, platform_tags))
|
96
|
+
|
97
|
+
final_tags = [
|
98
|
+
namever,
|
99
|
+
".".join(final_python_tags),
|
100
|
+
".".join(final_abi_tags),
|
101
|
+
".".join(final_plat_tags),
|
102
|
+
]
|
103
|
+
if build:
|
104
|
+
final_tags.insert(1, build)
|
105
|
+
|
106
|
+
final_wheel_name = "-".join(final_tags) + ".whl"
|
107
|
+
|
108
|
+
if original_wheel_name != final_wheel_name:
|
109
|
+
del info["Tag"], info["Build"]
|
110
|
+
for a, b, c in itertools.product(
|
111
|
+
final_python_tags, final_abi_tags, final_plat_tags
|
112
|
+
):
|
113
|
+
info["Tag"] = f"{a}-{b}-{c}"
|
114
|
+
if build:
|
115
|
+
info["Build"] = build
|
116
|
+
|
117
|
+
original_wheel_path = os.path.join(
|
118
|
+
os.path.dirname(f.filename), original_wheel_name
|
119
|
+
)
|
120
|
+
final_wheel_path = os.path.join(os.path.dirname(f.filename), final_wheel_name)
|
121
|
+
|
122
|
+
with WheelFile(original_wheel_path, "r") as fin, WheelFile(
|
123
|
+
final_wheel_path, "w"
|
124
|
+
) as fout:
|
125
|
+
fout.comment = fin.comment # preserve the comment
|
126
|
+
for item in fin.infolist():
|
127
|
+
if item.is_dir():
|
128
|
+
continue
|
129
|
+
if item.filename == f.dist_info_path + "/RECORD":
|
130
|
+
continue
|
131
|
+
if item.filename == f.dist_info_path + "/WHEEL":
|
132
|
+
fout.writestr(item, info.as_bytes())
|
133
|
+
else:
|
134
|
+
fout.writestr(item, fin.read(item))
|
135
|
+
|
136
|
+
if remove:
|
137
|
+
os.remove(original_wheel_path)
|
138
|
+
|
139
|
+
return final_wheel_name
|
@@ -0,0 +1,30 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from pathlib import Path
|
4
|
+
|
5
|
+
from ..wheelfile import WheelFile
|
6
|
+
|
7
|
+
|
8
|
+
def unpack(path: str, dest: str = ".") -> None:
|
9
|
+
"""Unpack a wheel.
|
10
|
+
|
11
|
+
Wheel content will be unpacked to {dest}/{name}-{ver}, where {name}
|
12
|
+
is the package name and {ver} its version.
|
13
|
+
|
14
|
+
:param path: The path to the wheel.
|
15
|
+
:param dest: Destination directory (default to current directory).
|
16
|
+
"""
|
17
|
+
with WheelFile(path) as wf:
|
18
|
+
namever = wf.parsed_filename.group("namever")
|
19
|
+
destination = Path(dest) / namever
|
20
|
+
print(f"Unpacking to: {destination}...", end="", flush=True)
|
21
|
+
for zinfo in wf.filelist:
|
22
|
+
wf.extract(zinfo, destination)
|
23
|
+
|
24
|
+
# Set permissions to the same values as they were set in the archive
|
25
|
+
# We have to do this manually due to
|
26
|
+
# https://github.com/python/cpython/issues/59999
|
27
|
+
permissions = zinfo.external_attr >> 16 & 0o777
|
28
|
+
destination.joinpath(zinfo.filename).chmod(permissions)
|
29
|
+
|
30
|
+
print("OK")
|