Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_distutils.py77 linesDownload Raw Back to _backends
1import os
2import shutil
3import sys
4import warnings
5
6from numpy.distutils.core import Extension, setup
7from numpy.distutils.misc_util import dict_append
8from numpy.distutils.system_info import get_info
9from numpy.exceptions import VisibleDeprecationWarning
10
11from ._backend import Backend
12
13
14class DistutilsBackend(Backend):
15    def __init__(sef, *args, **kwargs):
16        warnings.warn(
17            "\ndistutils has been deprecated since NumPy 1.26.x\n"
18            "Use the Meson backend instead, or generate wrappers"
19            " without -c and use a custom build script",
20            VisibleDeprecationWarning,
21            stacklevel=2,
22        )
23        super().__init__(*args, **kwargs)
24
25    def compile(self):
26        num_info = {}
27        if num_info:
28            self.include_dirs.extend(num_info.get("include_dirs", []))
29        ext_args = {
30            "name": self.modulename,
31            "sources": self.sources,
32            "include_dirs": self.include_dirs,
33            "library_dirs": self.library_dirs,
34            "libraries": self.libraries,
35            "define_macros": self.define_macros,
36            "undef_macros": self.undef_macros,
37            "extra_objects": self.extra_objects,
38            "f2py_options": self.f2py_flags,
39        }
40
41        if self.sysinfo_flags:
42            for n in self.sysinfo_flags:
43                i = get_info(n)
44                if not i:
45                    print(
46                        f"No {n!r} resources found"
47                        "in system (try `f2py --help-link`)"
48                    )
49                dict_append(ext_args, **i)
50
51        ext = Extension(**ext_args)
52
53        sys.argv = [sys.argv[0]] + self.setup_flags
54        sys.argv.extend(
55            [
56                "build",
57                "--build-temp",
58                self.build_dir,
59                "--build-base",
60                self.build_dir,
61                "--build-platlib",
62                ".",
63                "--disable-optimization",
64            ]
65        )
66
67        if self.fc_flags:
68            sys.argv.extend(["config_fc"] + self.fc_flags)
69        if self.flib_flags:
70            sys.argv.extend(["build_ext"] + self.flib_flags)
71
72        setup(ext_modules=[ext])
73
74        if self.remove_build_dir and os.path.exists(self.build_dir):
75            print(f"Removing build directory {self.build_dir}")
76            shutil.rmtree(self.build_dir)
77 
codekingpro/portable-devtools · Team Ai