@@ -102,29 +102,33 @@ def __init__(
102102 filename ,
103103 * ,
104104 mode ,
105- distinfo_dir : str | Path ,
105+ distribution_prefix : str ,
106106 strip_path_prefixes = None ,
107107 compression = zipfile .ZIP_DEFLATED ,
108108 ** kwargs ,
109109 ):
110- self ._distinfo_dir : str = Path (distinfo_dir ).name
110+ self ._distribution_prefix = distribution_prefix
111+
111112 self ._strip_path_prefixes = strip_path_prefixes or []
112113 # Entries for the RECORD file as (filename, hash, size) tuples.
113114 self ._record = []
114115
115116 super ().__init__ (filename , mode = mode , compression = compression , ** kwargs )
116117
117118 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 } "
119123
120124 def add_file (self , package_filename , real_filename ):
121125 """Add given file to the distribution."""
122126
123127 def arcname_from (name ):
124128 # Always use unix path separators.
125129 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 ):
128132 return normalized_arcname
129133 for prefix in self ._strip_path_prefixes :
130134 if normalized_arcname .startswith (prefix ):
@@ -237,11 +241,9 @@ def __init__(
237241 self ._wheelname_fragment_distribution_name = escape_filename_distribution_name (
238242 self ._name
239243 )
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
245247 )
246248
247249 self ._whlfile = None
@@ -250,7 +252,7 @@ def __enter__(self):
250252 self ._whlfile = _WhlFile (
251253 self .filename (),
252254 mode = "w" ,
253- distinfo_dir = self ._distinfo_dir ,
255+ distribution_prefix = self ._distribution_prefix ,
254256 strip_path_prefixes = self ._strip_path_prefixes ,
255257 )
256258 return self
@@ -280,6 +282,9 @@ def disttags(self):
280282 def distinfo_path (self , basename ):
281283 return self ._whlfile .distinfo_path (basename )
282284
285+ def data_path (self , basename ):
286+ return self ._whlfile .data_path (basename )
287+
283288 def add_file (self , package_filename , real_filename ):
284289 """Add given file to the distribution."""
285290 self ._whlfile .add_file (package_filename , real_filename )
@@ -436,6 +441,12 @@ def parse_args() -> argparse.Namespace:
436441 help = "'filename;real_path' pairs listing extra files to include in"
437442 "dist-info directory. Can be supplied multiple times." ,
438443 )
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+ )
439450
440451 build_group = parser .add_argument_group ("Building requirements" )
441452 build_group .add_argument (
@@ -452,25 +463,25 @@ def parse_args() -> argparse.Namespace:
452463 return parser .parse_args (sys .argv [1 :])
453464
454465
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+
455473def main () -> None :
456474 arguments = parse_args ()
457475
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 )
467479
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 (";" ))
474485
475486 all_files = get_files_to_package (input_files )
476487 # Sort the files for reproducible order in the archive.
@@ -570,6 +581,8 @@ def main() -> None:
570581 )
571582
572583 # 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 )
573586 for filename , real_path in sorted (extra_distinfo_file ):
574587 maker .add_file (maker .distinfo_path (filename ), real_path )
575588
0 commit comments