1818from ..builder .wheel_tag import WheelTag
1919from ..cmake import CMake , CMaker
2020from ..settings .skbuild_read_settings import SettingsReader
21- from ._file_processor import each_unignored_file
2221from ._init import setup_logging
22+ from ._pathutil import packages_to_file_mapping
2323from ._wheelfile import WheelWriter
2424
2525__all__ : list [str ] = ["_build_wheel_impl" ]
@@ -29,44 +29,24 @@ def __dir__() -> list[str]:
2929 return __all__
3030
3131
32- def _copy_python_packages_to_wheel (
33- * ,
34- packages : Sequence [str ] | None ,
35- name : str ,
36- platlib_dir : Path ,
37- include : Sequence [str ],
38- exclude : Sequence [str ],
39- ) -> dict [str , str ]:
40- mapping = {}
41- if packages is None :
42- # Auto package discovery
43- packages = []
44- for base_path in (Path ("src" ), Path ("." )):
45- path = base_path / name
46- if path .is_dir () and (
47- (path / "__init__.py" ).is_file () or (path / "__init__.pyi" ).is_file ()
48- ):
49- logger .info ("Discovered Python package at {}" , path )
50- packages += [str (path )]
51- break
52- else :
53- logger .debug ("Didn't find a Python package for {}" , name )
54-
55- for package in packages :
56- source_package = Path (package )
57- base_path = source_package .parent
58- for filepath in each_unignored_file (
59- source_package ,
60- include = include ,
61- exclude = exclude ,
32+ def _get_packages (* , packages : Sequence [str ] | None , name : str ) -> list [str ]:
33+ if packages is not None :
34+ return list (packages )
35+
36+ # Auto package discovery
37+ packages = []
38+ for base_path in (Path ("src" ), Path ("." )):
39+ path = base_path / name
40+ if path .is_dir () and (
41+ (path / "__init__.py" ).is_file () or (path / "__init__.pyi" ).is_file ()
6242 ):
63- package_dir = platlib_dir / filepath . relative_to ( base_path )
64- if not package_dir . is_file ():
65- package_dir . parent . mkdir ( exist_ok = True , parents = True )
66- shutil . copyfile ( filepath , package_dir )
67- mapping [ str ( filepath )] = str ( package_dir )
43+ logger . info ( "Discovered Python package at {}" , path )
44+ packages += [ str ( path )]
45+ break
46+ else :
47+ logger . debug ( "Didn't find a Python package for {}" , name )
6848
69- return mapping
49+ return packages
7050
7151
7252@dataclasses .dataclass
@@ -203,14 +183,21 @@ def _build_wheel_impl(
203183 builder .install (install_dir )
204184
205185 rich_print ("[green]***[/green] [bold]Making wheel..." )
206- mapping = _copy_python_packages_to_wheel (
186+ packages = _get_packages (
207187 packages = settings .wheel .packages ,
208188 name = normalized_name ,
189+ )
190+ mapping = packages_to_file_mapping (
191+ packages = packages ,
209192 platlib_dir = wheel_dirs ["platlib" ],
210193 include = settings .sdist .include ,
211194 exclude = settings .sdist .exclude ,
212195 )
213196
197+ for filepath , package_dir in mapping .items ():
198+ Path (package_dir ).parent .mkdir (exist_ok = True , parents = True )
199+ shutil .copyfile (filepath , package_dir )
200+
214201 for item in wheel_dirs ["scripts" ].iterdir ():
215202 with item .open ("rb" ) as f :
216203 content = f .read (len (b"#!python" ))
0 commit comments