@@ -239,7 +239,7 @@ def has_flag(compiler: Any, flag: str) -> bool:
239239 with tmp_chdir ():
240240 fname = Path ("flagcheck.cpp" )
241241 # Don't trigger -Wunused-parameter.
242- fname .write_text ("int main (int, char **) { return 0; }" )
242+ fname .write_text ("int main (int, char **) { return 0; }" , encoding = "utf-8" )
243243
244244 try :
245245 compiler .compile ([str (fname )], extra_postargs = [flag ])
@@ -303,29 +303,31 @@ def intree_extensions(
303303 """
304304 exts = []
305305
306- for path in paths :
307- if package_dir is None :
306+ if package_dir is None :
307+ for path in paths :
308308 parent , _ = os .path .split (path )
309309 while os .path .exists (os .path .join (parent , "__init__.py" )):
310310 parent , _ = os .path .split (parent )
311311 relname , _ = os .path .splitext (os .path .relpath (path , parent ))
312312 qualified_name = relname .replace (os .path .sep , "." )
313313 exts .append (Pybind11Extension (qualified_name , [path ]))
314+ return exts
315+
316+ for path in paths :
317+ for prefix , parent in package_dir .items ():
318+ if path .startswith (parent ):
319+ relname , _ = os .path .splitext (os .path .relpath (path , parent ))
320+ qualified_name = relname .replace (os .path .sep , "." )
321+ if prefix :
322+ qualified_name = prefix + "." + qualified_name
323+ exts .append (Pybind11Extension (qualified_name , [path ]))
324+ break
314325 else :
315- for prefix , parent in package_dir .items ():
316- if path .startswith (parent ):
317- relname , _ = os .path .splitext (os .path .relpath (path , parent ))
318- qualified_name = relname .replace (os .path .sep , "." )
319- if prefix :
320- qualified_name = prefix + "." + qualified_name
321- exts .append (Pybind11Extension (qualified_name , [path ]))
322-
323- if not exts :
324- msg = (
325- f"path { path } is not a child of any of the directories listed "
326- f"in 'package_dir' ({ package_dir } )"
327- )
328- raise ValueError (msg )
326+ msg = (
327+ f"path { path } is not a child of any of the directories listed "
328+ f"in 'package_dir' ({ package_dir } )"
329+ )
330+ raise ValueError (msg )
329331
330332 return exts
331333
@@ -339,7 +341,7 @@ def naive_recompile(obj: str, src: str) -> bool:
339341 return os .stat (obj ).st_mtime < os .stat (src ).st_mtime
340342
341343
342- def no_recompile (obg : str , src : str ) -> bool :
344+ def no_recompile (obg : str , src : str ) -> bool : # pylint: disable=unused-argument
343345 """
344346 This is the safest but slowest choice (and is the default) - will always
345347 recompile sources.
@@ -412,7 +414,7 @@ def __init__(
412414 self ,
413415 envvar : Optional [str ] = None ,
414416 default : int = 0 ,
415- max : int = 0 ,
417+ max : int = 0 , # pylint: disable=redefined-builtin
416418 needs_recompile : Callable [[str , str ], bool ] = no_recompile ,
417419 ) -> None :
418420 self .envvar = envvar
@@ -488,6 +490,9 @@ def _single_compile(obj: Any) -> None:
488490 return compile_function
489491
490492 def install (self : S ) -> S :
493+ """
494+ Installs the compile function into distutils.ccompiler.CCompiler.compile.
495+ """
491496 distutils .ccompiler .CCompiler .compile = self .function () # type: ignore[assignment]
492497 return self
493498
0 commit comments