Skip to content

Commit

Permalink
fix setup.py to not use distutils (as it has been removed in python 3…
Browse files Browse the repository at this point in the history
….12)
  • Loading branch information
arvidn committed Mar 11, 2024
1 parent 44d1a9c commit 5970ff3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: dependencies (MacOS)
if: runner.os == 'macOS'
run: |
brew install boost-build boost boost-python3 python@3.12 openssl@1.1
brew install boost-build boost boost-python3 python@3.12 openssl@1.1 python-setuptools
export PATH=$(brew --prefix)/opt/python@3.12/bin:$PATH
- name: update package lists (linux)
Expand Down
47 changes: 12 additions & 35 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#!/usr/bin/env python3

import contextlib
from distutils import log
import distutils.cmd
import distutils.command.install_data as install_data_lib
import distutils.debug
import distutils.errors
import distutils.sysconfig
import functools
import itertools
import logging as log
import os
import pathlib
import re
Expand Down Expand Up @@ -75,11 +70,11 @@ def b2_version() -> Tuple[int, ...]:
class B2Distribution(setuptools.Distribution):
def reinitialize_command(
self, command: str, reinit_subcommands: int = 0
) -> distutils.cmd.Command:
) -> setuptools.Command:
if command == "build_ext":
return cast(distutils.cmd.Command, self.get_command_obj("build_ext"))
return cast(setuptools.Command, self.get_command_obj("build_ext"))
return cast(
distutils.cmd.Command,
setuptools.Command,
super().reinitialize_command(
command, reinit_subcommands=reinit_subcommands
),
Expand Down Expand Up @@ -155,13 +150,11 @@ def write_b2_python_config(
# other words we apply debian's override everywhere, and hope no other
# overrides ever disagree with us.

# Note that sysconfig and distutils.sysconfig disagree here, especially on
# windows.
ext_suffix = distutils.sysconfig.get_config_var("EXT_SUFFIX")
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
ext_suffix = str(ext_suffix or "")

# python.jam appends the platform-specific final suffix on its own. I can't
# find a consistent value from sysconfig or distutils.sysconfig for this.
# find a consistent value from sysconfig for this.
for plat_suffix in (".pyd", ".dll", ".so", ".sl"):
if ext_suffix.endswith(plat_suffix):
ext_suffix = ext_suffix[: -len(plat_suffix)]
Expand Down Expand Up @@ -271,7 +264,7 @@ def finalize_options(self) -> None:
super().finalize_options()

if self.config_mode not in self.CONFIG_MODES:
raise distutils.errors.DistutilsOptionError(
raise setuptools.errors.DistutilsOptionError(
f"--config-mode must be one of {self.CONFIG_MODES}"
)

Expand Down Expand Up @@ -382,10 +375,10 @@ def _configure_b2_with_distutils(self) -> Iterator[None]:
if os.name == "nt":
self._maybe_add_arg("--abbreviate-paths")

if distutils.debug.DEBUG:
self._maybe_add_arg("--debug-configuration")
self._maybe_add_arg("--debug-building")
self._maybe_add_arg("--debug-generators")
# if distutils.debug.DEBUG:
# self._maybe_add_arg("--debug-configuration")
# self._maybe_add_arg("--debug-building")
# self._maybe_add_arg("--debug-generators")

if sys.platform == "darwin":
# boost.build defaults to toolset=clang on mac. However python.jam
Expand All @@ -411,7 +404,7 @@ def _configure_b2_with_distutils(self) -> Iterator[None]:
# macOS uses multi-arch binaries. Attempt to match the
# configuration of the running python by translating distutils
# platform modes to b2 architecture modes
machine = distutils.util.get_platform().split("-")[-1]
machine = sysconfig.get_platform().split("-")[-1]
if machine == "arm64":
self._maybe_add_arg("architecture=arm")
elif machine in ("ppc", "ppc64"):
Expand Down Expand Up @@ -500,21 +493,6 @@ def _find_project_config(self) -> Optional[pathlib.Path]:
return None


class InstallDataToLibDir(install_data_lib.install_data):
def finalize_options(self) -> None:
# install_data installs to the *base* directory, which is useless.
# Nothing ever gets installed there, no tools search there. You could
# only make use of it by manually picking the right install paths.
# This instead defaults the "install_dir" option to be "install_lib",
# which is "where packages are normally installed".
self.set_undefined_options(
"install",
("install_lib", "install_dir"), # note "install_lib"
("root", "root"),
("force", "force"),
)


def find_all_files(path: str) -> Iterator[str]:
for dirpath, _, filenames in os.walk(path):
for filename in filenames:
Expand All @@ -532,7 +510,6 @@ def find_all_files(path: str) -> Iterator[str]:
ext_modules=[StubExtension("libtorrent.__init__")],
cmdclass={
"build_ext": LibtorrentBuildExt,
"install_data": InstallDataToLibDir,
},
distclass=B2Distribution,
data_files=[
Expand Down

0 comments on commit 5970ff3

Please sign in to comment.