applied-ai-018 commited on
Commit
d2716a8
·
verified ·
1 Parent(s): 93502d3

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/bnb.cpython-310.pyc +0 -0
  2. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/constants.cpython-310.pyc +0 -0
  3. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/deepspeed.cpython-310.pyc +0 -0
  4. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/environment.cpython-310.pyc +0 -0
  5. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/imports.cpython-310.pyc +0 -0
  6. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/launch.cpython-310.pyc +0 -0
  7. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/megatron_lm.cpython-310.pyc +0 -0
  8. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/modeling.cpython-310.pyc +0 -0
  9. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/operations.cpython-310.pyc +0 -0
  10. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/other.cpython-310.pyc +0 -0
  11. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/random.cpython-310.pyc +0 -0
  12. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/rich.cpython-310.pyc +0 -0
  13. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/torch_xla.cpython-310.pyc +0 -0
  14. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/tqdm.cpython-310.pyc +0 -0
  15. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/transformer_engine.cpython-310.pyc +0 -0
  16. env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/versions.cpython-310.pyc +0 -0
  17. env-llmeval/lib/python3.10/site-packages/numpy/_pytesttester.pyi +18 -0
  18. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__init__.pyi +4 -0
  19. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/__init__.cpython-310.pyc +0 -0
  20. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/_shell_utils.cpython-310.pyc +0 -0
  21. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/armccompiler.cpython-310.pyc +0 -0
  22. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/ccompiler.cpython-310.pyc +0 -0
  23. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/ccompiler_opt.cpython-310.pyc +0 -0
  24. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/conv_template.cpython-310.pyc +0 -0
  25. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/core.cpython-310.pyc +0 -0
  26. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/cpuinfo.cpython-310.pyc +0 -0
  27. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/exec_command.cpython-310.pyc +0 -0
  28. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/extension.cpython-310.pyc +0 -0
  29. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/from_template.cpython-310.pyc +0 -0
  30. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/fujitsuccompiler.cpython-310.pyc +0 -0
  31. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/intelccompiler.cpython-310.pyc +0 -0
  32. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/lib2def.cpython-310.pyc +0 -0
  33. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/line_endings.cpython-310.pyc +0 -0
  34. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/log.cpython-310.pyc +0 -0
  35. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/mingw32ccompiler.cpython-310.pyc +0 -0
  36. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/misc_util.cpython-310.pyc +0 -0
  37. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/msvc9compiler.cpython-310.pyc +0 -0
  38. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/msvccompiler.cpython-310.pyc +0 -0
  39. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/npy_pkg_config.cpython-310.pyc +0 -0
  40. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/numpy_distribution.cpython-310.pyc +0 -0
  41. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/pathccompiler.cpython-310.pyc +0 -0
  42. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/setup.cpython-310.pyc +0 -0
  43. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/system_info.cpython-310.pyc +0 -0
  44. env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/unixccompiler.cpython-310.pyc +0 -0
  45. env-llmeval/lib/python3.10/site-packages/numpy/distutils/_shell_utils.py +91 -0
  46. env-llmeval/lib/python3.10/site-packages/numpy/distutils/armccompiler.py +26 -0
  47. env-llmeval/lib/python3.10/site-packages/numpy/distutils/ccompiler.py +826 -0
  48. env-llmeval/lib/python3.10/site-packages/numpy/distutils/ccompiler_opt.py +0 -0
  49. env-llmeval/lib/python3.10/site-packages/numpy/distutils/conv_template.py +329 -0
  50. env-llmeval/lib/python3.10/site-packages/numpy/distutils/core.py +216 -0
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/bnb.cpython-310.pyc ADDED
Binary file (13.7 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/constants.cpython-310.pyc ADDED
Binary file (1.95 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/deepspeed.cpython-310.pyc ADDED
Binary file (9.46 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/environment.cpython-310.pyc ADDED
Binary file (10 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/imports.cpython-310.pyc ADDED
Binary file (10.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/launch.cpython-310.pyc ADDED
Binary file (16.9 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/megatron_lm.cpython-310.pyc ADDED
Binary file (38.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/modeling.cpython-310.pyc ADDED
Binary file (53.1 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/operations.cpython-310.pyc ADDED
Binary file (28.4 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/other.cpython-310.pyc ADDED
Binary file (10.4 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/random.cpython-310.pyc ADDED
Binary file (3.37 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/rich.cpython-310.pyc ADDED
Binary file (409 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/torch_xla.cpython-310.pyc ADDED
Binary file (1.36 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/tqdm.cpython-310.pyc ADDED
Binary file (917 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/transformer_engine.cpython-310.pyc ADDED
Binary file (2.09 kB). View file
 
env-llmeval/lib/python3.10/site-packages/accelerate/utils/__pycache__/versions.cpython-310.pyc ADDED
Binary file (1.68 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/_pytesttester.pyi ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections.abc import Iterable
2
+ from typing import Literal as L
3
+
4
+ __all__: list[str]
5
+
6
+ class PytestTester:
7
+ module_name: str
8
+ def __init__(self, module_name: str) -> None: ...
9
+ def __call__(
10
+ self,
11
+ label: L["fast", "full"] = ...,
12
+ verbose: int = ...,
13
+ extra_argv: None | Iterable[str] = ...,
14
+ doctests: L[False] = ...,
15
+ coverage: bool = ...,
16
+ durations: int = ...,
17
+ tests: None | Iterable[str] = ...,
18
+ ) -> bool: ...
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__init__.pyi ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ from typing import Any
2
+
3
+ # TODO: remove when the full numpy namespace is defined
4
+ def __getattr__(name: str) -> Any: ...
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (1.99 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/_shell_utils.cpython-310.pyc ADDED
Binary file (3.11 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/armccompiler.cpython-310.pyc ADDED
Binary file (963 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/ccompiler.cpython-310.pyc ADDED
Binary file (20.2 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/ccompiler_opt.cpython-310.pyc ADDED
Binary file (73.5 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/conv_template.cpython-310.pyc ADDED
Binary file (8.29 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/core.cpython-310.pyc ADDED
Binary file (4.78 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/cpuinfo.cpython-310.pyc ADDED
Binary file (29.6 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/exec_command.cpython-310.pyc ADDED
Binary file (9.19 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/extension.cpython-310.pyc ADDED
Binary file (2.65 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/from_template.cpython-310.pyc ADDED
Binary file (7.26 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/fujitsuccompiler.cpython-310.pyc ADDED
Binary file (997 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/intelccompiler.cpython-310.pyc ADDED
Binary file (3.61 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/lib2def.cpython-310.pyc ADDED
Binary file (3.36 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/line_endings.cpython-310.pyc ADDED
Binary file (2.09 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/log.cpython-310.pyc ADDED
Binary file (3.03 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/mingw32ccompiler.cpython-310.pyc ADDED
Binary file (13.5 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/misc_util.cpython-310.pyc ADDED
Binary file (73.9 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/msvc9compiler.cpython-310.pyc ADDED
Binary file (2.22 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/msvccompiler.cpython-310.pyc ADDED
Binary file (2.47 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/npy_pkg_config.cpython-310.pyc ADDED
Binary file (12.2 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/numpy_distribution.cpython-310.pyc ADDED
Binary file (810 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/pathccompiler.cpython-310.pyc ADDED
Binary file (941 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/setup.cpython-310.pyc ADDED
Binary file (766 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/system_info.cpython-310.pyc ADDED
Binary file (90 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/__pycache__/unixccompiler.cpython-310.pyc ADDED
Binary file (3.43 kB). View file
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/_shell_utils.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Helper functions for interacting with the shell, and consuming shell-style
3
+ parameters provided in config files.
4
+ """
5
+ import os
6
+ import shlex
7
+ import subprocess
8
+ try:
9
+ from shlex import quote
10
+ except ImportError:
11
+ from pipes import quote
12
+
13
+ __all__ = ['WindowsParser', 'PosixParser', 'NativeParser']
14
+
15
+
16
+ class CommandLineParser:
17
+ """
18
+ An object that knows how to split and join command-line arguments.
19
+
20
+ It must be true that ``argv == split(join(argv))`` for all ``argv``.
21
+ The reverse neednt be true - `join(split(cmd))` may result in the addition
22
+ or removal of unnecessary escaping.
23
+ """
24
+ @staticmethod
25
+ def join(argv):
26
+ """ Join a list of arguments into a command line string """
27
+ raise NotImplementedError
28
+
29
+ @staticmethod
30
+ def split(cmd):
31
+ """ Split a command line string into a list of arguments """
32
+ raise NotImplementedError
33
+
34
+
35
+ class WindowsParser:
36
+ """
37
+ The parsing behavior used by `subprocess.call("string")` on Windows, which
38
+ matches the Microsoft C/C++ runtime.
39
+
40
+ Note that this is _not_ the behavior of cmd.
41
+ """
42
+ @staticmethod
43
+ def join(argv):
44
+ # note that list2cmdline is specific to the windows syntax
45
+ return subprocess.list2cmdline(argv)
46
+
47
+ @staticmethod
48
+ def split(cmd):
49
+ import ctypes # guarded import for systems without ctypes
50
+ try:
51
+ ctypes.windll
52
+ except AttributeError:
53
+ raise NotImplementedError
54
+
55
+ # Windows has special parsing rules for the executable (no quotes),
56
+ # that we do not care about - insert a dummy element
57
+ if not cmd:
58
+ return []
59
+ cmd = 'dummy ' + cmd
60
+
61
+ CommandLineToArgvW = ctypes.windll.shell32.CommandLineToArgvW
62
+ CommandLineToArgvW.restype = ctypes.POINTER(ctypes.c_wchar_p)
63
+ CommandLineToArgvW.argtypes = (ctypes.c_wchar_p, ctypes.POINTER(ctypes.c_int))
64
+
65
+ nargs = ctypes.c_int()
66
+ lpargs = CommandLineToArgvW(cmd, ctypes.byref(nargs))
67
+ args = [lpargs[i] for i in range(nargs.value)]
68
+ assert not ctypes.windll.kernel32.LocalFree(lpargs)
69
+
70
+ # strip the element we inserted
71
+ assert args[0] == "dummy"
72
+ return args[1:]
73
+
74
+
75
+ class PosixParser:
76
+ """
77
+ The parsing behavior used by `subprocess.call("string", shell=True)` on Posix.
78
+ """
79
+ @staticmethod
80
+ def join(argv):
81
+ return ' '.join(quote(arg) for arg in argv)
82
+
83
+ @staticmethod
84
+ def split(cmd):
85
+ return shlex.split(cmd, posix=True)
86
+
87
+
88
+ if os.name == 'nt':
89
+ NativeParser = WindowsParser
90
+ elif os.name == 'posix':
91
+ NativeParser = PosixParser
env-llmeval/lib/python3.10/site-packages/numpy/distutils/armccompiler.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from distutils.unixccompiler import UnixCCompiler
2
+
3
+ class ArmCCompiler(UnixCCompiler):
4
+
5
+ """
6
+ Arm compiler.
7
+ """
8
+
9
+ compiler_type = 'arm'
10
+ cc_exe = 'armclang'
11
+ cxx_exe = 'armclang++'
12
+
13
+ def __init__(self, verbose=0, dry_run=0, force=0):
14
+ UnixCCompiler.__init__(self, verbose, dry_run, force)
15
+ cc_compiler = self.cc_exe
16
+ cxx_compiler = self.cxx_exe
17
+ self.set_executables(compiler=cc_compiler +
18
+ ' -O3 -fPIC',
19
+ compiler_so=cc_compiler +
20
+ ' -O3 -fPIC',
21
+ compiler_cxx=cxx_compiler +
22
+ ' -O3 -fPIC',
23
+ linker_exe=cc_compiler +
24
+ ' -lamath',
25
+ linker_so=cc_compiler +
26
+ ' -lamath -shared')
env-llmeval/lib/python3.10/site-packages/numpy/distutils/ccompiler.py ADDED
@@ -0,0 +1,826 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+ import sys
4
+ import platform
5
+ import shlex
6
+ import time
7
+ import subprocess
8
+ from copy import copy
9
+ from pathlib import Path
10
+ from distutils import ccompiler
11
+ from distutils.ccompiler import (
12
+ compiler_class, gen_lib_options, get_default_compiler, new_compiler,
13
+ CCompiler
14
+ )
15
+ from distutils.errors import (
16
+ DistutilsExecError, DistutilsModuleError, DistutilsPlatformError,
17
+ CompileError, UnknownFileError
18
+ )
19
+ from distutils.sysconfig import customize_compiler
20
+ from distutils.version import LooseVersion
21
+
22
+ from numpy.distutils import log
23
+ from numpy.distutils.exec_command import (
24
+ filepath_from_subprocess_output, forward_bytes_to_stdout
25
+ )
26
+ from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, \
27
+ get_num_build_jobs, \
28
+ _commandline_dep_string, \
29
+ sanitize_cxx_flags
30
+
31
+ # globals for parallel build management
32
+ import threading
33
+
34
+ _job_semaphore = None
35
+ _global_lock = threading.Lock()
36
+ _processing_files = set()
37
+
38
+
39
+ def _needs_build(obj, cc_args, extra_postargs, pp_opts):
40
+ """
41
+ Check if an objects needs to be rebuild based on its dependencies
42
+
43
+ Parameters
44
+ ----------
45
+ obj : str
46
+ object file
47
+
48
+ Returns
49
+ -------
50
+ bool
51
+ """
52
+ # defined in unixcompiler.py
53
+ dep_file = obj + '.d'
54
+ if not os.path.exists(dep_file):
55
+ return True
56
+
57
+ # dep_file is a makefile containing 'object: dependencies'
58
+ # formatted like posix shell (spaces escaped, \ line continuations)
59
+ # the last line contains the compiler commandline arguments as some
60
+ # projects may compile an extension multiple times with different
61
+ # arguments
62
+ with open(dep_file) as f:
63
+ lines = f.readlines()
64
+
65
+ cmdline =_commandline_dep_string(cc_args, extra_postargs, pp_opts)
66
+ last_cmdline = lines[-1]
67
+ if last_cmdline != cmdline:
68
+ return True
69
+
70
+ contents = ''.join(lines[:-1])
71
+ deps = [x for x in shlex.split(contents, posix=True)
72
+ if x != "\n" and not x.endswith(":")]
73
+
74
+ try:
75
+ t_obj = os.stat(obj).st_mtime
76
+
77
+ # check if any of the dependencies is newer than the object
78
+ # the dependencies includes the source used to create the object
79
+ for f in deps:
80
+ if os.stat(f).st_mtime > t_obj:
81
+ return True
82
+ except OSError:
83
+ # no object counts as newer (shouldn't happen if dep_file exists)
84
+ return True
85
+
86
+ return False
87
+
88
+
89
+ def replace_method(klass, method_name, func):
90
+ # Py3k does not have unbound method anymore, MethodType does not work
91
+ m = lambda self, *args, **kw: func(self, *args, **kw)
92
+ setattr(klass, method_name, m)
93
+
94
+
95
+ ######################################################################
96
+ ## Method that subclasses may redefine. But don't call this method,
97
+ ## it i private to CCompiler class and may return unexpected
98
+ ## results if used elsewhere. So, you have been warned..
99
+
100
+ def CCompiler_find_executables(self):
101
+ """
102
+ Does nothing here, but is called by the get_version method and can be
103
+ overridden by subclasses. In particular it is redefined in the `FCompiler`
104
+ class where more documentation can be found.
105
+
106
+ """
107
+ pass
108
+
109
+
110
+ replace_method(CCompiler, 'find_executables', CCompiler_find_executables)
111
+
112
+
113
+ # Using customized CCompiler.spawn.
114
+ def CCompiler_spawn(self, cmd, display=None, env=None):
115
+ """
116
+ Execute a command in a sub-process.
117
+
118
+ Parameters
119
+ ----------
120
+ cmd : str
121
+ The command to execute.
122
+ display : str or sequence of str, optional
123
+ The text to add to the log file kept by `numpy.distutils`.
124
+ If not given, `display` is equal to `cmd`.
125
+ env : a dictionary for environment variables, optional
126
+
127
+ Returns
128
+ -------
129
+ None
130
+
131
+ Raises
132
+ ------
133
+ DistutilsExecError
134
+ If the command failed, i.e. the exit status was not 0.
135
+
136
+ """
137
+ env = env if env is not None else dict(os.environ)
138
+ if display is None:
139
+ display = cmd
140
+ if is_sequence(display):
141
+ display = ' '.join(list(display))
142
+ log.info(display)
143
+ try:
144
+ if self.verbose:
145
+ subprocess.check_output(cmd, env=env)
146
+ else:
147
+ subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env)
148
+ except subprocess.CalledProcessError as exc:
149
+ o = exc.output
150
+ s = exc.returncode
151
+ except OSError as e:
152
+ # OSError doesn't have the same hooks for the exception
153
+ # output, but exec_command() historically would use an
154
+ # empty string for EnvironmentError (base class for
155
+ # OSError)
156
+ # o = b''
157
+ # still that would make the end-user lost in translation!
158
+ o = f"\n\n{e}\n\n\n"
159
+ try:
160
+ o = o.encode(sys.stdout.encoding)
161
+ except AttributeError:
162
+ o = o.encode('utf8')
163
+ # status previously used by exec_command() for parent
164
+ # of OSError
165
+ s = 127
166
+ else:
167
+ # use a convenience return here so that any kind of
168
+ # caught exception will execute the default code after the
169
+ # try / except block, which handles various exceptions
170
+ return None
171
+
172
+ if is_sequence(cmd):
173
+ cmd = ' '.join(list(cmd))
174
+
175
+ if self.verbose:
176
+ forward_bytes_to_stdout(o)
177
+
178
+ if re.search(b'Too many open files', o):
179
+ msg = '\nTry rerunning setup command until build succeeds.'
180
+ else:
181
+ msg = ''
182
+ raise DistutilsExecError('Command "%s" failed with exit status %d%s' %
183
+ (cmd, s, msg))
184
+
185
+ replace_method(CCompiler, 'spawn', CCompiler_spawn)
186
+
187
+ def CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
188
+ """
189
+ Return the name of the object files for the given source files.
190
+
191
+ Parameters
192
+ ----------
193
+ source_filenames : list of str
194
+ The list of paths to source files. Paths can be either relative or
195
+ absolute, this is handled transparently.
196
+ strip_dir : bool, optional
197
+ Whether to strip the directory from the returned paths. If True,
198
+ the file name prepended by `output_dir` is returned. Default is False.
199
+ output_dir : str, optional
200
+ If given, this path is prepended to the returned paths to the
201
+ object files.
202
+
203
+ Returns
204
+ -------
205
+ obj_names : list of str
206
+ The list of paths to the object files corresponding to the source
207
+ files in `source_filenames`.
208
+
209
+ """
210
+ if output_dir is None:
211
+ output_dir = ''
212
+ obj_names = []
213
+ for src_name in source_filenames:
214
+ base, ext = os.path.splitext(os.path.normpath(src_name))
215
+ base = os.path.splitdrive(base)[1] # Chop off the drive
216
+ base = base[os.path.isabs(base):] # If abs, chop off leading /
217
+ if base.startswith('..'):
218
+ # Resolve starting relative path components, middle ones
219
+ # (if any) have been handled by os.path.normpath above.
220
+ i = base.rfind('..')+2
221
+ d = base[:i]
222
+ d = os.path.basename(os.path.abspath(d))
223
+ base = d + base[i:]
224
+ if ext not in self.src_extensions:
225
+ raise UnknownFileError("unknown file type '%s' (from '%s')" % (ext, src_name))
226
+ if strip_dir:
227
+ base = os.path.basename(base)
228
+ obj_name = os.path.join(output_dir, base + self.obj_extension)
229
+ obj_names.append(obj_name)
230
+ return obj_names
231
+
232
+ replace_method(CCompiler, 'object_filenames', CCompiler_object_filenames)
233
+
234
+ def CCompiler_compile(self, sources, output_dir=None, macros=None,
235
+ include_dirs=None, debug=0, extra_preargs=None,
236
+ extra_postargs=None, depends=None):
237
+ """
238
+ Compile one or more source files.
239
+
240
+ Please refer to the Python distutils API reference for more details.
241
+
242
+ Parameters
243
+ ----------
244
+ sources : list of str
245
+ A list of filenames
246
+ output_dir : str, optional
247
+ Path to the output directory.
248
+ macros : list of tuples
249
+ A list of macro definitions.
250
+ include_dirs : list of str, optional
251
+ The directories to add to the default include file search path for
252
+ this compilation only.
253
+ debug : bool, optional
254
+ Whether or not to output debug symbols in or alongside the object
255
+ file(s).
256
+ extra_preargs, extra_postargs : ?
257
+ Extra pre- and post-arguments.
258
+ depends : list of str, optional
259
+ A list of file names that all targets depend on.
260
+
261
+ Returns
262
+ -------
263
+ objects : list of str
264
+ A list of object file names, one per source file `sources`.
265
+
266
+ Raises
267
+ ------
268
+ CompileError
269
+ If compilation fails.
270
+
271
+ """
272
+ global _job_semaphore
273
+
274
+ jobs = get_num_build_jobs()
275
+
276
+ # setup semaphore to not exceed number of compile jobs when parallelized at
277
+ # extension level (python >= 3.5)
278
+ with _global_lock:
279
+ if _job_semaphore is None:
280
+ _job_semaphore = threading.Semaphore(jobs)
281
+
282
+ if not sources:
283
+ return []
284
+ from numpy.distutils.fcompiler import (FCompiler,
285
+ FORTRAN_COMMON_FIXED_EXTENSIONS,
286
+ has_f90_header)
287
+ if isinstance(self, FCompiler):
288
+ display = []
289
+ for fc in ['f77', 'f90', 'fix']:
290
+ fcomp = getattr(self, 'compiler_'+fc)
291
+ if fcomp is None:
292
+ continue
293
+ display.append("Fortran %s compiler: %s" % (fc, ' '.join(fcomp)))
294
+ display = '\n'.join(display)
295
+ else:
296
+ ccomp = self.compiler_so
297
+ display = "C compiler: %s\n" % (' '.join(ccomp),)
298
+ log.info(display)
299
+ macros, objects, extra_postargs, pp_opts, build = \
300
+ self._setup_compile(output_dir, macros, include_dirs, sources,
301
+ depends, extra_postargs)
302
+ cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
303
+ display = "compile options: '%s'" % (' '.join(cc_args))
304
+ if extra_postargs:
305
+ display += "\nextra options: '%s'" % (' '.join(extra_postargs))
306
+ log.info(display)
307
+
308
+ def single_compile(args):
309
+ obj, (src, ext) = args
310
+ if not _needs_build(obj, cc_args, extra_postargs, pp_opts):
311
+ return
312
+
313
+ # check if we are currently already processing the same object
314
+ # happens when using the same source in multiple extensions
315
+ while True:
316
+ # need explicit lock as there is no atomic check and add with GIL
317
+ with _global_lock:
318
+ # file not being worked on, start working
319
+ if obj not in _processing_files:
320
+ _processing_files.add(obj)
321
+ break
322
+ # wait for the processing to end
323
+ time.sleep(0.1)
324
+
325
+ try:
326
+ # retrieve slot from our #job semaphore and build
327
+ with _job_semaphore:
328
+ self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
329
+ finally:
330
+ # register being done processing
331
+ with _global_lock:
332
+ _processing_files.remove(obj)
333
+
334
+
335
+ if isinstance(self, FCompiler):
336
+ objects_to_build = list(build.keys())
337
+ f77_objects, other_objects = [], []
338
+ for obj in objects:
339
+ if obj in objects_to_build:
340
+ src, ext = build[obj]
341
+ if self.compiler_type=='absoft':
342
+ obj = cyg2win32(obj)
343
+ src = cyg2win32(src)
344
+ if Path(src).suffix.lower() in FORTRAN_COMMON_FIXED_EXTENSIONS \
345
+ and not has_f90_header(src):
346
+ f77_objects.append((obj, (src, ext)))
347
+ else:
348
+ other_objects.append((obj, (src, ext)))
349
+
350
+ # f77 objects can be built in parallel
351
+ build_items = f77_objects
352
+ # build f90 modules serial, module files are generated during
353
+ # compilation and may be used by files later in the list so the
354
+ # ordering is important
355
+ for o in other_objects:
356
+ single_compile(o)
357
+ else:
358
+ build_items = build.items()
359
+
360
+ if len(build) > 1 and jobs > 1:
361
+ # build parallel
362
+ from concurrent.futures import ThreadPoolExecutor
363
+ with ThreadPoolExecutor(jobs) as pool:
364
+ res = pool.map(single_compile, build_items)
365
+ list(res) # access result to raise errors
366
+ else:
367
+ # build serial
368
+ for o in build_items:
369
+ single_compile(o)
370
+
371
+ # Return *all* object filenames, not just the ones we just built.
372
+ return objects
373
+
374
+ replace_method(CCompiler, 'compile', CCompiler_compile)
375
+
376
+ def CCompiler_customize_cmd(self, cmd, ignore=()):
377
+ """
378
+ Customize compiler using distutils command.
379
+
380
+ Parameters
381
+ ----------
382
+ cmd : class instance
383
+ An instance inheriting from `distutils.cmd.Command`.
384
+ ignore : sequence of str, optional
385
+ List of `CCompiler` commands (without ``'set_'``) that should not be
386
+ altered. Strings that are checked for are:
387
+ ``('include_dirs', 'define', 'undef', 'libraries', 'library_dirs',
388
+ 'rpath', 'link_objects')``.
389
+
390
+ Returns
391
+ -------
392
+ None
393
+
394
+ """
395
+ log.info('customize %s using %s' % (self.__class__.__name__,
396
+ cmd.__class__.__name__))
397
+
398
+ if (
399
+ hasattr(self, 'compiler') and
400
+ 'clang' in self.compiler[0] and
401
+ not (platform.machine() == 'arm64' and sys.platform == 'darwin')
402
+ ):
403
+ # clang defaults to a non-strict floating error point model.
404
+ # However, '-ftrapping-math' is not currently supported (2023-04-08)
405
+ # for macosx_arm64.
406
+ # Since NumPy and most Python libs give warnings for these, override:
407
+ self.compiler.append('-ftrapping-math')
408
+ self.compiler_so.append('-ftrapping-math')
409
+
410
+ def allow(attr):
411
+ return getattr(cmd, attr, None) is not None and attr not in ignore
412
+
413
+ if allow('include_dirs'):
414
+ self.set_include_dirs(cmd.include_dirs)
415
+ if allow('define'):
416
+ for (name, value) in cmd.define:
417
+ self.define_macro(name, value)
418
+ if allow('undef'):
419
+ for macro in cmd.undef:
420
+ self.undefine_macro(macro)
421
+ if allow('libraries'):
422
+ self.set_libraries(self.libraries + cmd.libraries)
423
+ if allow('library_dirs'):
424
+ self.set_library_dirs(self.library_dirs + cmd.library_dirs)
425
+ if allow('rpath'):
426
+ self.set_runtime_library_dirs(cmd.rpath)
427
+ if allow('link_objects'):
428
+ self.set_link_objects(cmd.link_objects)
429
+
430
+ replace_method(CCompiler, 'customize_cmd', CCompiler_customize_cmd)
431
+
432
+ def _compiler_to_string(compiler):
433
+ props = []
434
+ mx = 0
435
+ keys = list(compiler.executables.keys())
436
+ for key in ['version', 'libraries', 'library_dirs',
437
+ 'object_switch', 'compile_switch',
438
+ 'include_dirs', 'define', 'undef', 'rpath', 'link_objects']:
439
+ if key not in keys:
440
+ keys.append(key)
441
+ for key in keys:
442
+ if hasattr(compiler, key):
443
+ v = getattr(compiler, key)
444
+ mx = max(mx, len(key))
445
+ props.append((key, repr(v)))
446
+ fmt = '%-' + repr(mx+1) + 's = %s'
447
+ lines = [fmt % prop for prop in props]
448
+ return '\n'.join(lines)
449
+
450
+ def CCompiler_show_customization(self):
451
+ """
452
+ Print the compiler customizations to stdout.
453
+
454
+ Parameters
455
+ ----------
456
+ None
457
+
458
+ Returns
459
+ -------
460
+ None
461
+
462
+ Notes
463
+ -----
464
+ Printing is only done if the distutils log threshold is < 2.
465
+
466
+ """
467
+ try:
468
+ self.get_version()
469
+ except Exception:
470
+ pass
471
+ if log._global_log.threshold<2:
472
+ print('*'*80)
473
+ print(self.__class__)
474
+ print(_compiler_to_string(self))
475
+ print('*'*80)
476
+
477
+ replace_method(CCompiler, 'show_customization', CCompiler_show_customization)
478
+
479
+ def CCompiler_customize(self, dist, need_cxx=0):
480
+ """
481
+ Do any platform-specific customization of a compiler instance.
482
+
483
+ This method calls `distutils.sysconfig.customize_compiler` for
484
+ platform-specific customization, as well as optionally remove a flag
485
+ to suppress spurious warnings in case C++ code is being compiled.
486
+
487
+ Parameters
488
+ ----------
489
+ dist : object
490
+ This parameter is not used for anything.
491
+ need_cxx : bool, optional
492
+ Whether or not C++ has to be compiled. If so (True), the
493
+ ``"-Wstrict-prototypes"`` option is removed to prevent spurious
494
+ warnings. Default is False.
495
+
496
+ Returns
497
+ -------
498
+ None
499
+
500
+ Notes
501
+ -----
502
+ All the default options used by distutils can be extracted with::
503
+
504
+ from distutils import sysconfig
505
+ sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'BASECFLAGS',
506
+ 'CCSHARED', 'LDSHARED', 'SO')
507
+
508
+ """
509
+ # See FCompiler.customize for suggested usage.
510
+ log.info('customize %s' % (self.__class__.__name__))
511
+ customize_compiler(self)
512
+ if need_cxx:
513
+ # In general, distutils uses -Wstrict-prototypes, but this option is
514
+ # not valid for C++ code, only for C. Remove it if it's there to
515
+ # avoid a spurious warning on every compilation.
516
+ try:
517
+ self.compiler_so.remove('-Wstrict-prototypes')
518
+ except (AttributeError, ValueError):
519
+ pass
520
+
521
+ if hasattr(self, 'compiler') and 'cc' in self.compiler[0]:
522
+ if not self.compiler_cxx:
523
+ if self.compiler[0].startswith('gcc'):
524
+ a, b = 'gcc', 'g++'
525
+ else:
526
+ a, b = 'cc', 'c++'
527
+ self.compiler_cxx = [self.compiler[0].replace(a, b)]\
528
+ + self.compiler[1:]
529
+ else:
530
+ if hasattr(self, 'compiler'):
531
+ log.warn("#### %s #######" % (self.compiler,))
532
+ if not hasattr(self, 'compiler_cxx'):
533
+ log.warn('Missing compiler_cxx fix for ' + self.__class__.__name__)
534
+
535
+
536
+ # check if compiler supports gcc style automatic dependencies
537
+ # run on every extension so skip for known good compilers
538
+ if hasattr(self, 'compiler') and ('gcc' in self.compiler[0] or
539
+ 'g++' in self.compiler[0] or
540
+ 'clang' in self.compiler[0]):
541
+ self._auto_depends = True
542
+ elif os.name == 'posix':
543
+ import tempfile
544
+ import shutil
545
+ tmpdir = tempfile.mkdtemp()
546
+ try:
547
+ fn = os.path.join(tmpdir, "file.c")
548
+ with open(fn, "w") as f:
549
+ f.write("int a;\n")
550
+ self.compile([fn], output_dir=tmpdir,
551
+ extra_preargs=['-MMD', '-MF', fn + '.d'])
552
+ self._auto_depends = True
553
+ except CompileError:
554
+ self._auto_depends = False
555
+ finally:
556
+ shutil.rmtree(tmpdir)
557
+
558
+ return
559
+
560
+ replace_method(CCompiler, 'customize', CCompiler_customize)
561
+
562
+ def simple_version_match(pat=r'[-.\d]+', ignore='', start=''):
563
+ """
564
+ Simple matching of version numbers, for use in CCompiler and FCompiler.
565
+
566
+ Parameters
567
+ ----------
568
+ pat : str, optional
569
+ A regular expression matching version numbers.
570
+ Default is ``r'[-.\\d]+'``.
571
+ ignore : str, optional
572
+ A regular expression matching patterns to skip.
573
+ Default is ``''``, in which case nothing is skipped.
574
+ start : str, optional
575
+ A regular expression matching the start of where to start looking
576
+ for version numbers.
577
+ Default is ``''``, in which case searching is started at the
578
+ beginning of the version string given to `matcher`.
579
+
580
+ Returns
581
+ -------
582
+ matcher : callable
583
+ A function that is appropriate to use as the ``.version_match``
584
+ attribute of a `CCompiler` class. `matcher` takes a single parameter,
585
+ a version string.
586
+
587
+ """
588
+ def matcher(self, version_string):
589
+ # version string may appear in the second line, so getting rid
590
+ # of new lines:
591
+ version_string = version_string.replace('\n', ' ')
592
+ pos = 0
593
+ if start:
594
+ m = re.match(start, version_string)
595
+ if not m:
596
+ return None
597
+ pos = m.end()
598
+ while True:
599
+ m = re.search(pat, version_string[pos:])
600
+ if not m:
601
+ return None
602
+ if ignore and re.match(ignore, m.group(0)):
603
+ pos = m.end()
604
+ continue
605
+ break
606
+ return m.group(0)
607
+ return matcher
608
+
609
+ def CCompiler_get_version(self, force=False, ok_status=[0]):
610
+ """
611
+ Return compiler version, or None if compiler is not available.
612
+
613
+ Parameters
614
+ ----------
615
+ force : bool, optional
616
+ If True, force a new determination of the version, even if the
617
+ compiler already has a version attribute. Default is False.
618
+ ok_status : list of int, optional
619
+ The list of status values returned by the version look-up process
620
+ for which a version string is returned. If the status value is not
621
+ in `ok_status`, None is returned. Default is ``[0]``.
622
+
623
+ Returns
624
+ -------
625
+ version : str or None
626
+ Version string, in the format of `distutils.version.LooseVersion`.
627
+
628
+ """
629
+ if not force and hasattr(self, 'version'):
630
+ return self.version
631
+ self.find_executables()
632
+ try:
633
+ version_cmd = self.version_cmd
634
+ except AttributeError:
635
+ return None
636
+ if not version_cmd or not version_cmd[0]:
637
+ return None
638
+ try:
639
+ matcher = self.version_match
640
+ except AttributeError:
641
+ try:
642
+ pat = self.version_pattern
643
+ except AttributeError:
644
+ return None
645
+ def matcher(version_string):
646
+ m = re.match(pat, version_string)
647
+ if not m:
648
+ return None
649
+ version = m.group('version')
650
+ return version
651
+
652
+ try:
653
+ output = subprocess.check_output(version_cmd, stderr=subprocess.STDOUT)
654
+ except subprocess.CalledProcessError as exc:
655
+ output = exc.output
656
+ status = exc.returncode
657
+ except OSError:
658
+ # match the historical returns for a parent
659
+ # exception class caught by exec_command()
660
+ status = 127
661
+ output = b''
662
+ else:
663
+ # output isn't actually a filepath but we do this
664
+ # for now to match previous distutils behavior
665
+ output = filepath_from_subprocess_output(output)
666
+ status = 0
667
+
668
+ version = None
669
+ if status in ok_status:
670
+ version = matcher(output)
671
+ if version:
672
+ version = LooseVersion(version)
673
+ self.version = version
674
+ return version
675
+
676
+ replace_method(CCompiler, 'get_version', CCompiler_get_version)
677
+
678
+ def CCompiler_cxx_compiler(self):
679
+ """
680
+ Return the C++ compiler.
681
+
682
+ Parameters
683
+ ----------
684
+ None
685
+
686
+ Returns
687
+ -------
688
+ cxx : class instance
689
+ The C++ compiler, as a `CCompiler` instance.
690
+
691
+ """
692
+ if self.compiler_type in ('msvc', 'intelw', 'intelemw'):
693
+ return self
694
+
695
+ cxx = copy(self)
696
+ cxx.compiler_cxx = cxx.compiler_cxx
697
+ cxx.compiler_so = [cxx.compiler_cxx[0]] + \
698
+ sanitize_cxx_flags(cxx.compiler_so[1:])
699
+ if (sys.platform.startswith(('aix', 'os400')) and
700
+ 'ld_so_aix' in cxx.linker_so[0]):
701
+ # AIX needs the ld_so_aix script included with Python
702
+ cxx.linker_so = [cxx.linker_so[0], cxx.compiler_cxx[0]] \
703
+ + cxx.linker_so[2:]
704
+ if sys.platform.startswith('os400'):
705
+ #This is required by i 7.4 and prievous for PRId64 in printf() call.
706
+ cxx.compiler_so.append('-D__STDC_FORMAT_MACROS')
707
+ #This a bug of gcc10.3, which failed to handle the TLS init.
708
+ cxx.compiler_so.append('-fno-extern-tls-init')
709
+ cxx.linker_so.append('-fno-extern-tls-init')
710
+ else:
711
+ cxx.linker_so = [cxx.compiler_cxx[0]] + cxx.linker_so[1:]
712
+ return cxx
713
+
714
+ replace_method(CCompiler, 'cxx_compiler', CCompiler_cxx_compiler)
715
+
716
+ compiler_class['intel'] = ('intelccompiler', 'IntelCCompiler',
717
+ "Intel C Compiler for 32-bit applications")
718
+ compiler_class['intele'] = ('intelccompiler', 'IntelItaniumCCompiler',
719
+ "Intel C Itanium Compiler for Itanium-based applications")
720
+ compiler_class['intelem'] = ('intelccompiler', 'IntelEM64TCCompiler',
721
+ "Intel C Compiler for 64-bit applications")
722
+ compiler_class['intelw'] = ('intelccompiler', 'IntelCCompilerW',
723
+ "Intel C Compiler for 32-bit applications on Windows")
724
+ compiler_class['intelemw'] = ('intelccompiler', 'IntelEM64TCCompilerW',
725
+ "Intel C Compiler for 64-bit applications on Windows")
726
+ compiler_class['pathcc'] = ('pathccompiler', 'PathScaleCCompiler',
727
+ "PathScale Compiler for SiCortex-based applications")
728
+ compiler_class['arm'] = ('armccompiler', 'ArmCCompiler',
729
+ "Arm C Compiler")
730
+ compiler_class['fujitsu'] = ('fujitsuccompiler', 'FujitsuCCompiler',
731
+ "Fujitsu C Compiler")
732
+
733
+ ccompiler._default_compilers += (('linux.*', 'intel'),
734
+ ('linux.*', 'intele'),
735
+ ('linux.*', 'intelem'),
736
+ ('linux.*', 'pathcc'),
737
+ ('nt', 'intelw'),
738
+ ('nt', 'intelemw'))
739
+
740
+ if sys.platform == 'win32':
741
+ compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',
742
+ "Mingw32 port of GNU C Compiler for Win32"\
743
+ "(for MSC built Python)")
744
+ if mingw32():
745
+ # On windows platforms, we want to default to mingw32 (gcc)
746
+ # because msvc can't build blitz stuff.
747
+ log.info('Setting mingw32 as default compiler for nt.')
748
+ ccompiler._default_compilers = (('nt', 'mingw32'),) \
749
+ + ccompiler._default_compilers
750
+
751
+
752
+ _distutils_new_compiler = new_compiler
753
+ def new_compiler (plat=None,
754
+ compiler=None,
755
+ verbose=None,
756
+ dry_run=0,
757
+ force=0):
758
+ # Try first C compilers from numpy.distutils.
759
+ if verbose is None:
760
+ verbose = log.get_threshold() <= log.INFO
761
+ if plat is None:
762
+ plat = os.name
763
+ try:
764
+ if compiler is None:
765
+ compiler = get_default_compiler(plat)
766
+ (module_name, class_name, long_description) = compiler_class[compiler]
767
+ except KeyError:
768
+ msg = "don't know how to compile C/C++ code on platform '%s'" % plat
769
+ if compiler is not None:
770
+ msg = msg + " with '%s' compiler" % compiler
771
+ raise DistutilsPlatformError(msg)
772
+ module_name = "numpy.distutils." + module_name
773
+ try:
774
+ __import__ (module_name)
775
+ except ImportError as e:
776
+ msg = str(e)
777
+ log.info('%s in numpy.distutils; trying from distutils',
778
+ str(msg))
779
+ module_name = module_name[6:]
780
+ try:
781
+ __import__(module_name)
782
+ except ImportError as e:
783
+ msg = str(e)
784
+ raise DistutilsModuleError("can't compile C/C++ code: unable to load module '%s'" % \
785
+ module_name)
786
+ try:
787
+ module = sys.modules[module_name]
788
+ klass = vars(module)[class_name]
789
+ except KeyError:
790
+ raise DistutilsModuleError(("can't compile C/C++ code: unable to find class '%s' " +
791
+ "in module '%s'") % (class_name, module_name))
792
+ compiler = klass(None, dry_run, force)
793
+ compiler.verbose = verbose
794
+ log.debug('new_compiler returns %s' % (klass))
795
+ return compiler
796
+
797
+ ccompiler.new_compiler = new_compiler
798
+
799
+ _distutils_gen_lib_options = gen_lib_options
800
+ def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
801
+ # the version of this function provided by CPython allows the following
802
+ # to return lists, which are unpacked automatically:
803
+ # - compiler.runtime_library_dir_option
804
+ # our version extends the behavior to:
805
+ # - compiler.library_dir_option
806
+ # - compiler.library_option
807
+ # - compiler.find_library_file
808
+ r = _distutils_gen_lib_options(compiler, library_dirs,
809
+ runtime_library_dirs, libraries)
810
+ lib_opts = []
811
+ for i in r:
812
+ if is_sequence(i):
813
+ lib_opts.extend(list(i))
814
+ else:
815
+ lib_opts.append(i)
816
+ return lib_opts
817
+ ccompiler.gen_lib_options = gen_lib_options
818
+
819
+ # Also fix up the various compiler modules, which do
820
+ # from distutils.ccompiler import gen_lib_options
821
+ # Don't bother with mwerks, as we don't support Classic Mac.
822
+ for _cc in ['msvc9', 'msvc', '_msvc', 'bcpp', 'cygwinc', 'emxc', 'unixc']:
823
+ _m = sys.modules.get('distutils.' + _cc + 'compiler')
824
+ if _m is not None:
825
+ setattr(_m, 'gen_lib_options', gen_lib_options)
826
+
env-llmeval/lib/python3.10/site-packages/numpy/distutils/ccompiler_opt.py ADDED
The diff for this file is too large to render. See raw diff
 
env-llmeval/lib/python3.10/site-packages/numpy/distutils/conv_template.py ADDED
@@ -0,0 +1,329 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ takes templated file .xxx.src and produces .xxx file where .xxx is
4
+ .i or .c or .h, using the following template rules
5
+
6
+ /**begin repeat -- on a line by itself marks the start of a repeated code
7
+ segment
8
+ /**end repeat**/ -- on a line by itself marks it's end
9
+
10
+ After the /**begin repeat and before the */, all the named templates are placed
11
+ these should all have the same number of replacements
12
+
13
+ Repeat blocks can be nested, with each nested block labeled with its depth,
14
+ i.e.
15
+ /**begin repeat1
16
+ *....
17
+ */
18
+ /**end repeat1**/
19
+
20
+ When using nested loops, you can optionally exclude particular
21
+ combinations of the variables using (inside the comment portion of the inner loop):
22
+
23
+ :exclude: var1=value1, var2=value2, ...
24
+
25
+ This will exclude the pattern where var1 is value1 and var2 is value2 when
26
+ the result is being generated.
27
+
28
+
29
+ In the main body each replace will use one entry from the list of named replacements
30
+
31
+ Note that all #..# forms in a block must have the same number of
32
+ comma-separated entries.
33
+
34
+ Example:
35
+
36
+ An input file containing
37
+
38
+ /**begin repeat
39
+ * #a = 1,2,3#
40
+ * #b = 1,2,3#
41
+ */
42
+
43
+ /**begin repeat1
44
+ * #c = ted, jim#
45
+ */
46
+ @a@, @b@, @c@
47
+ /**end repeat1**/
48
+
49
+ /**end repeat**/
50
+
51
+ produces
52
+
53
+ line 1 "template.c.src"
54
+
55
+ /*
56
+ *********************************************************************
57
+ ** This file was autogenerated from a template DO NOT EDIT!!**
58
+ ** Changes should be made to the original source (.src) file **
59
+ *********************************************************************
60
+ */
61
+
62
+ #line 9
63
+ 1, 1, ted
64
+
65
+ #line 9
66
+ 1, 1, jim
67
+
68
+ #line 9
69
+ 2, 2, ted
70
+
71
+ #line 9
72
+ 2, 2, jim
73
+
74
+ #line 9
75
+ 3, 3, ted
76
+
77
+ #line 9
78
+ 3, 3, jim
79
+
80
+ """
81
+
82
+ __all__ = ['process_str', 'process_file']
83
+
84
+ import os
85
+ import sys
86
+ import re
87
+
88
+ # names for replacement that are already global.
89
+ global_names = {}
90
+
91
+ # header placed at the front of head processed file
92
+ header =\
93
+ """
94
+ /*
95
+ *****************************************************************************
96
+ ** This file was autogenerated from a template DO NOT EDIT!!!! **
97
+ ** Changes should be made to the original source (.src) file **
98
+ *****************************************************************************
99
+ */
100
+
101
+ """
102
+ # Parse string for repeat loops
103
+ def parse_structure(astr, level):
104
+ """
105
+ The returned line number is from the beginning of the string, starting
106
+ at zero. Returns an empty list if no loops found.
107
+
108
+ """
109
+ if level == 0 :
110
+ loopbeg = "/**begin repeat"
111
+ loopend = "/**end repeat**/"
112
+ else :
113
+ loopbeg = "/**begin repeat%d" % level
114
+ loopend = "/**end repeat%d**/" % level
115
+
116
+ ind = 0
117
+ line = 0
118
+ spanlist = []
119
+ while True:
120
+ start = astr.find(loopbeg, ind)
121
+ if start == -1:
122
+ break
123
+ start2 = astr.find("*/", start)
124
+ start2 = astr.find("\n", start2)
125
+ fini1 = astr.find(loopend, start2)
126
+ fini2 = astr.find("\n", fini1)
127
+ line += astr.count("\n", ind, start2+1)
128
+ spanlist.append((start, start2+1, fini1, fini2+1, line))
129
+ line += astr.count("\n", start2+1, fini2)
130
+ ind = fini2
131
+ spanlist.sort()
132
+ return spanlist
133
+
134
+
135
+ def paren_repl(obj):
136
+ torep = obj.group(1)
137
+ numrep = obj.group(2)
138
+ return ','.join([torep]*int(numrep))
139
+
140
+ parenrep = re.compile(r"\(([^)]*)\)\*(\d+)")
141
+ plainrep = re.compile(r"([^*]+)\*(\d+)")
142
+ def parse_values(astr):
143
+ # replaces all occurrences of '(a,b,c)*4' in astr
144
+ # with 'a,b,c,a,b,c,a,b,c,a,b,c'. Empty braces generate
145
+ # empty values, i.e., ()*4 yields ',,,'. The result is
146
+ # split at ',' and a list of values returned.
147
+ astr = parenrep.sub(paren_repl, astr)
148
+ # replaces occurrences of xxx*3 with xxx, xxx, xxx
149
+ astr = ','.join([plainrep.sub(paren_repl, x.strip())
150
+ for x in astr.split(',')])
151
+ return astr.split(',')
152
+
153
+
154
+ stripast = re.compile(r"\n\s*\*?")
155
+ named_re = re.compile(r"#\s*(\w*)\s*=([^#]*)#")
156
+ exclude_vars_re = re.compile(r"(\w*)=(\w*)")
157
+ exclude_re = re.compile(":exclude:")
158
+ def parse_loop_header(loophead) :
159
+ """Find all named replacements in the header
160
+
161
+ Returns a list of dictionaries, one for each loop iteration,
162
+ where each key is a name to be substituted and the corresponding
163
+ value is the replacement string.
164
+
165
+ Also return a list of exclusions. The exclusions are dictionaries
166
+ of key value pairs. There can be more than one exclusion.
167
+ [{'var1':'value1', 'var2', 'value2'[,...]}, ...]
168
+
169
+ """
170
+ # Strip out '\n' and leading '*', if any, in continuation lines.
171
+ # This should not effect code previous to this change as
172
+ # continuation lines were not allowed.
173
+ loophead = stripast.sub("", loophead)
174
+ # parse out the names and lists of values
175
+ names = []
176
+ reps = named_re.findall(loophead)
177
+ nsub = None
178
+ for rep in reps:
179
+ name = rep[0]
180
+ vals = parse_values(rep[1])
181
+ size = len(vals)
182
+ if nsub is None :
183
+ nsub = size
184
+ elif nsub != size :
185
+ msg = "Mismatch in number of values, %d != %d\n%s = %s"
186
+ raise ValueError(msg % (nsub, size, name, vals))
187
+ names.append((name, vals))
188
+
189
+
190
+ # Find any exclude variables
191
+ excludes = []
192
+
193
+ for obj in exclude_re.finditer(loophead):
194
+ span = obj.span()
195
+ # find next newline
196
+ endline = loophead.find('\n', span[1])
197
+ substr = loophead[span[1]:endline]
198
+ ex_names = exclude_vars_re.findall(substr)
199
+ excludes.append(dict(ex_names))
200
+
201
+ # generate list of dictionaries, one for each template iteration
202
+ dlist = []
203
+ if nsub is None :
204
+ raise ValueError("No substitution variables found")
205
+ for i in range(nsub):
206
+ tmp = {name: vals[i] for name, vals in names}
207
+ dlist.append(tmp)
208
+ return dlist
209
+
210
+ replace_re = re.compile(r"@(\w+)@")
211
+ def parse_string(astr, env, level, line) :
212
+ lineno = "#line %d\n" % line
213
+
214
+ # local function for string replacement, uses env
215
+ def replace(match):
216
+ name = match.group(1)
217
+ try :
218
+ val = env[name]
219
+ except KeyError:
220
+ msg = 'line %d: no definition of key "%s"'%(line, name)
221
+ raise ValueError(msg) from None
222
+ return val
223
+
224
+ code = [lineno]
225
+ struct = parse_structure(astr, level)
226
+ if struct :
227
+ # recurse over inner loops
228
+ oldend = 0
229
+ newlevel = level + 1
230
+ for sub in struct:
231
+ pref = astr[oldend:sub[0]]
232
+ head = astr[sub[0]:sub[1]]
233
+ text = astr[sub[1]:sub[2]]
234
+ oldend = sub[3]
235
+ newline = line + sub[4]
236
+ code.append(replace_re.sub(replace, pref))
237
+ try :
238
+ envlist = parse_loop_header(head)
239
+ except ValueError as e:
240
+ msg = "line %d: %s" % (newline, e)
241
+ raise ValueError(msg)
242
+ for newenv in envlist :
243
+ newenv.update(env)
244
+ newcode = parse_string(text, newenv, newlevel, newline)
245
+ code.extend(newcode)
246
+ suff = astr[oldend:]
247
+ code.append(replace_re.sub(replace, suff))
248
+ else :
249
+ # replace keys
250
+ code.append(replace_re.sub(replace, astr))
251
+ code.append('\n')
252
+ return ''.join(code)
253
+
254
+ def process_str(astr):
255
+ code = [header]
256
+ code.extend(parse_string(astr, global_names, 0, 1))
257
+ return ''.join(code)
258
+
259
+
260
+ include_src_re = re.compile(r"(\n|\A)#include\s*['\"]"
261
+ r"(?P<name>[\w\d./\\]+[.]src)['\"]", re.I)
262
+
263
+ def resolve_includes(source):
264
+ d = os.path.dirname(source)
265
+ with open(source) as fid:
266
+ lines = []
267
+ for line in fid:
268
+ m = include_src_re.match(line)
269
+ if m:
270
+ fn = m.group('name')
271
+ if not os.path.isabs(fn):
272
+ fn = os.path.join(d, fn)
273
+ if os.path.isfile(fn):
274
+ lines.extend(resolve_includes(fn))
275
+ else:
276
+ lines.append(line)
277
+ else:
278
+ lines.append(line)
279
+ return lines
280
+
281
+ def process_file(source):
282
+ lines = resolve_includes(source)
283
+ sourcefile = os.path.normcase(source).replace("\\", "\\\\")
284
+ try:
285
+ code = process_str(''.join(lines))
286
+ except ValueError as e:
287
+ raise ValueError('In "%s" loop at %s' % (sourcefile, e)) from None
288
+ return '#line 1 "%s"\n%s' % (sourcefile, code)
289
+
290
+
291
+ def unique_key(adict):
292
+ # this obtains a unique key given a dictionary
293
+ # currently it works by appending together n of the letters of the
294
+ # current keys and increasing n until a unique key is found
295
+ # -- not particularly quick
296
+ allkeys = list(adict.keys())
297
+ done = False
298
+ n = 1
299
+ while not done:
300
+ newkey = "".join([x[:n] for x in allkeys])
301
+ if newkey in allkeys:
302
+ n += 1
303
+ else:
304
+ done = True
305
+ return newkey
306
+
307
+
308
+ def main():
309
+ try:
310
+ file = sys.argv[1]
311
+ except IndexError:
312
+ fid = sys.stdin
313
+ outfile = sys.stdout
314
+ else:
315
+ fid = open(file, 'r')
316
+ (base, ext) = os.path.splitext(file)
317
+ newname = base
318
+ outfile = open(newname, 'w')
319
+
320
+ allstr = fid.read()
321
+ try:
322
+ writestr = process_str(allstr)
323
+ except ValueError as e:
324
+ raise ValueError("In %s loop at %s" % (file, e)) from None
325
+
326
+ outfile.write(writestr)
327
+
328
+ if __name__ == "__main__":
329
+ main()
env-llmeval/lib/python3.10/site-packages/numpy/distutils/core.py ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from distutils.core import Distribution
3
+
4
+ if 'setuptools' in sys.modules:
5
+ have_setuptools = True
6
+ from setuptools import setup as old_setup
7
+ # easy_install imports math, it may be picked up from cwd
8
+ from setuptools.command import easy_install
9
+ try:
10
+ # very old versions of setuptools don't have this
11
+ from setuptools.command import bdist_egg
12
+ except ImportError:
13
+ have_setuptools = False
14
+ else:
15
+ from distutils.core import setup as old_setup
16
+ have_setuptools = False
17
+
18
+ import warnings
19
+ import distutils.core
20
+ import distutils.dist
21
+
22
+ from numpy.distutils.extension import Extension # noqa: F401
23
+ from numpy.distutils.numpy_distribution import NumpyDistribution
24
+ from numpy.distutils.command import config, config_compiler, \
25
+ build, build_py, build_ext, build_clib, build_src, build_scripts, \
26
+ sdist, install_data, install_headers, install, bdist_rpm, \
27
+ install_clib
28
+ from numpy.distutils.misc_util import is_sequence, is_string
29
+
30
+ numpy_cmdclass = {'build': build.build,
31
+ 'build_src': build_src.build_src,
32
+ 'build_scripts': build_scripts.build_scripts,
33
+ 'config_cc': config_compiler.config_cc,
34
+ 'config_fc': config_compiler.config_fc,
35
+ 'config': config.config,
36
+ 'build_ext': build_ext.build_ext,
37
+ 'build_py': build_py.build_py,
38
+ 'build_clib': build_clib.build_clib,
39
+ 'sdist': sdist.sdist,
40
+ 'install_data': install_data.install_data,
41
+ 'install_headers': install_headers.install_headers,
42
+ 'install_clib': install_clib.install_clib,
43
+ 'install': install.install,
44
+ 'bdist_rpm': bdist_rpm.bdist_rpm,
45
+ }
46
+ if have_setuptools:
47
+ # Use our own versions of develop and egg_info to ensure that build_src is
48
+ # handled appropriately.
49
+ from numpy.distutils.command import develop, egg_info
50
+ numpy_cmdclass['bdist_egg'] = bdist_egg.bdist_egg
51
+ numpy_cmdclass['develop'] = develop.develop
52
+ numpy_cmdclass['easy_install'] = easy_install.easy_install
53
+ numpy_cmdclass['egg_info'] = egg_info.egg_info
54
+
55
+ def _dict_append(d, **kws):
56
+ for k, v in kws.items():
57
+ if k not in d:
58
+ d[k] = v
59
+ continue
60
+ dv = d[k]
61
+ if isinstance(dv, tuple):
62
+ d[k] = dv + tuple(v)
63
+ elif isinstance(dv, list):
64
+ d[k] = dv + list(v)
65
+ elif isinstance(dv, dict):
66
+ _dict_append(dv, **v)
67
+ elif is_string(dv):
68
+ assert is_string(v)
69
+ d[k] = v
70
+ else:
71
+ raise TypeError(repr(type(dv)))
72
+
73
+ def _command_line_ok(_cache=None):
74
+ """ Return True if command line does not contain any
75
+ help or display requests.
76
+ """
77
+ if _cache:
78
+ return _cache[0]
79
+ elif _cache is None:
80
+ _cache = []
81
+ ok = True
82
+ display_opts = ['--'+n for n in Distribution.display_option_names]
83
+ for o in Distribution.display_options:
84
+ if o[1]:
85
+ display_opts.append('-'+o[1])
86
+ for arg in sys.argv:
87
+ if arg.startswith('--help') or arg=='-h' or arg in display_opts:
88
+ ok = False
89
+ break
90
+ _cache.append(ok)
91
+ return ok
92
+
93
+ def get_distribution(always=False):
94
+ dist = distutils.core._setup_distribution
95
+ # XXX Hack to get numpy installable with easy_install.
96
+ # The problem is easy_install runs it's own setup(), which
97
+ # sets up distutils.core._setup_distribution. However,
98
+ # when our setup() runs, that gets overwritten and lost.
99
+ # We can't use isinstance, as the DistributionWithoutHelpCommands
100
+ # class is local to a function in setuptools.command.easy_install
101
+ if dist is not None and \
102
+ 'DistributionWithoutHelpCommands' in repr(dist):
103
+ dist = None
104
+ if always and dist is None:
105
+ dist = NumpyDistribution()
106
+ return dist
107
+
108
+ def setup(**attr):
109
+
110
+ cmdclass = numpy_cmdclass.copy()
111
+
112
+ new_attr = attr.copy()
113
+ if 'cmdclass' in new_attr:
114
+ cmdclass.update(new_attr['cmdclass'])
115
+ new_attr['cmdclass'] = cmdclass
116
+
117
+ if 'configuration' in new_attr:
118
+ # To avoid calling configuration if there are any errors
119
+ # or help request in command in the line.
120
+ configuration = new_attr.pop('configuration')
121
+
122
+ old_dist = distutils.core._setup_distribution
123
+ old_stop = distutils.core._setup_stop_after
124
+ distutils.core._setup_distribution = None
125
+ distutils.core._setup_stop_after = "commandline"
126
+ try:
127
+ dist = setup(**new_attr)
128
+ finally:
129
+ distutils.core._setup_distribution = old_dist
130
+ distutils.core._setup_stop_after = old_stop
131
+ if dist.help or not _command_line_ok():
132
+ # probably displayed help, skip running any commands
133
+ return dist
134
+
135
+ # create setup dictionary and append to new_attr
136
+ config = configuration()
137
+ if hasattr(config, 'todict'):
138
+ config = config.todict()
139
+ _dict_append(new_attr, **config)
140
+
141
+ # Move extension source libraries to libraries
142
+ libraries = []
143
+ for ext in new_attr.get('ext_modules', []):
144
+ new_libraries = []
145
+ for item in ext.libraries:
146
+ if is_sequence(item):
147
+ lib_name, build_info = item
148
+ _check_append_ext_library(libraries, lib_name, build_info)
149
+ new_libraries.append(lib_name)
150
+ elif is_string(item):
151
+ new_libraries.append(item)
152
+ else:
153
+ raise TypeError("invalid description of extension module "
154
+ "library %r" % (item,))
155
+ ext.libraries = new_libraries
156
+ if libraries:
157
+ if 'libraries' not in new_attr:
158
+ new_attr['libraries'] = []
159
+ for item in libraries:
160
+ _check_append_library(new_attr['libraries'], item)
161
+
162
+ # sources in ext_modules or libraries may contain header files
163
+ if ('ext_modules' in new_attr or 'libraries' in new_attr) \
164
+ and 'headers' not in new_attr:
165
+ new_attr['headers'] = []
166
+
167
+ # Use our custom NumpyDistribution class instead of distutils' one
168
+ new_attr['distclass'] = NumpyDistribution
169
+
170
+ return old_setup(**new_attr)
171
+
172
+ def _check_append_library(libraries, item):
173
+ for libitem in libraries:
174
+ if is_sequence(libitem):
175
+ if is_sequence(item):
176
+ if item[0]==libitem[0]:
177
+ if item[1] is libitem[1]:
178
+ return
179
+ warnings.warn("[0] libraries list contains %r with"
180
+ " different build_info" % (item[0],),
181
+ stacklevel=2)
182
+ break
183
+ else:
184
+ if item==libitem[0]:
185
+ warnings.warn("[1] libraries list contains %r with"
186
+ " no build_info" % (item[0],),
187
+ stacklevel=2)
188
+ break
189
+ else:
190
+ if is_sequence(item):
191
+ if item[0]==libitem:
192
+ warnings.warn("[2] libraries list contains %r with"
193
+ " no build_info" % (item[0],),
194
+ stacklevel=2)
195
+ break
196
+ else:
197
+ if item==libitem:
198
+ return
199
+ libraries.append(item)
200
+
201
+ def _check_append_ext_library(libraries, lib_name, build_info):
202
+ for item in libraries:
203
+ if is_sequence(item):
204
+ if item[0]==lib_name:
205
+ if item[1] is build_info:
206
+ return
207
+ warnings.warn("[3] libraries list contains %r with"
208
+ " different build_info" % (lib_name,),
209
+ stacklevel=2)
210
+ break
211
+ elif item==lib_name:
212
+ warnings.warn("[4] libraries list contains %r with"
213
+ " no build_info" % (lib_name,),
214
+ stacklevel=2)
215
+ break
216
+ libraries.append((lib_name, build_info))