7
7
from __future__ import annotations
8
8
9
9
import os
10
+ from pathlib import Path
10
11
import re
11
12
import shutil
12
13
import stat
22
23
23
24
import setuptools
24
25
from setuptools import Command
26
+ import setuptools .dist
25
27
26
28
from . import __version__ as wheel_version
27
29
from .macosx_libfile import calculate_macosx_platform_tag
@@ -219,6 +221,12 @@ class bdist_wheel(Command):
219
221
None ,
220
222
"Python tag (cp32|cp33|cpNN) for abi3 wheel tag" " (default: false)" ,
221
223
),
224
+ (
225
+ "dist-info-dir=" ,
226
+ None ,
227
+ "directory where a pre-generated dist-info can be found (e.g. as a "
228
+ "result of calling the PEP517 'prepare_metadata_for_build_wheel' "
229
+ "method)" ),
222
230
]
223
231
224
232
boolean_options = ["keep-temp" , "skip-build" , "relative" , "universal" ]
@@ -231,6 +239,7 @@ def initialize_options(self):
231
239
self .format = "zip"
232
240
self .keep_temp = False
233
241
self .dist_dir = None
242
+ self .dist_info_dir = None
234
243
self .egginfo_dir = None
235
244
self .root_is_pure = None
236
245
self .skip_build = None
@@ -249,8 +258,9 @@ def finalize_options(self):
249
258
bdist_base = self .get_finalized_command ("bdist" ).bdist_base
250
259
self .bdist_dir = os .path .join (bdist_base , "wheel" )
251
260
252
- egg_info = self .distribution .get_command_obj ("egg_info" )
253
- egg_info .ensure_finalized () # needed for correct `wheel_dist_name`
261
+ if self .dist_info_dir is None :
262
+ egg_info = self .distribution .get_command_obj ("egg_info" )
263
+ egg_info .ensure_finalized () # needed for correct `wheel_dist_name`
254
264
255
265
self .data_dir = self .wheel_dist_name + ".data"
256
266
self .plat_name_supplied = self .plat_name is not None
@@ -412,12 +422,21 @@ def run(self):
412
422
)
413
423
414
424
self .set_undefined_options ("install_egg_info" , ("target" , "egginfo_dir" ))
425
+
415
426
distinfo_dirname = (
416
427
f"{ safer_name (self .distribution .get_name ())} -"
417
428
f"{ safer_version (self .distribution .get_version ())} .dist-info"
418
429
)
419
430
distinfo_dir = os .path .join (self .bdist_dir , distinfo_dirname )
420
- self .egg2dist (self .egginfo_dir , distinfo_dir )
431
+ if self .dist_info_dir :
432
+ # Use the given dist-info directly.
433
+ shutil .copytree (self .dist_info_dir , distinfo_dir )
434
+ # Egg info is still generated, so remove it now to avoid it getting
435
+ # copied into the wheel.
436
+ shutil .rmtree (self .egginfo_dir )
437
+ else :
438
+ # Convert the generated egg-info into dist-info.
439
+ self .egg2dist (self .egginfo_dir , distinfo_dir )
421
440
422
441
self .write_wheelfile (distinfo_dir )
423
442
0 commit comments