3333 Protocol ,
3434 Tuple ,
3535 TypeVar ,
36+ cast ,
3637)
3738
3839from .. import (
5051 SetuptoolsDeprecationWarning ,
5152 SetuptoolsWarning ,
5253)
54+ from .build import build as build_cls
5355from .build_py import build_py as build_py_cls
56+ from .dist_info import dist_info as dist_info_cls
57+ from .egg_info import egg_info as egg_info_cls
58+ from .install import install as install_cls
59+ from .install_scripts import install_scripts as install_scripts_cls
5460
5561if TYPE_CHECKING :
5662 from wheel .wheelfile import WheelFile # noqa
@@ -155,7 +161,7 @@ def run(self):
155161
156162 def _ensure_dist_info (self ):
157163 if self .dist_info_dir is None :
158- dist_info = self .reinitialize_command ("dist_info" )
164+ dist_info = cast ( dist_info_cls , self .reinitialize_command ("dist_info" ) )
159165 dist_info .output_dir = self .dist_dir
160166 dist_info .ensure_finalized ()
161167 dist_info .run ()
@@ -202,25 +208,33 @@ def _configure_build(
202208 scripts = str (Path (unpacked_wheel , f"{ name } .data" , "scripts" ))
203209
204210 # egg-info may be generated again to create a manifest (used for package data)
205- egg_info = dist .reinitialize_command ("egg_info" , reinit_subcommands = True )
211+ egg_info = cast (
212+ egg_info_cls , dist .reinitialize_command ("egg_info" , reinit_subcommands = True )
213+ )
206214 egg_info .egg_base = str (tmp_dir )
207215 egg_info .ignore_egg_info_in_manifest = True
208216
209- build = dist .reinitialize_command ("build" , reinit_subcommands = True )
210- install = dist .reinitialize_command ("install" , reinit_subcommands = True )
217+ build = cast (
218+ build_cls , dist .reinitialize_command ("build" , reinit_subcommands = True )
219+ )
220+ install = cast (
221+ install_cls , dist .reinitialize_command ("install" , reinit_subcommands = True )
222+ )
211223
212224 build .build_platlib = build .build_purelib = build .build_lib = build_lib
213225 install .install_purelib = install .install_platlib = install .install_lib = wheel
214226 install .install_scripts = build .build_scripts = scripts
215227 install .install_headers = headers
216228 install .install_data = data
217229
218- install_scripts = dist .get_command_obj ("install_scripts" )
230+ install_scripts = cast (
231+ install_scripts_cls , dist .get_command_obj ("install_scripts" )
232+ )
219233 install_scripts .no_ep = True
220234
221235 build .build_temp = str (tmp_dir )
222236
223- build_py = dist .get_command_obj ("build_py" )
237+ build_py = cast ( build_py_cls , dist .get_command_obj ("build_py" ) )
224238 build_py .compile = False
225239 build_py .existing_egg_info_dir = self ._find_egg_info_dir ()
226240
@@ -233,6 +247,7 @@ def _set_editable_mode(self):
233247 """Set the ``editable_mode`` flag in the build sub-commands"""
234248 dist = self .distribution
235249 build = dist .get_command_obj ("build" )
250+ # TODO: Update typeshed distutils stubs to overload non-None return type by default
236251 for cmd_name in build .get_sub_commands ():
237252 cmd = dist .get_command_obj (cmd_name )
238253 if hasattr (cmd , "editable_mode" ):
@@ -269,7 +284,7 @@ def _run_build_commands(
269284 self ._run_install ("data" )
270285 return files , mapping
271286
272- def _run_build_subcommands (self ):
287+ def _run_build_subcommands (self ) -> None :
273288 """
274289 Issue #3501 indicates that some plugins/customizations might rely on:
275290
@@ -283,7 +298,7 @@ def _run_build_subcommands(self):
283298 # TODO: Once plugins/customisations had the chance to catch up, replace
284299 # `self._run_build_subcommands()` with `self.run_command("build")`.
285300 # Also remove _safely_run, TestCustomBuildPy. Suggested date: Aug/2023.
286- build : Command = self .get_finalized_command ("build" )
301+ build = self .get_finalized_command ("build" )
287302 for name in build .get_sub_commands ():
288303 cmd = self .get_finalized_command (name )
289304 if name == "build_py" and type (cmd ) != build_py_cls :
@@ -432,7 +447,8 @@ def __init__(
432447 ):
433448 self .auxiliary_dir = Path (auxiliary_dir )
434449 self .build_lib = Path (build_lib ).resolve ()
435- self ._file = dist .get_command_obj ("build_py" ).copy_file
450+ # TODO: Update typeshed distutils stubs to overload non-None return type by default
451+ self ._file = dist .get_command_obj ("build_py" ).copy_file # type: ignore[union-attr]
436452 super ().__init__ (dist , name , [self .auxiliary_dir ])
437453
438454 def __call__ (self , wheel : "WheelFile" , files : List [str ], mapping : Dict [str , str ]):
@@ -450,7 +466,9 @@ def _create_file(self, relative_output: str, src_file: str, link=None):
450466 dest = self .auxiliary_dir / relative_output
451467 if not dest .parent .is_dir ():
452468 dest .parent .mkdir (parents = True )
453- self ._file (src_file , dest , link = link )
469+ # TODO: Update typeshed distutils stubs so distutils.cmd.Command.copy_file, accepts PathLike
470+ # same with methods used by copy_file
471+ self ._file (src_file , dest , link = link ) # type: ignore[arg-type]
454472
455473 def _create_links (self , outputs , output_mapping ):
456474 self .auxiliary_dir .mkdir (parents = True , exist_ok = True )
@@ -603,7 +621,8 @@ def _simple_layout(
603621 layout = {pkg : find_package_path (pkg , package_dir , project_dir ) for pkg in packages }
604622 if not layout :
605623 return set (package_dir ) in ({}, {"" })
606- parent = os .path .commonpath (starmap (_parent_path , layout .items ()))
624+ # TODO: has been fixed upstream, waiting for new mypy release https://github.com/python/typeshed/pull/11310
625+ parent = os .path .commonpath (starmap (_parent_path , layout .items ())) # type: ignore[call-overload]
607626 return all (
608627 _path .same_path (Path (parent , * key .split ('.' )), value )
609628 for key , value in layout .items ()
0 commit comments