11#!/usr/bin/env python3
22
33import contextlib
4- from distutils import log
5- import distutils .cmd
6- import distutils .command .install_data as install_data_lib
7- import distutils .debug
8- import distutils .errors
9- import distutils .sysconfig
104import functools
115import itertools
6+ import logging as log
127import os
138import pathlib
149import re
@@ -75,11 +70,11 @@ def b2_version() -> Tuple[int, ...]:
7570class B2Distribution (setuptools .Distribution ):
7671 def reinitialize_command (
7772 self , command : str , reinit_subcommands : int = 0
78- ) -> distutils . cmd .Command :
73+ ) -> setuptools .Command :
7974 if command == "build_ext" :
80- return cast (distutils . cmd .Command , self .get_command_obj ("build_ext" ))
75+ return cast (setuptools .Command , self .get_command_obj ("build_ext" ))
8176 return cast (
82- distutils . cmd .Command ,
77+ setuptools .Command ,
8378 super ().reinitialize_command (
8479 command , reinit_subcommands = reinit_subcommands
8580 ),
@@ -102,7 +97,10 @@ def b2_escape(value: str) -> str:
10297
10398
10499def write_b2_python_config (
105- include_dirs : Sequence [str ], library_dirs : Sequence [str ], config : IO [str ]
100+ include_dirs : Sequence [str ],
101+ library_dirs : Sequence [str ],
102+ ext_suffix : str ,
103+ config : IO [str ],
106104) -> None :
107105 write = config .write
108106 # b2 keys python environments by X.Y version, breaking ties by matching
@@ -155,13 +153,8 @@ def write_b2_python_config(
155153 # other words we apply debian's override everywhere, and hope no other
156154 # overrides ever disagree with us.
157155
158- # Note that sysconfig and distutils.sysconfig disagree here, especially on
159- # windows.
160- ext_suffix = distutils .sysconfig .get_config_var ("EXT_SUFFIX" )
161- ext_suffix = str (ext_suffix or "" )
162-
163156 # python.jam appends the platform-specific final suffix on its own. I can't
164- # find a consistent value from sysconfig or distutils.sysconfig for this.
157+ # find a consistent value from sysconfig for this.
165158 for plat_suffix in (".pyd" , ".dll" , ".so" , ".sl" ):
166159 if ext_suffix .endswith (plat_suffix ):
167160 ext_suffix = ext_suffix [: - len (plat_suffix )]
@@ -271,7 +264,7 @@ def finalize_options(self) -> None:
271264 super ().finalize_options ()
272265
273266 if self .config_mode not in self .CONFIG_MODES :
274- raise distutils .errors .DistutilsOptionError (
267+ raise setuptools .errors .DistutilsOptionError (
275268 f"--config-mode must be one of { self .CONFIG_MODES } "
276269 )
277270
@@ -382,10 +375,10 @@ def _configure_b2_with_distutils(self) -> Iterator[None]:
382375 if os .name == "nt" :
383376 self ._maybe_add_arg ("--abbreviate-paths" )
384377
385- if distutils .debug .DEBUG :
386- self ._maybe_add_arg ("--debug-configuration" )
387- self ._maybe_add_arg ("--debug-building" )
388- self ._maybe_add_arg ("--debug-generators" )
378+ # if distutils.debug.DEBUG:
379+ # self._maybe_add_arg("--debug-configuration")
380+ # self._maybe_add_arg("--debug-building")
381+ # self._maybe_add_arg("--debug-generators")
389382
390383 if sys .platform == "darwin" :
391384 # boost.build defaults to toolset=clang on mac. However python.jam
@@ -411,7 +404,7 @@ def _configure_b2_with_distutils(self) -> Iterator[None]:
411404 # macOS uses multi-arch binaries. Attempt to match the
412405 # configuration of the running python by translating distutils
413406 # platform modes to b2 architecture modes
414- machine = distutils . util .get_platform ().split ("-" )[- 1 ]
407+ machine = sysconfig .get_platform ().split ("-" )[- 1 ]
415408 if machine == "arm64" :
416409 self ._maybe_add_arg ("architecture=arm" )
417410 elif machine in ("ppc" , "ppc64" ):
@@ -435,7 +428,10 @@ def _configure_b2_with_distutils(self) -> Iterator[None]:
435428 if self ._maybe_add_arg (f"python={ sysconfig .get_python_version ()} " ):
436429 config_writers .append (
437430 functools .partial (
438- write_b2_python_config , self .include_dirs , self .library_dirs
431+ write_b2_python_config ,
432+ self .include_dirs ,
433+ self .library_dirs ,
434+ os .path .basename (self .get_ext_fullpath ("" )),
439435 )
440436 )
441437
@@ -500,21 +496,6 @@ def _find_project_config(self) -> Optional[pathlib.Path]:
500496 return None
501497
502498
503- class InstallDataToLibDir (install_data_lib .install_data ):
504- def finalize_options (self ) -> None :
505- # install_data installs to the *base* directory, which is useless.
506- # Nothing ever gets installed there, no tools search there. You could
507- # only make use of it by manually picking the right install paths.
508- # This instead defaults the "install_dir" option to be "install_lib",
509- # which is "where packages are normally installed".
510- self .set_undefined_options (
511- "install" ,
512- ("install_lib" , "install_dir" ), # note "install_lib"
513- ("root" , "root" ),
514- ("force" , "force" ),
515- )
516-
517-
518499def find_all_files (path : str ) -> Iterator [str ]:
519500 for dirpath , _ , filenames in os .walk (path ):
520501 for filename in filenames :
@@ -532,7 +513,6 @@ def find_all_files(path: str) -> Iterator[str]:
532513 ext_modules = [StubExtension ("libtorrent.__init__" )],
533514 cmdclass = {
534515 "build_ext" : LibtorrentBuildExt ,
535- "install_data" : InstallDataToLibDir ,
536516 },
537517 distclass = B2Distribution ,
538518 data_files = [
0 commit comments