Skip to content

Commit

Permalink
Changed imports to use setuptools exclusively, and stlib logging module
Browse files Browse the repository at this point in the history
For all functions/objects of distutils that haven't been directly replaced by a setuptools implementation yet, there is a complete copy of distutils inside of it.
  • Loading branch information
Oliver Copping committed Apr 15, 2024
1 parent 5274ba4 commit 60006b4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/setuptools_dso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
from __future__ import print_function

import os
import logging as log
# import of setuptools implicitly monkey patches distutils...
from setuptools import setup as _setup
from .dsocmd import DSO, Extension, install, build, build_dso, build_ext, bdist_egg
from .runtime import dylink_prepare_dso, find_dso
from .probe import ProbeToolchain

from distutils import log

__all__ = (
'DSO',
'Extension',
Expand Down
16 changes: 10 additions & 6 deletions src/setuptools_dso/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import os
from functools import partial

from distutils.ccompiler import (new_compiler as _new_compiler, gen_preprocess_options, CCompiler)
from distutils.dep_util import newer
from distutils.errors import DistutilsExecError, CompileError
from distutils.sysconfig import customize_compiler
from distutils import log
# Seems like the easiest fix for now as these don't appear
# to be exposed directly through setuptools yet
# See https://github.com/pypa/setuptools/issues/2806
from setuptools._distutils.ccompiler import (new_compiler as _new_compiler, gen_preprocess_options, CCompiler)
from setuptools._distutils.sysconfig import customize_compiler

from setuptools.modified import newer
from setuptools.errors import ExecError, CompileError
import logging as log

__all__ = (
'new_compiler',
Expand Down Expand Up @@ -60,7 +64,7 @@ def _msvc_preprocess(self, source, output_file=None, macros=None,
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError as msg:
except ExecError as msg:
raise CompileError(msg)

def new_compiler(**kws):
Expand Down
12 changes: 3 additions & 9 deletions src/setuptools_dso/dsocmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from importlib import import_module # say that three times fast...
from multiprocessing import Pool
import multiprocessing as MP
import logging as log

try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
Expand All @@ -19,15 +20,8 @@
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.install import install as _install
from setuptools.command.bdist_egg import bdist_egg as _bdist_egg
try:
# attempt at future proofing
# doesn't exist as of setuptools 52.0.0
from setuptools.command.build import build as _build
except ImportError:
from distutils.command.build import build as _build

from distutils.dep_util import newer_group
from distutils import log
from setuptools.command.build import build as _build
from setuptools.modified import newer_group

from .compiler import new_compiler

Expand Down
6 changes: 3 additions & 3 deletions src/setuptools_dso/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import os
import shutil
import logging as log

import tempfile
try:
Expand All @@ -28,8 +29,7 @@ def cleanup(self):
shutil.rmtree(self.name, ignore_errors=True)
self.name = None

from distutils.errors import DistutilsExecError, CompileError
from distutils import log
from setuptools.errors import ExecError, CompileError

from .compiler import new_compiler

Expand Down Expand Up @@ -118,7 +118,7 @@ def try_compile(self, src, **kws):
try:
self.compile(src, **kws)
return True
except (DistutilsExecError, CompileError):
except (ExecError, CompileError):
return False

def check_includes(self, headers, **kws):
Expand Down
4 changes: 2 additions & 2 deletions src/setuptools_dso/test/test_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class TryCompile(unittest.TestCase):
def setUp(self):
from distutils import log
log.set_threshold(log.DEBUG)
import logging
log = logging.Logger(name="test", level=logging.DEBUG)
self.probe = probe.ProbeToolchain(verbose=True)

def test_try_compile(self):
Expand Down

0 comments on commit 60006b4

Please sign in to comment.