@@ -102,29 +102,33 @@ def __init__(
102
102
filename ,
103
103
* ,
104
104
mode ,
105
- distinfo_dir : str | Path ,
105
+ distribution_prefix : str ,
106
106
strip_path_prefixes = None ,
107
107
compression = zipfile .ZIP_DEFLATED ,
108
108
** kwargs ,
109
109
):
110
- self ._distinfo_dir : str = Path (distinfo_dir ).name
110
+ self ._distribution_prefix = distribution_prefix
111
+
111
112
self ._strip_path_prefixes = strip_path_prefixes or []
112
113
# Entries for the RECORD file as (filename, hash, size) tuples.
113
114
self ._record = []
114
115
115
116
super ().__init__ (filename , mode = mode , compression = compression , ** kwargs )
116
117
117
118
def distinfo_path (self , basename ):
118
- return f"{ self ._distinfo_dir } /{ basename } "
119
+ return f"{ self ._distribution_prefix } .dist-info/{ basename } "
120
+
121
+ def data_path (self , basename ):
122
+ return f"{ self ._distribution_prefix } .data/{ basename } "
119
123
120
124
def add_file (self , package_filename , real_filename ):
121
125
"""Add given file to the distribution."""
122
126
123
127
def arcname_from (name ):
124
128
# Always use unix path separators.
125
129
normalized_arcname = name .replace (os .path .sep , "/" )
126
- # Don't manipulate names filenames in the .distinfo directory .
127
- if normalized_arcname .startswith (self ._distinfo_dir ):
130
+ # Don't manipulate names filenames in the .distinfo or .data directories .
131
+ if normalized_arcname .startswith (self ._distribution_prefix ):
128
132
return normalized_arcname
129
133
for prefix in self ._strip_path_prefixes :
130
134
if normalized_arcname .startswith (prefix ):
@@ -237,11 +241,9 @@ def __init__(
237
241
self ._wheelname_fragment_distribution_name = escape_filename_distribution_name (
238
242
self ._name
239
243
)
240
- self ._distinfo_dir = (
241
- self ._wheelname_fragment_distribution_name
242
- + "-"
243
- + self ._version
244
- + ".dist-info/"
244
+
245
+ self ._distribution_prefix = (
246
+ self ._wheelname_fragment_distribution_name + "-" + self ._version
245
247
)
246
248
247
249
self ._whlfile = None
@@ -250,7 +252,7 @@ def __enter__(self):
250
252
self ._whlfile = _WhlFile (
251
253
self .filename (),
252
254
mode = "w" ,
253
- distinfo_dir = self ._distinfo_dir ,
255
+ distribution_prefix = self ._distribution_prefix ,
254
256
strip_path_prefixes = self ._strip_path_prefixes ,
255
257
)
256
258
return self
@@ -280,6 +282,9 @@ def disttags(self):
280
282
def distinfo_path (self , basename ):
281
283
return self ._whlfile .distinfo_path (basename )
282
284
285
+ def data_path (self , basename ):
286
+ return self ._whlfile .data_path (basename )
287
+
283
288
def add_file (self , package_filename , real_filename ):
284
289
"""Add given file to the distribution."""
285
290
self ._whlfile .add_file (package_filename , real_filename )
@@ -436,6 +441,12 @@ def parse_args() -> argparse.Namespace:
436
441
help = "'filename;real_path' pairs listing extra files to include in"
437
442
"dist-info directory. Can be supplied multiple times." ,
438
443
)
444
+ contents_group .add_argument (
445
+ "--data_files" ,
446
+ action = "append" ,
447
+ help = "'filename;real_path' pairs listing data files to include in"
448
+ "data directory. Can be supplied multiple times." ,
449
+ )
439
450
440
451
build_group = parser .add_argument_group ("Building requirements" )
441
452
build_group .add_argument (
@@ -452,25 +463,25 @@ def parse_args() -> argparse.Namespace:
452
463
return parser .parse_args (sys .argv [1 :])
453
464
454
465
466
+ def _parse_file_pairs (content : List [str ]) -> List [List [str ]]:
467
+ """
468
+ Parse ; delimited lists of files into a 2D list.
469
+ """
470
+ return [i .split (";" , maxsplit = 1 ) for i in content or []]
471
+
472
+
455
473
def main () -> None :
456
474
arguments = parse_args ()
457
475
458
- if arguments .input_file :
459
- input_files = [i .split (";" ) for i in arguments .input_file ]
460
- else :
461
- input_files = []
462
-
463
- if arguments .extra_distinfo_file :
464
- extra_distinfo_file = [i .split (";" ) for i in arguments .extra_distinfo_file ]
465
- else :
466
- extra_distinfo_file = []
476
+ input_files = _parse_file_pairs (arguments .input_file )
477
+ extra_distinfo_file = _parse_file_pairs (arguments .extra_distinfo_file )
478
+ data_files = _parse_file_pairs (arguments .data_files )
467
479
468
- if arguments .input_file_list :
469
- for input_file in arguments .input_file_list :
470
- with open (input_file ) as _file :
471
- input_file_list = _file .read ().splitlines ()
472
- for _input_file in input_file_list :
473
- input_files .append (_input_file .split (";" ))
480
+ for input_file in arguments .input_file_list :
481
+ with open (input_file ) as _file :
482
+ input_file_list = _file .read ().splitlines ()
483
+ for _input_file in input_file_list :
484
+ input_files .append (_input_file .split (";" ))
474
485
475
486
all_files = get_files_to_package (input_files )
476
487
# Sort the files for reproducible order in the archive.
@@ -570,6 +581,8 @@ def main() -> None:
570
581
)
571
582
572
583
# Sort the files for reproducible order in the archive.
584
+ for filename , real_path in sorted (data_files ):
585
+ maker .add_file (maker .data_path (filename ), real_path )
573
586
for filename , real_path in sorted (extra_distinfo_file ):
574
587
maker .add_file (maker .distinfo_path (filename ), real_path )
575
588
0 commit comments