Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- ckpts/universal/global_step60/zero/24.attention.query_key_value.weight/exp_avg_sq.pt +3 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__init__.pyi +4 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/_shell_utils.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/armccompiler.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/ccompiler.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/ccompiler_opt.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/conv_template.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/core.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/cpuinfo.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/exec_command.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/extension.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/from_template.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/fujitsuccompiler.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/intelccompiler.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/lib2def.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/line_endings.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/log.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/mingw32ccompiler.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/misc_util.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/msvc9compiler.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/msvccompiler.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/npy_pkg_config.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/numpy_distribution.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/pathccompiler.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/setup.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/system_info.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/unixccompiler.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/_shell_utils.py +91 -0
- venv/lib/python3.10/site-packages/numpy/distutils/armccompiler.py +26 -0
- venv/lib/python3.10/site-packages/numpy/distutils/ccompiler.py +826 -0
- venv/lib/python3.10/site-packages/numpy/distutils/conv_template.py +329 -0
- venv/lib/python3.10/site-packages/numpy/distutils/core.py +216 -0
- venv/lib/python3.10/site-packages/numpy/distutils/cpuinfo.py +683 -0
- venv/lib/python3.10/site-packages/numpy/distutils/exec_command.py +315 -0
- venv/lib/python3.10/site-packages/numpy/distutils/extension.py +107 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__init__.py +1035 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/arm.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/g95.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/gnu.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/hpux.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/intel.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/nag.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/none.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/sun.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/vast.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/absoft.py +156 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/arm.py +71 -0
- venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/compaq.py +120 -0
ckpts/universal/global_step60/zero/24.attention.query_key_value.weight/exp_avg_sq.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:058433c1552bf34a98bc7be71e3a183b8096120597d838881a18531bc471c6df
|
3 |
+
size 50332843
|
venv/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: ...
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (1.99 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/_shell_utils.cpython-310.pyc
ADDED
Binary file (3.12 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/armccompiler.cpython-310.pyc
ADDED
Binary file (966 Bytes). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/ccompiler.cpython-310.pyc
ADDED
Binary file (20.2 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/ccompiler_opt.cpython-310.pyc
ADDED
Binary file (73.5 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/conv_template.cpython-310.pyc
ADDED
Binary file (8.3 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/core.cpython-310.pyc
ADDED
Binary file (4.79 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/cpuinfo.cpython-310.pyc
ADDED
Binary file (29.6 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/exec_command.cpython-310.pyc
ADDED
Binary file (9.2 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/extension.cpython-310.pyc
ADDED
Binary file (2.65 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/from_template.cpython-310.pyc
ADDED
Binary file (7.26 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/fujitsuccompiler.cpython-310.pyc
ADDED
Binary file (1 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/intelccompiler.cpython-310.pyc
ADDED
Binary file (3.61 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/lib2def.cpython-310.pyc
ADDED
Binary file (3.36 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/line_endings.cpython-310.pyc
ADDED
Binary file (2.09 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/log.cpython-310.pyc
ADDED
Binary file (3.04 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/mingw32ccompiler.cpython-310.pyc
ADDED
Binary file (13.5 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/misc_util.cpython-310.pyc
ADDED
Binary file (73.9 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/msvc9compiler.cpython-310.pyc
ADDED
Binary file (2.22 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/msvccompiler.cpython-310.pyc
ADDED
Binary file (2.47 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/npy_pkg_config.cpython-310.pyc
ADDED
Binary file (12.2 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/numpy_distribution.cpython-310.pyc
ADDED
Binary file (813 Bytes). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/pathccompiler.cpython-310.pyc
ADDED
Binary file (944 Bytes). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/setup.cpython-310.pyc
ADDED
Binary file (769 Bytes). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/system_info.cpython-310.pyc
ADDED
Binary file (90 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/__pycache__/unixccompiler.cpython-310.pyc
ADDED
Binary file (3.43 kB). View file
|
|
venv/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
|
venv/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')
|
venv/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 |
+
|
venv/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()
|
venv/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))
|
venv/lib/python3.10/site-packages/numpy/distutils/cpuinfo.py
ADDED
@@ -0,0 +1,683 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
cpuinfo
|
4 |
+
|
5 |
+
Copyright 2002 Pearu Peterson all rights reserved,
|
6 |
+
Pearu Peterson <[email protected]>
|
7 |
+
Permission to use, modify, and distribute this software is given under the
|
8 |
+
terms of the NumPy (BSD style) license. See LICENSE.txt that came with
|
9 |
+
this distribution for specifics.
|
10 |
+
|
11 |
+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
12 |
+
Pearu Peterson
|
13 |
+
|
14 |
+
"""
|
15 |
+
__all__ = ['cpu']
|
16 |
+
|
17 |
+
import os
|
18 |
+
import platform
|
19 |
+
import re
|
20 |
+
import sys
|
21 |
+
import types
|
22 |
+
import warnings
|
23 |
+
|
24 |
+
from subprocess import getstatusoutput
|
25 |
+
|
26 |
+
|
27 |
+
def getoutput(cmd, successful_status=(0,), stacklevel=1):
|
28 |
+
try:
|
29 |
+
status, output = getstatusoutput(cmd)
|
30 |
+
except OSError as e:
|
31 |
+
warnings.warn(str(e), UserWarning, stacklevel=stacklevel)
|
32 |
+
return False, ""
|
33 |
+
if os.WIFEXITED(status) and os.WEXITSTATUS(status) in successful_status:
|
34 |
+
return True, output
|
35 |
+
return False, output
|
36 |
+
|
37 |
+
def command_info(successful_status=(0,), stacklevel=1, **kw):
|
38 |
+
info = {}
|
39 |
+
for key in kw:
|
40 |
+
ok, output = getoutput(kw[key], successful_status=successful_status,
|
41 |
+
stacklevel=stacklevel+1)
|
42 |
+
if ok:
|
43 |
+
info[key] = output.strip()
|
44 |
+
return info
|
45 |
+
|
46 |
+
def command_by_line(cmd, successful_status=(0,), stacklevel=1):
|
47 |
+
ok, output = getoutput(cmd, successful_status=successful_status,
|
48 |
+
stacklevel=stacklevel+1)
|
49 |
+
if not ok:
|
50 |
+
return
|
51 |
+
for line in output.splitlines():
|
52 |
+
yield line.strip()
|
53 |
+
|
54 |
+
def key_value_from_command(cmd, sep, successful_status=(0,),
|
55 |
+
stacklevel=1):
|
56 |
+
d = {}
|
57 |
+
for line in command_by_line(cmd, successful_status=successful_status,
|
58 |
+
stacklevel=stacklevel+1):
|
59 |
+
l = [s.strip() for s in line.split(sep, 1)]
|
60 |
+
if len(l) == 2:
|
61 |
+
d[l[0]] = l[1]
|
62 |
+
return d
|
63 |
+
|
64 |
+
class CPUInfoBase:
|
65 |
+
"""Holds CPU information and provides methods for requiring
|
66 |
+
the availability of various CPU features.
|
67 |
+
"""
|
68 |
+
|
69 |
+
def _try_call(self, func):
|
70 |
+
try:
|
71 |
+
return func()
|
72 |
+
except Exception:
|
73 |
+
pass
|
74 |
+
|
75 |
+
def __getattr__(self, name):
|
76 |
+
if not name.startswith('_'):
|
77 |
+
if hasattr(self, '_'+name):
|
78 |
+
attr = getattr(self, '_'+name)
|
79 |
+
if isinstance(attr, types.MethodType):
|
80 |
+
return lambda func=self._try_call,attr=attr : func(attr)
|
81 |
+
else:
|
82 |
+
return lambda : None
|
83 |
+
raise AttributeError(name)
|
84 |
+
|
85 |
+
def _getNCPUs(self):
|
86 |
+
return 1
|
87 |
+
|
88 |
+
def __get_nbits(self):
|
89 |
+
abits = platform.architecture()[0]
|
90 |
+
nbits = re.compile(r'(\d+)bit').search(abits).group(1)
|
91 |
+
return nbits
|
92 |
+
|
93 |
+
def _is_32bit(self):
|
94 |
+
return self.__get_nbits() == '32'
|
95 |
+
|
96 |
+
def _is_64bit(self):
|
97 |
+
return self.__get_nbits() == '64'
|
98 |
+
|
99 |
+
class LinuxCPUInfo(CPUInfoBase):
|
100 |
+
|
101 |
+
info = None
|
102 |
+
|
103 |
+
def __init__(self):
|
104 |
+
if self.info is not None:
|
105 |
+
return
|
106 |
+
info = [ {} ]
|
107 |
+
ok, output = getoutput('uname -m')
|
108 |
+
if ok:
|
109 |
+
info[0]['uname_m'] = output.strip()
|
110 |
+
try:
|
111 |
+
fo = open('/proc/cpuinfo')
|
112 |
+
except OSError as e:
|
113 |
+
warnings.warn(str(e), UserWarning, stacklevel=2)
|
114 |
+
else:
|
115 |
+
for line in fo:
|
116 |
+
name_value = [s.strip() for s in line.split(':', 1)]
|
117 |
+
if len(name_value) != 2:
|
118 |
+
continue
|
119 |
+
name, value = name_value
|
120 |
+
if not info or name in info[-1]: # next processor
|
121 |
+
info.append({})
|
122 |
+
info[-1][name] = value
|
123 |
+
fo.close()
|
124 |
+
self.__class__.info = info
|
125 |
+
|
126 |
+
def _not_impl(self): pass
|
127 |
+
|
128 |
+
# Athlon
|
129 |
+
|
130 |
+
def _is_AMD(self):
|
131 |
+
return self.info[0]['vendor_id']=='AuthenticAMD'
|
132 |
+
|
133 |
+
def _is_AthlonK6_2(self):
|
134 |
+
return self._is_AMD() and self.info[0]['model'] == '2'
|
135 |
+
|
136 |
+
def _is_AthlonK6_3(self):
|
137 |
+
return self._is_AMD() and self.info[0]['model'] == '3'
|
138 |
+
|
139 |
+
def _is_AthlonK6(self):
|
140 |
+
return re.match(r'.*?AMD-K6', self.info[0]['model name']) is not None
|
141 |
+
|
142 |
+
def _is_AthlonK7(self):
|
143 |
+
return re.match(r'.*?AMD-K7', self.info[0]['model name']) is not None
|
144 |
+
|
145 |
+
def _is_AthlonMP(self):
|
146 |
+
return re.match(r'.*?Athlon\(tm\) MP\b',
|
147 |
+
self.info[0]['model name']) is not None
|
148 |
+
|
149 |
+
def _is_AMD64(self):
|
150 |
+
return self.is_AMD() and self.info[0]['family'] == '15'
|
151 |
+
|
152 |
+
def _is_Athlon64(self):
|
153 |
+
return re.match(r'.*?Athlon\(tm\) 64\b',
|
154 |
+
self.info[0]['model name']) is not None
|
155 |
+
|
156 |
+
def _is_AthlonHX(self):
|
157 |
+
return re.match(r'.*?Athlon HX\b',
|
158 |
+
self.info[0]['model name']) is not None
|
159 |
+
|
160 |
+
def _is_Opteron(self):
|
161 |
+
return re.match(r'.*?Opteron\b',
|
162 |
+
self.info[0]['model name']) is not None
|
163 |
+
|
164 |
+
def _is_Hammer(self):
|
165 |
+
return re.match(r'.*?Hammer\b',
|
166 |
+
self.info[0]['model name']) is not None
|
167 |
+
|
168 |
+
# Alpha
|
169 |
+
|
170 |
+
def _is_Alpha(self):
|
171 |
+
return self.info[0]['cpu']=='Alpha'
|
172 |
+
|
173 |
+
def _is_EV4(self):
|
174 |
+
return self.is_Alpha() and self.info[0]['cpu model'] == 'EV4'
|
175 |
+
|
176 |
+
def _is_EV5(self):
|
177 |
+
return self.is_Alpha() and self.info[0]['cpu model'] == 'EV5'
|
178 |
+
|
179 |
+
def _is_EV56(self):
|
180 |
+
return self.is_Alpha() and self.info[0]['cpu model'] == 'EV56'
|
181 |
+
|
182 |
+
def _is_PCA56(self):
|
183 |
+
return self.is_Alpha() and self.info[0]['cpu model'] == 'PCA56'
|
184 |
+
|
185 |
+
# Intel
|
186 |
+
|
187 |
+
#XXX
|
188 |
+
_is_i386 = _not_impl
|
189 |
+
|
190 |
+
def _is_Intel(self):
|
191 |
+
return self.info[0]['vendor_id']=='GenuineIntel'
|
192 |
+
|
193 |
+
def _is_i486(self):
|
194 |
+
return self.info[0]['cpu']=='i486'
|
195 |
+
|
196 |
+
def _is_i586(self):
|
197 |
+
return self.is_Intel() and self.info[0]['cpu family'] == '5'
|
198 |
+
|
199 |
+
def _is_i686(self):
|
200 |
+
return self.is_Intel() and self.info[0]['cpu family'] == '6'
|
201 |
+
|
202 |
+
def _is_Celeron(self):
|
203 |
+
return re.match(r'.*?Celeron',
|
204 |
+
self.info[0]['model name']) is not None
|
205 |
+
|
206 |
+
def _is_Pentium(self):
|
207 |
+
return re.match(r'.*?Pentium',
|
208 |
+
self.info[0]['model name']) is not None
|
209 |
+
|
210 |
+
def _is_PentiumII(self):
|
211 |
+
return re.match(r'.*?Pentium.*?II\b',
|
212 |
+
self.info[0]['model name']) is not None
|
213 |
+
|
214 |
+
def _is_PentiumPro(self):
|
215 |
+
return re.match(r'.*?PentiumPro\b',
|
216 |
+
self.info[0]['model name']) is not None
|
217 |
+
|
218 |
+
def _is_PentiumMMX(self):
|
219 |
+
return re.match(r'.*?Pentium.*?MMX\b',
|
220 |
+
self.info[0]['model name']) is not None
|
221 |
+
|
222 |
+
def _is_PentiumIII(self):
|
223 |
+
return re.match(r'.*?Pentium.*?III\b',
|
224 |
+
self.info[0]['model name']) is not None
|
225 |
+
|
226 |
+
def _is_PentiumIV(self):
|
227 |
+
return re.match(r'.*?Pentium.*?(IV|4)\b',
|
228 |
+
self.info[0]['model name']) is not None
|
229 |
+
|
230 |
+
def _is_PentiumM(self):
|
231 |
+
return re.match(r'.*?Pentium.*?M\b',
|
232 |
+
self.info[0]['model name']) is not None
|
233 |
+
|
234 |
+
def _is_Prescott(self):
|
235 |
+
return self.is_PentiumIV() and self.has_sse3()
|
236 |
+
|
237 |
+
def _is_Nocona(self):
|
238 |
+
return (self.is_Intel()
|
239 |
+
and (self.info[0]['cpu family'] == '6'
|
240 |
+
or self.info[0]['cpu family'] == '15')
|
241 |
+
and (self.has_sse3() and not self.has_ssse3())
|
242 |
+
and re.match(r'.*?\blm\b', self.info[0]['flags']) is not None)
|
243 |
+
|
244 |
+
def _is_Core2(self):
|
245 |
+
return (self.is_64bit() and self.is_Intel() and
|
246 |
+
re.match(r'.*?Core\(TM\)2\b',
|
247 |
+
self.info[0]['model name']) is not None)
|
248 |
+
|
249 |
+
def _is_Itanium(self):
|
250 |
+
return re.match(r'.*?Itanium\b',
|
251 |
+
self.info[0]['family']) is not None
|
252 |
+
|
253 |
+
def _is_XEON(self):
|
254 |
+
return re.match(r'.*?XEON\b',
|
255 |
+
self.info[0]['model name'], re.IGNORECASE) is not None
|
256 |
+
|
257 |
+
_is_Xeon = _is_XEON
|
258 |
+
|
259 |
+
# Varia
|
260 |
+
|
261 |
+
def _is_singleCPU(self):
|
262 |
+
return len(self.info) == 1
|
263 |
+
|
264 |
+
def _getNCPUs(self):
|
265 |
+
return len(self.info)
|
266 |
+
|
267 |
+
def _has_fdiv_bug(self):
|
268 |
+
return self.info[0]['fdiv_bug']=='yes'
|
269 |
+
|
270 |
+
def _has_f00f_bug(self):
|
271 |
+
return self.info[0]['f00f_bug']=='yes'
|
272 |
+
|
273 |
+
def _has_mmx(self):
|
274 |
+
return re.match(r'.*?\bmmx\b', self.info[0]['flags']) is not None
|
275 |
+
|
276 |
+
def _has_sse(self):
|
277 |
+
return re.match(r'.*?\bsse\b', self.info[0]['flags']) is not None
|
278 |
+
|
279 |
+
def _has_sse2(self):
|
280 |
+
return re.match(r'.*?\bsse2\b', self.info[0]['flags']) is not None
|
281 |
+
|
282 |
+
def _has_sse3(self):
|
283 |
+
return re.match(r'.*?\bpni\b', self.info[0]['flags']) is not None
|
284 |
+
|
285 |
+
def _has_ssse3(self):
|
286 |
+
return re.match(r'.*?\bssse3\b', self.info[0]['flags']) is not None
|
287 |
+
|
288 |
+
def _has_3dnow(self):
|
289 |
+
return re.match(r'.*?\b3dnow\b', self.info[0]['flags']) is not None
|
290 |
+
|
291 |
+
def _has_3dnowext(self):
|
292 |
+
return re.match(r'.*?\b3dnowext\b', self.info[0]['flags']) is not None
|
293 |
+
|
294 |
+
class IRIXCPUInfo(CPUInfoBase):
|
295 |
+
info = None
|
296 |
+
|
297 |
+
def __init__(self):
|
298 |
+
if self.info is not None:
|
299 |
+
return
|
300 |
+
info = key_value_from_command('sysconf', sep=' ',
|
301 |
+
successful_status=(0, 1))
|
302 |
+
self.__class__.info = info
|
303 |
+
|
304 |
+
def _not_impl(self): pass
|
305 |
+
|
306 |
+
def _is_singleCPU(self):
|
307 |
+
return self.info.get('NUM_PROCESSORS') == '1'
|
308 |
+
|
309 |
+
def _getNCPUs(self):
|
310 |
+
return int(self.info.get('NUM_PROCESSORS', 1))
|
311 |
+
|
312 |
+
def __cputype(self, n):
|
313 |
+
return self.info.get('PROCESSORS').split()[0].lower() == 'r%s' % (n)
|
314 |
+
def _is_r2000(self): return self.__cputype(2000)
|
315 |
+
def _is_r3000(self): return self.__cputype(3000)
|
316 |
+
def _is_r3900(self): return self.__cputype(3900)
|
317 |
+
def _is_r4000(self): return self.__cputype(4000)
|
318 |
+
def _is_r4100(self): return self.__cputype(4100)
|
319 |
+
def _is_r4300(self): return self.__cputype(4300)
|
320 |
+
def _is_r4400(self): return self.__cputype(4400)
|
321 |
+
def _is_r4600(self): return self.__cputype(4600)
|
322 |
+
def _is_r4650(self): return self.__cputype(4650)
|
323 |
+
def _is_r5000(self): return self.__cputype(5000)
|
324 |
+
def _is_r6000(self): return self.__cputype(6000)
|
325 |
+
def _is_r8000(self): return self.__cputype(8000)
|
326 |
+
def _is_r10000(self): return self.__cputype(10000)
|
327 |
+
def _is_r12000(self): return self.__cputype(12000)
|
328 |
+
def _is_rorion(self): return self.__cputype('orion')
|
329 |
+
|
330 |
+
def get_ip(self):
|
331 |
+
try: return self.info.get('MACHINE')
|
332 |
+
except Exception: pass
|
333 |
+
def __machine(self, n):
|
334 |
+
return self.info.get('MACHINE').lower() == 'ip%s' % (n)
|
335 |
+
def _is_IP19(self): return self.__machine(19)
|
336 |
+
def _is_IP20(self): return self.__machine(20)
|
337 |
+
def _is_IP21(self): return self.__machine(21)
|
338 |
+
def _is_IP22(self): return self.__machine(22)
|
339 |
+
def _is_IP22_4k(self): return self.__machine(22) and self._is_r4000()
|
340 |
+
def _is_IP22_5k(self): return self.__machine(22) and self._is_r5000()
|
341 |
+
def _is_IP24(self): return self.__machine(24)
|
342 |
+
def _is_IP25(self): return self.__machine(25)
|
343 |
+
def _is_IP26(self): return self.__machine(26)
|
344 |
+
def _is_IP27(self): return self.__machine(27)
|
345 |
+
def _is_IP28(self): return self.__machine(28)
|
346 |
+
def _is_IP30(self): return self.__machine(30)
|
347 |
+
def _is_IP32(self): return self.__machine(32)
|
348 |
+
def _is_IP32_5k(self): return self.__machine(32) and self._is_r5000()
|
349 |
+
def _is_IP32_10k(self): return self.__machine(32) and self._is_r10000()
|
350 |
+
|
351 |
+
|
352 |
+
class DarwinCPUInfo(CPUInfoBase):
|
353 |
+
info = None
|
354 |
+
|
355 |
+
def __init__(self):
|
356 |
+
if self.info is not None:
|
357 |
+
return
|
358 |
+
info = command_info(arch='arch',
|
359 |
+
machine='machine')
|
360 |
+
info['sysctl_hw'] = key_value_from_command('sysctl hw', sep='=')
|
361 |
+
self.__class__.info = info
|
362 |
+
|
363 |
+
def _not_impl(self): pass
|
364 |
+
|
365 |
+
def _getNCPUs(self):
|
366 |
+
return int(self.info['sysctl_hw'].get('hw.ncpu', 1))
|
367 |
+
|
368 |
+
def _is_Power_Macintosh(self):
|
369 |
+
return self.info['sysctl_hw']['hw.machine']=='Power Macintosh'
|
370 |
+
|
371 |
+
def _is_i386(self):
|
372 |
+
return self.info['arch']=='i386'
|
373 |
+
def _is_ppc(self):
|
374 |
+
return self.info['arch']=='ppc'
|
375 |
+
|
376 |
+
def __machine(self, n):
|
377 |
+
return self.info['machine'] == 'ppc%s'%n
|
378 |
+
def _is_ppc601(self): return self.__machine(601)
|
379 |
+
def _is_ppc602(self): return self.__machine(602)
|
380 |
+
def _is_ppc603(self): return self.__machine(603)
|
381 |
+
def _is_ppc603e(self): return self.__machine('603e')
|
382 |
+
def _is_ppc604(self): return self.__machine(604)
|
383 |
+
def _is_ppc604e(self): return self.__machine('604e')
|
384 |
+
def _is_ppc620(self): return self.__machine(620)
|
385 |
+
def _is_ppc630(self): return self.__machine(630)
|
386 |
+
def _is_ppc740(self): return self.__machine(740)
|
387 |
+
def _is_ppc7400(self): return self.__machine(7400)
|
388 |
+
def _is_ppc7450(self): return self.__machine(7450)
|
389 |
+
def _is_ppc750(self): return self.__machine(750)
|
390 |
+
def _is_ppc403(self): return self.__machine(403)
|
391 |
+
def _is_ppc505(self): return self.__machine(505)
|
392 |
+
def _is_ppc801(self): return self.__machine(801)
|
393 |
+
def _is_ppc821(self): return self.__machine(821)
|
394 |
+
def _is_ppc823(self): return self.__machine(823)
|
395 |
+
def _is_ppc860(self): return self.__machine(860)
|
396 |
+
|
397 |
+
|
398 |
+
class SunOSCPUInfo(CPUInfoBase):
|
399 |
+
|
400 |
+
info = None
|
401 |
+
|
402 |
+
def __init__(self):
|
403 |
+
if self.info is not None:
|
404 |
+
return
|
405 |
+
info = command_info(arch='arch',
|
406 |
+
mach='mach',
|
407 |
+
uname_i='uname_i',
|
408 |
+
isainfo_b='isainfo -b',
|
409 |
+
isainfo_n='isainfo -n',
|
410 |
+
)
|
411 |
+
info['uname_X'] = key_value_from_command('uname -X', sep='=')
|
412 |
+
for line in command_by_line('psrinfo -v 0'):
|
413 |
+
m = re.match(r'\s*The (?P<p>[\w\d]+) processor operates at', line)
|
414 |
+
if m:
|
415 |
+
info['processor'] = m.group('p')
|
416 |
+
break
|
417 |
+
self.__class__.info = info
|
418 |
+
|
419 |
+
def _not_impl(self): pass
|
420 |
+
|
421 |
+
def _is_i386(self):
|
422 |
+
return self.info['isainfo_n']=='i386'
|
423 |
+
def _is_sparc(self):
|
424 |
+
return self.info['isainfo_n']=='sparc'
|
425 |
+
def _is_sparcv9(self):
|
426 |
+
return self.info['isainfo_n']=='sparcv9'
|
427 |
+
|
428 |
+
def _getNCPUs(self):
|
429 |
+
return int(self.info['uname_X'].get('NumCPU', 1))
|
430 |
+
|
431 |
+
def _is_sun4(self):
|
432 |
+
return self.info['arch']=='sun4'
|
433 |
+
|
434 |
+
def _is_SUNW(self):
|
435 |
+
return re.match(r'SUNW', self.info['uname_i']) is not None
|
436 |
+
def _is_sparcstation5(self):
|
437 |
+
return re.match(r'.*SPARCstation-5', self.info['uname_i']) is not None
|
438 |
+
def _is_ultra1(self):
|
439 |
+
return re.match(r'.*Ultra-1', self.info['uname_i']) is not None
|
440 |
+
def _is_ultra250(self):
|
441 |
+
return re.match(r'.*Ultra-250', self.info['uname_i']) is not None
|
442 |
+
def _is_ultra2(self):
|
443 |
+
return re.match(r'.*Ultra-2', self.info['uname_i']) is not None
|
444 |
+
def _is_ultra30(self):
|
445 |
+
return re.match(r'.*Ultra-30', self.info['uname_i']) is not None
|
446 |
+
def _is_ultra4(self):
|
447 |
+
return re.match(r'.*Ultra-4', self.info['uname_i']) is not None
|
448 |
+
def _is_ultra5_10(self):
|
449 |
+
return re.match(r'.*Ultra-5_10', self.info['uname_i']) is not None
|
450 |
+
def _is_ultra5(self):
|
451 |
+
return re.match(r'.*Ultra-5', self.info['uname_i']) is not None
|
452 |
+
def _is_ultra60(self):
|
453 |
+
return re.match(r'.*Ultra-60', self.info['uname_i']) is not None
|
454 |
+
def _is_ultra80(self):
|
455 |
+
return re.match(r'.*Ultra-80', self.info['uname_i']) is not None
|
456 |
+
def _is_ultraenterprice(self):
|
457 |
+
return re.match(r'.*Ultra-Enterprise', self.info['uname_i']) is not None
|
458 |
+
def _is_ultraenterprice10k(self):
|
459 |
+
return re.match(r'.*Ultra-Enterprise-10000', self.info['uname_i']) is not None
|
460 |
+
def _is_sunfire(self):
|
461 |
+
return re.match(r'.*Sun-Fire', self.info['uname_i']) is not None
|
462 |
+
def _is_ultra(self):
|
463 |
+
return re.match(r'.*Ultra', self.info['uname_i']) is not None
|
464 |
+
|
465 |
+
def _is_cpusparcv7(self):
|
466 |
+
return self.info['processor']=='sparcv7'
|
467 |
+
def _is_cpusparcv8(self):
|
468 |
+
return self.info['processor']=='sparcv8'
|
469 |
+
def _is_cpusparcv9(self):
|
470 |
+
return self.info['processor']=='sparcv9'
|
471 |
+
|
472 |
+
class Win32CPUInfo(CPUInfoBase):
|
473 |
+
|
474 |
+
info = None
|
475 |
+
pkey = r"HARDWARE\DESCRIPTION\System\CentralProcessor"
|
476 |
+
# XXX: what does the value of
|
477 |
+
# HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0
|
478 |
+
# mean?
|
479 |
+
|
480 |
+
def __init__(self):
|
481 |
+
if self.info is not None:
|
482 |
+
return
|
483 |
+
info = []
|
484 |
+
try:
|
485 |
+
#XXX: Bad style to use so long `try:...except:...`. Fix it!
|
486 |
+
import winreg
|
487 |
+
|
488 |
+
prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)"
|
489 |
+
r"\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE)
|
490 |
+
chnd=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, self.pkey)
|
491 |
+
pnum=0
|
492 |
+
while True:
|
493 |
+
try:
|
494 |
+
proc=winreg.EnumKey(chnd, pnum)
|
495 |
+
except winreg.error:
|
496 |
+
break
|
497 |
+
else:
|
498 |
+
pnum+=1
|
499 |
+
info.append({"Processor":proc})
|
500 |
+
phnd=winreg.OpenKey(chnd, proc)
|
501 |
+
pidx=0
|
502 |
+
while True:
|
503 |
+
try:
|
504 |
+
name, value, vtpe=winreg.EnumValue(phnd, pidx)
|
505 |
+
except winreg.error:
|
506 |
+
break
|
507 |
+
else:
|
508 |
+
pidx=pidx+1
|
509 |
+
info[-1][name]=value
|
510 |
+
if name=="Identifier":
|
511 |
+
srch=prgx.search(value)
|
512 |
+
if srch:
|
513 |
+
info[-1]["Family"]=int(srch.group("FML"))
|
514 |
+
info[-1]["Model"]=int(srch.group("MDL"))
|
515 |
+
info[-1]["Stepping"]=int(srch.group("STP"))
|
516 |
+
except Exception as e:
|
517 |
+
print(e, '(ignoring)')
|
518 |
+
self.__class__.info = info
|
519 |
+
|
520 |
+
def _not_impl(self): pass
|
521 |
+
|
522 |
+
# Athlon
|
523 |
+
|
524 |
+
def _is_AMD(self):
|
525 |
+
return self.info[0]['VendorIdentifier']=='AuthenticAMD'
|
526 |
+
|
527 |
+
def _is_Am486(self):
|
528 |
+
return self.is_AMD() and self.info[0]['Family']==4
|
529 |
+
|
530 |
+
def _is_Am5x86(self):
|
531 |
+
return self.is_AMD() and self.info[0]['Family']==4
|
532 |
+
|
533 |
+
def _is_AMDK5(self):
|
534 |
+
return self.is_AMD() and self.info[0]['Family']==5 \
|
535 |
+
and self.info[0]['Model'] in [0, 1, 2, 3]
|
536 |
+
|
537 |
+
def _is_AMDK6(self):
|
538 |
+
return self.is_AMD() and self.info[0]['Family']==5 \
|
539 |
+
and self.info[0]['Model'] in [6, 7]
|
540 |
+
|
541 |
+
def _is_AMDK6_2(self):
|
542 |
+
return self.is_AMD() and self.info[0]['Family']==5 \
|
543 |
+
and self.info[0]['Model']==8
|
544 |
+
|
545 |
+
def _is_AMDK6_3(self):
|
546 |
+
return self.is_AMD() and self.info[0]['Family']==5 \
|
547 |
+
and self.info[0]['Model']==9
|
548 |
+
|
549 |
+
def _is_AMDK7(self):
|
550 |
+
return self.is_AMD() and self.info[0]['Family'] == 6
|
551 |
+
|
552 |
+
# To reliably distinguish between the different types of AMD64 chips
|
553 |
+
# (Athlon64, Operton, Athlon64 X2, Semperon, Turion 64, etc.) would
|
554 |
+
# require looking at the 'brand' from cpuid
|
555 |
+
|
556 |
+
def _is_AMD64(self):
|
557 |
+
return self.is_AMD() and self.info[0]['Family'] == 15
|
558 |
+
|
559 |
+
# Intel
|
560 |
+
|
561 |
+
def _is_Intel(self):
|
562 |
+
return self.info[0]['VendorIdentifier']=='GenuineIntel'
|
563 |
+
|
564 |
+
def _is_i386(self):
|
565 |
+
return self.info[0]['Family']==3
|
566 |
+
|
567 |
+
def _is_i486(self):
|
568 |
+
return self.info[0]['Family']==4
|
569 |
+
|
570 |
+
def _is_i586(self):
|
571 |
+
return self.is_Intel() and self.info[0]['Family']==5
|
572 |
+
|
573 |
+
def _is_i686(self):
|
574 |
+
return self.is_Intel() and self.info[0]['Family']==6
|
575 |
+
|
576 |
+
def _is_Pentium(self):
|
577 |
+
return self.is_Intel() and self.info[0]['Family']==5
|
578 |
+
|
579 |
+
def _is_PentiumMMX(self):
|
580 |
+
return self.is_Intel() and self.info[0]['Family']==5 \
|
581 |
+
and self.info[0]['Model']==4
|
582 |
+
|
583 |
+
def _is_PentiumPro(self):
|
584 |
+
return self.is_Intel() and self.info[0]['Family']==6 \
|
585 |
+
and self.info[0]['Model']==1
|
586 |
+
|
587 |
+
def _is_PentiumII(self):
|
588 |
+
return self.is_Intel() and self.info[0]['Family']==6 \
|
589 |
+
and self.info[0]['Model'] in [3, 5, 6]
|
590 |
+
|
591 |
+
def _is_PentiumIII(self):
|
592 |
+
return self.is_Intel() and self.info[0]['Family']==6 \
|
593 |
+
and self.info[0]['Model'] in [7, 8, 9, 10, 11]
|
594 |
+
|
595 |
+
def _is_PentiumIV(self):
|
596 |
+
return self.is_Intel() and self.info[0]['Family']==15
|
597 |
+
|
598 |
+
def _is_PentiumM(self):
|
599 |
+
return self.is_Intel() and self.info[0]['Family'] == 6 \
|
600 |
+
and self.info[0]['Model'] in [9, 13, 14]
|
601 |
+
|
602 |
+
def _is_Core2(self):
|
603 |
+
return self.is_Intel() and self.info[0]['Family'] == 6 \
|
604 |
+
and self.info[0]['Model'] in [15, 16, 17]
|
605 |
+
|
606 |
+
# Varia
|
607 |
+
|
608 |
+
def _is_singleCPU(self):
|
609 |
+
return len(self.info) == 1
|
610 |
+
|
611 |
+
def _getNCPUs(self):
|
612 |
+
return len(self.info)
|
613 |
+
|
614 |
+
def _has_mmx(self):
|
615 |
+
if self.is_Intel():
|
616 |
+
return (self.info[0]['Family']==5 and self.info[0]['Model']==4) \
|
617 |
+
or (self.info[0]['Family'] in [6, 15])
|
618 |
+
elif self.is_AMD():
|
619 |
+
return self.info[0]['Family'] in [5, 6, 15]
|
620 |
+
else:
|
621 |
+
return False
|
622 |
+
|
623 |
+
def _has_sse(self):
|
624 |
+
if self.is_Intel():
|
625 |
+
return ((self.info[0]['Family']==6 and
|
626 |
+
self.info[0]['Model'] in [7, 8, 9, 10, 11])
|
627 |
+
or self.info[0]['Family']==15)
|
628 |
+
elif self.is_AMD():
|
629 |
+
return ((self.info[0]['Family']==6 and
|
630 |
+
self.info[0]['Model'] in [6, 7, 8, 10])
|
631 |
+
or self.info[0]['Family']==15)
|
632 |
+
else:
|
633 |
+
return False
|
634 |
+
|
635 |
+
def _has_sse2(self):
|
636 |
+
if self.is_Intel():
|
637 |
+
return self.is_Pentium4() or self.is_PentiumM() \
|
638 |
+
or self.is_Core2()
|
639 |
+
elif self.is_AMD():
|
640 |
+
return self.is_AMD64()
|
641 |
+
else:
|
642 |
+
return False
|
643 |
+
|
644 |
+
def _has_3dnow(self):
|
645 |
+
return self.is_AMD() and self.info[0]['Family'] in [5, 6, 15]
|
646 |
+
|
647 |
+
def _has_3dnowext(self):
|
648 |
+
return self.is_AMD() and self.info[0]['Family'] in [6, 15]
|
649 |
+
|
650 |
+
if sys.platform.startswith('linux'): # variations: linux2,linux-i386 (any others?)
|
651 |
+
cpuinfo = LinuxCPUInfo
|
652 |
+
elif sys.platform.startswith('irix'):
|
653 |
+
cpuinfo = IRIXCPUInfo
|
654 |
+
elif sys.platform == 'darwin':
|
655 |
+
cpuinfo = DarwinCPUInfo
|
656 |
+
elif sys.platform.startswith('sunos'):
|
657 |
+
cpuinfo = SunOSCPUInfo
|
658 |
+
elif sys.platform.startswith('win32'):
|
659 |
+
cpuinfo = Win32CPUInfo
|
660 |
+
elif sys.platform.startswith('cygwin'):
|
661 |
+
cpuinfo = LinuxCPUInfo
|
662 |
+
#XXX: other OS's. Eg. use _winreg on Win32. Or os.uname on unices.
|
663 |
+
else:
|
664 |
+
cpuinfo = CPUInfoBase
|
665 |
+
|
666 |
+
cpu = cpuinfo()
|
667 |
+
|
668 |
+
#if __name__ == "__main__":
|
669 |
+
#
|
670 |
+
# cpu.is_blaa()
|
671 |
+
# cpu.is_Intel()
|
672 |
+
# cpu.is_Alpha()
|
673 |
+
#
|
674 |
+
# print('CPU information:'),
|
675 |
+
# for name in dir(cpuinfo):
|
676 |
+
# if name[0]=='_' and name[1]!='_':
|
677 |
+
# r = getattr(cpu,name[1:])()
|
678 |
+
# if r:
|
679 |
+
# if r!=1:
|
680 |
+
# print('%s=%s' %(name[1:],r))
|
681 |
+
# else:
|
682 |
+
# print(name[1:]),
|
683 |
+
# print()
|
venv/lib/python3.10/site-packages/numpy/distutils/exec_command.py
ADDED
@@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
exec_command
|
3 |
+
|
4 |
+
Implements exec_command function that is (almost) equivalent to
|
5 |
+
commands.getstatusoutput function but on NT, DOS systems the
|
6 |
+
returned status is actually correct (though, the returned status
|
7 |
+
values may be different by a factor). In addition, exec_command
|
8 |
+
takes keyword arguments for (re-)defining environment variables.
|
9 |
+
|
10 |
+
Provides functions:
|
11 |
+
|
12 |
+
exec_command --- execute command in a specified directory and
|
13 |
+
in the modified environment.
|
14 |
+
find_executable --- locate a command using info from environment
|
15 |
+
variable PATH. Equivalent to posix `which`
|
16 |
+
command.
|
17 |
+
|
18 |
+
Author: Pearu Peterson <[email protected]>
|
19 |
+
Created: 11 January 2003
|
20 |
+
|
21 |
+
Requires: Python 2.x
|
22 |
+
|
23 |
+
Successfully tested on:
|
24 |
+
|
25 |
+
======== ============ =================================================
|
26 |
+
os.name sys.platform comments
|
27 |
+
======== ============ =================================================
|
28 |
+
posix linux2 Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3
|
29 |
+
PyCrust 0.9.3, Idle 1.0.2
|
30 |
+
posix linux2 Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2
|
31 |
+
posix sunos5 SunOS 5.9, Python 2.2, 2.3.2
|
32 |
+
posix darwin Darwin 7.2.0, Python 2.3
|
33 |
+
nt win32 Windows Me
|
34 |
+
Python 2.3(EE), Idle 1.0, PyCrust 0.7.2
|
35 |
+
Python 2.1.1 Idle 0.8
|
36 |
+
nt win32 Windows 98, Python 2.1.1. Idle 0.8
|
37 |
+
nt win32 Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests
|
38 |
+
fail i.e. redefining environment variables may
|
39 |
+
not work. FIXED: don't use cygwin echo!
|
40 |
+
Comment: also `cmd /c echo` will not work
|
41 |
+
but redefining environment variables do work.
|
42 |
+
posix cygwin Cygwin 98-4.10, Python 2.3.3(cygming special)
|
43 |
+
nt win32 Windows XP, Python 2.3.3
|
44 |
+
======== ============ =================================================
|
45 |
+
|
46 |
+
Known bugs:
|
47 |
+
|
48 |
+
* Tests, that send messages to stderr, fail when executed from MSYS prompt
|
49 |
+
because the messages are lost at some point.
|
50 |
+
|
51 |
+
"""
|
52 |
+
__all__ = ['exec_command', 'find_executable']
|
53 |
+
|
54 |
+
import os
|
55 |
+
import sys
|
56 |
+
import subprocess
|
57 |
+
import locale
|
58 |
+
import warnings
|
59 |
+
|
60 |
+
from numpy.distutils.misc_util import is_sequence, make_temp_file
|
61 |
+
from numpy.distutils import log
|
62 |
+
|
63 |
+
def filepath_from_subprocess_output(output):
|
64 |
+
"""
|
65 |
+
Convert `bytes` in the encoding used by a subprocess into a filesystem-appropriate `str`.
|
66 |
+
|
67 |
+
Inherited from `exec_command`, and possibly incorrect.
|
68 |
+
"""
|
69 |
+
mylocale = locale.getpreferredencoding(False)
|
70 |
+
if mylocale is None:
|
71 |
+
mylocale = 'ascii'
|
72 |
+
output = output.decode(mylocale, errors='replace')
|
73 |
+
output = output.replace('\r\n', '\n')
|
74 |
+
# Another historical oddity
|
75 |
+
if output[-1:] == '\n':
|
76 |
+
output = output[:-1]
|
77 |
+
return output
|
78 |
+
|
79 |
+
|
80 |
+
def forward_bytes_to_stdout(val):
|
81 |
+
"""
|
82 |
+
Forward bytes from a subprocess call to the console, without attempting to
|
83 |
+
decode them.
|
84 |
+
|
85 |
+
The assumption is that the subprocess call already returned bytes in
|
86 |
+
a suitable encoding.
|
87 |
+
"""
|
88 |
+
if hasattr(sys.stdout, 'buffer'):
|
89 |
+
# use the underlying binary output if there is one
|
90 |
+
sys.stdout.buffer.write(val)
|
91 |
+
elif hasattr(sys.stdout, 'encoding'):
|
92 |
+
# round-trip the encoding if necessary
|
93 |
+
sys.stdout.write(val.decode(sys.stdout.encoding))
|
94 |
+
else:
|
95 |
+
# make a best-guess at the encoding
|
96 |
+
sys.stdout.write(val.decode('utf8', errors='replace'))
|
97 |
+
|
98 |
+
|
99 |
+
def temp_file_name():
|
100 |
+
# 2019-01-30, 1.17
|
101 |
+
warnings.warn('temp_file_name is deprecated since NumPy v1.17, use '
|
102 |
+
'tempfile.mkstemp instead', DeprecationWarning, stacklevel=1)
|
103 |
+
fo, name = make_temp_file()
|
104 |
+
fo.close()
|
105 |
+
return name
|
106 |
+
|
107 |
+
def get_pythonexe():
|
108 |
+
pythonexe = sys.executable
|
109 |
+
if os.name in ['nt', 'dos']:
|
110 |
+
fdir, fn = os.path.split(pythonexe)
|
111 |
+
fn = fn.upper().replace('PYTHONW', 'PYTHON')
|
112 |
+
pythonexe = os.path.join(fdir, fn)
|
113 |
+
assert os.path.isfile(pythonexe), '%r is not a file' % (pythonexe,)
|
114 |
+
return pythonexe
|
115 |
+
|
116 |
+
def find_executable(exe, path=None, _cache={}):
|
117 |
+
"""Return full path of a executable or None.
|
118 |
+
|
119 |
+
Symbolic links are not followed.
|
120 |
+
"""
|
121 |
+
key = exe, path
|
122 |
+
try:
|
123 |
+
return _cache[key]
|
124 |
+
except KeyError:
|
125 |
+
pass
|
126 |
+
log.debug('find_executable(%r)' % exe)
|
127 |
+
orig_exe = exe
|
128 |
+
|
129 |
+
if path is None:
|
130 |
+
path = os.environ.get('PATH', os.defpath)
|
131 |
+
if os.name=='posix':
|
132 |
+
realpath = os.path.realpath
|
133 |
+
else:
|
134 |
+
realpath = lambda a:a
|
135 |
+
|
136 |
+
if exe.startswith('"'):
|
137 |
+
exe = exe[1:-1]
|
138 |
+
|
139 |
+
suffixes = ['']
|
140 |
+
if os.name in ['nt', 'dos', 'os2']:
|
141 |
+
fn, ext = os.path.splitext(exe)
|
142 |
+
extra_suffixes = ['.exe', '.com', '.bat']
|
143 |
+
if ext.lower() not in extra_suffixes:
|
144 |
+
suffixes = extra_suffixes
|
145 |
+
|
146 |
+
if os.path.isabs(exe):
|
147 |
+
paths = ['']
|
148 |
+
else:
|
149 |
+
paths = [ os.path.abspath(p) for p in path.split(os.pathsep) ]
|
150 |
+
|
151 |
+
for path in paths:
|
152 |
+
fn = os.path.join(path, exe)
|
153 |
+
for s in suffixes:
|
154 |
+
f_ext = fn+s
|
155 |
+
if not os.path.islink(f_ext):
|
156 |
+
f_ext = realpath(f_ext)
|
157 |
+
if os.path.isfile(f_ext) and os.access(f_ext, os.X_OK):
|
158 |
+
log.info('Found executable %s' % f_ext)
|
159 |
+
_cache[key] = f_ext
|
160 |
+
return f_ext
|
161 |
+
|
162 |
+
log.warn('Could not locate executable %s' % orig_exe)
|
163 |
+
return None
|
164 |
+
|
165 |
+
############################################################
|
166 |
+
|
167 |
+
def _preserve_environment( names ):
|
168 |
+
log.debug('_preserve_environment(%r)' % (names))
|
169 |
+
env = {name: os.environ.get(name) for name in names}
|
170 |
+
return env
|
171 |
+
|
172 |
+
def _update_environment( **env ):
|
173 |
+
log.debug('_update_environment(...)')
|
174 |
+
for name, value in env.items():
|
175 |
+
os.environ[name] = value or ''
|
176 |
+
|
177 |
+
def exec_command(command, execute_in='', use_shell=None, use_tee=None,
|
178 |
+
_with_python = 1, **env ):
|
179 |
+
"""
|
180 |
+
Return (status,output) of executed command.
|
181 |
+
|
182 |
+
.. deprecated:: 1.17
|
183 |
+
Use subprocess.Popen instead
|
184 |
+
|
185 |
+
Parameters
|
186 |
+
----------
|
187 |
+
command : str
|
188 |
+
A concatenated string of executable and arguments.
|
189 |
+
execute_in : str
|
190 |
+
Before running command ``cd execute_in`` and after ``cd -``.
|
191 |
+
use_shell : {bool, None}, optional
|
192 |
+
If True, execute ``sh -c command``. Default None (True)
|
193 |
+
use_tee : {bool, None}, optional
|
194 |
+
If True use tee. Default None (True)
|
195 |
+
|
196 |
+
|
197 |
+
Returns
|
198 |
+
-------
|
199 |
+
res : str
|
200 |
+
Both stdout and stderr messages.
|
201 |
+
|
202 |
+
Notes
|
203 |
+
-----
|
204 |
+
On NT, DOS systems the returned status is correct for external commands.
|
205 |
+
Wild cards will not work for non-posix systems or when use_shell=0.
|
206 |
+
|
207 |
+
"""
|
208 |
+
# 2019-01-30, 1.17
|
209 |
+
warnings.warn('exec_command is deprecated since NumPy v1.17, use '
|
210 |
+
'subprocess.Popen instead', DeprecationWarning, stacklevel=1)
|
211 |
+
log.debug('exec_command(%r,%s)' % (command,
|
212 |
+
','.join(['%s=%r'%kv for kv in env.items()])))
|
213 |
+
|
214 |
+
if use_tee is None:
|
215 |
+
use_tee = os.name=='posix'
|
216 |
+
if use_shell is None:
|
217 |
+
use_shell = os.name=='posix'
|
218 |
+
execute_in = os.path.abspath(execute_in)
|
219 |
+
oldcwd = os.path.abspath(os.getcwd())
|
220 |
+
|
221 |
+
if __name__[-12:] == 'exec_command':
|
222 |
+
exec_dir = os.path.dirname(os.path.abspath(__file__))
|
223 |
+
elif os.path.isfile('exec_command.py'):
|
224 |
+
exec_dir = os.path.abspath('.')
|
225 |
+
else:
|
226 |
+
exec_dir = os.path.abspath(sys.argv[0])
|
227 |
+
if os.path.isfile(exec_dir):
|
228 |
+
exec_dir = os.path.dirname(exec_dir)
|
229 |
+
|
230 |
+
if oldcwd!=execute_in:
|
231 |
+
os.chdir(execute_in)
|
232 |
+
log.debug('New cwd: %s' % execute_in)
|
233 |
+
else:
|
234 |
+
log.debug('Retaining cwd: %s' % oldcwd)
|
235 |
+
|
236 |
+
oldenv = _preserve_environment( list(env.keys()) )
|
237 |
+
_update_environment( **env )
|
238 |
+
|
239 |
+
try:
|
240 |
+
st = _exec_command(command,
|
241 |
+
use_shell=use_shell,
|
242 |
+
use_tee=use_tee,
|
243 |
+
**env)
|
244 |
+
finally:
|
245 |
+
if oldcwd!=execute_in:
|
246 |
+
os.chdir(oldcwd)
|
247 |
+
log.debug('Restored cwd to %s' % oldcwd)
|
248 |
+
_update_environment(**oldenv)
|
249 |
+
|
250 |
+
return st
|
251 |
+
|
252 |
+
|
253 |
+
def _exec_command(command, use_shell=None, use_tee = None, **env):
|
254 |
+
"""
|
255 |
+
Internal workhorse for exec_command().
|
256 |
+
"""
|
257 |
+
if use_shell is None:
|
258 |
+
use_shell = os.name=='posix'
|
259 |
+
if use_tee is None:
|
260 |
+
use_tee = os.name=='posix'
|
261 |
+
|
262 |
+
if os.name == 'posix' and use_shell:
|
263 |
+
# On POSIX, subprocess always uses /bin/sh, override
|
264 |
+
sh = os.environ.get('SHELL', '/bin/sh')
|
265 |
+
if is_sequence(command):
|
266 |
+
command = [sh, '-c', ' '.join(command)]
|
267 |
+
else:
|
268 |
+
command = [sh, '-c', command]
|
269 |
+
use_shell = False
|
270 |
+
|
271 |
+
elif os.name == 'nt' and is_sequence(command):
|
272 |
+
# On Windows, join the string for CreateProcess() ourselves as
|
273 |
+
# subprocess does it a bit differently
|
274 |
+
command = ' '.join(_quote_arg(arg) for arg in command)
|
275 |
+
|
276 |
+
# Inherit environment by default
|
277 |
+
env = env or None
|
278 |
+
try:
|
279 |
+
# text is set to False so that communicate()
|
280 |
+
# will return bytes. We need to decode the output ourselves
|
281 |
+
# so that Python will not raise a UnicodeDecodeError when
|
282 |
+
# it encounters an invalid character; rather, we simply replace it
|
283 |
+
proc = subprocess.Popen(command, shell=use_shell, env=env, text=False,
|
284 |
+
stdout=subprocess.PIPE,
|
285 |
+
stderr=subprocess.STDOUT)
|
286 |
+
except OSError:
|
287 |
+
# Return 127, as os.spawn*() and /bin/sh do
|
288 |
+
return 127, ''
|
289 |
+
|
290 |
+
text, err = proc.communicate()
|
291 |
+
mylocale = locale.getpreferredencoding(False)
|
292 |
+
if mylocale is None:
|
293 |
+
mylocale = 'ascii'
|
294 |
+
text = text.decode(mylocale, errors='replace')
|
295 |
+
text = text.replace('\r\n', '\n')
|
296 |
+
# Another historical oddity
|
297 |
+
if text[-1:] == '\n':
|
298 |
+
text = text[:-1]
|
299 |
+
|
300 |
+
if use_tee and text:
|
301 |
+
print(text)
|
302 |
+
return proc.returncode, text
|
303 |
+
|
304 |
+
|
305 |
+
def _quote_arg(arg):
|
306 |
+
"""
|
307 |
+
Quote the argument for safe use in a shell command line.
|
308 |
+
"""
|
309 |
+
# If there is a quote in the string, assume relevants parts of the
|
310 |
+
# string are already quoted (e.g. '-I"C:\\Program Files\\..."')
|
311 |
+
if '"' not in arg and ' ' in arg:
|
312 |
+
return '"%s"' % arg
|
313 |
+
return arg
|
314 |
+
|
315 |
+
############################################################
|
venv/lib/python3.10/site-packages/numpy/distutils/extension.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.extension
|
2 |
+
|
3 |
+
Provides the Extension class, used to describe C/C++ extension
|
4 |
+
modules in setup scripts.
|
5 |
+
|
6 |
+
Overridden to support f2py.
|
7 |
+
|
8 |
+
"""
|
9 |
+
import re
|
10 |
+
from distutils.extension import Extension as old_Extension
|
11 |
+
|
12 |
+
|
13 |
+
cxx_ext_re = re.compile(r'.*\.(cpp|cxx|cc)\Z', re.I).match
|
14 |
+
fortran_pyf_ext_re = re.compile(r'.*\.(f90|f95|f77|for|ftn|f|pyf)\Z', re.I).match
|
15 |
+
|
16 |
+
|
17 |
+
class Extension(old_Extension):
|
18 |
+
"""
|
19 |
+
Parameters
|
20 |
+
----------
|
21 |
+
name : str
|
22 |
+
Extension name.
|
23 |
+
sources : list of str
|
24 |
+
List of source file locations relative to the top directory of
|
25 |
+
the package.
|
26 |
+
extra_compile_args : list of str
|
27 |
+
Extra command line arguments to pass to the compiler.
|
28 |
+
extra_f77_compile_args : list of str
|
29 |
+
Extra command line arguments to pass to the fortran77 compiler.
|
30 |
+
extra_f90_compile_args : list of str
|
31 |
+
Extra command line arguments to pass to the fortran90 compiler.
|
32 |
+
"""
|
33 |
+
def __init__(
|
34 |
+
self, name, sources,
|
35 |
+
include_dirs=None,
|
36 |
+
define_macros=None,
|
37 |
+
undef_macros=None,
|
38 |
+
library_dirs=None,
|
39 |
+
libraries=None,
|
40 |
+
runtime_library_dirs=None,
|
41 |
+
extra_objects=None,
|
42 |
+
extra_compile_args=None,
|
43 |
+
extra_link_args=None,
|
44 |
+
export_symbols=None,
|
45 |
+
swig_opts=None,
|
46 |
+
depends=None,
|
47 |
+
language=None,
|
48 |
+
f2py_options=None,
|
49 |
+
module_dirs=None,
|
50 |
+
extra_c_compile_args=None,
|
51 |
+
extra_cxx_compile_args=None,
|
52 |
+
extra_f77_compile_args=None,
|
53 |
+
extra_f90_compile_args=None,):
|
54 |
+
|
55 |
+
old_Extension.__init__(
|
56 |
+
self, name, [],
|
57 |
+
include_dirs=include_dirs,
|
58 |
+
define_macros=define_macros,
|
59 |
+
undef_macros=undef_macros,
|
60 |
+
library_dirs=library_dirs,
|
61 |
+
libraries=libraries,
|
62 |
+
runtime_library_dirs=runtime_library_dirs,
|
63 |
+
extra_objects=extra_objects,
|
64 |
+
extra_compile_args=extra_compile_args,
|
65 |
+
extra_link_args=extra_link_args,
|
66 |
+
export_symbols=export_symbols)
|
67 |
+
|
68 |
+
# Avoid assert statements checking that sources contains strings:
|
69 |
+
self.sources = sources
|
70 |
+
|
71 |
+
# Python 2.4 distutils new features
|
72 |
+
self.swig_opts = swig_opts or []
|
73 |
+
# swig_opts is assumed to be a list. Here we handle the case where it
|
74 |
+
# is specified as a string instead.
|
75 |
+
if isinstance(self.swig_opts, str):
|
76 |
+
import warnings
|
77 |
+
msg = "swig_opts is specified as a string instead of a list"
|
78 |
+
warnings.warn(msg, SyntaxWarning, stacklevel=2)
|
79 |
+
self.swig_opts = self.swig_opts.split()
|
80 |
+
|
81 |
+
# Python 2.3 distutils new features
|
82 |
+
self.depends = depends or []
|
83 |
+
self.language = language
|
84 |
+
|
85 |
+
# numpy_distutils features
|
86 |
+
self.f2py_options = f2py_options or []
|
87 |
+
self.module_dirs = module_dirs or []
|
88 |
+
self.extra_c_compile_args = extra_c_compile_args or []
|
89 |
+
self.extra_cxx_compile_args = extra_cxx_compile_args or []
|
90 |
+
self.extra_f77_compile_args = extra_f77_compile_args or []
|
91 |
+
self.extra_f90_compile_args = extra_f90_compile_args or []
|
92 |
+
|
93 |
+
return
|
94 |
+
|
95 |
+
def has_cxx_sources(self):
|
96 |
+
for source in self.sources:
|
97 |
+
if cxx_ext_re(str(source)):
|
98 |
+
return True
|
99 |
+
return False
|
100 |
+
|
101 |
+
def has_f2py_sources(self):
|
102 |
+
for source in self.sources:
|
103 |
+
if fortran_pyf_ext_re(source):
|
104 |
+
return True
|
105 |
+
return False
|
106 |
+
|
107 |
+
# class Extension
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__init__.py
ADDED
@@ -0,0 +1,1035 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""numpy.distutils.fcompiler
|
2 |
+
|
3 |
+
Contains FCompiler, an abstract base class that defines the interface
|
4 |
+
for the numpy.distutils Fortran compiler abstraction model.
|
5 |
+
|
6 |
+
Terminology:
|
7 |
+
|
8 |
+
To be consistent, where the term 'executable' is used, it means the single
|
9 |
+
file, like 'gcc', that is executed, and should be a string. In contrast,
|
10 |
+
'command' means the entire command line, like ['gcc', '-c', 'file.c'], and
|
11 |
+
should be a list.
|
12 |
+
|
13 |
+
But note that FCompiler.executables is actually a dictionary of commands.
|
14 |
+
|
15 |
+
"""
|
16 |
+
__all__ = ['FCompiler', 'new_fcompiler', 'show_fcompilers',
|
17 |
+
'dummy_fortran_file']
|
18 |
+
|
19 |
+
import os
|
20 |
+
import sys
|
21 |
+
import re
|
22 |
+
from pathlib import Path
|
23 |
+
|
24 |
+
from distutils.sysconfig import get_python_lib
|
25 |
+
from distutils.fancy_getopt import FancyGetopt
|
26 |
+
from distutils.errors import DistutilsModuleError, \
|
27 |
+
DistutilsExecError, CompileError, LinkError, DistutilsPlatformError
|
28 |
+
from distutils.util import split_quoted, strtobool
|
29 |
+
|
30 |
+
from numpy.distutils.ccompiler import CCompiler, gen_lib_options
|
31 |
+
from numpy.distutils import log
|
32 |
+
from numpy.distutils.misc_util import is_string, all_strings, is_sequence, \
|
33 |
+
make_temp_file, get_shared_lib_extension
|
34 |
+
from numpy.distutils.exec_command import find_executable
|
35 |
+
from numpy.distutils import _shell_utils
|
36 |
+
|
37 |
+
from .environment import EnvironmentConfig
|
38 |
+
|
39 |
+
__metaclass__ = type
|
40 |
+
|
41 |
+
|
42 |
+
FORTRAN_COMMON_FIXED_EXTENSIONS = ['.for', '.ftn', '.f77', '.f']
|
43 |
+
|
44 |
+
|
45 |
+
class CompilerNotFound(Exception):
|
46 |
+
pass
|
47 |
+
|
48 |
+
def flaglist(s):
|
49 |
+
if is_string(s):
|
50 |
+
return split_quoted(s)
|
51 |
+
else:
|
52 |
+
return s
|
53 |
+
|
54 |
+
def str2bool(s):
|
55 |
+
if is_string(s):
|
56 |
+
return strtobool(s)
|
57 |
+
return bool(s)
|
58 |
+
|
59 |
+
def is_sequence_of_strings(seq):
|
60 |
+
return is_sequence(seq) and all_strings(seq)
|
61 |
+
|
62 |
+
class FCompiler(CCompiler):
|
63 |
+
"""Abstract base class to define the interface that must be implemented
|
64 |
+
by real Fortran compiler classes.
|
65 |
+
|
66 |
+
Methods that subclasses may redefine:
|
67 |
+
|
68 |
+
update_executables(), find_executables(), get_version()
|
69 |
+
get_flags(), get_flags_opt(), get_flags_arch(), get_flags_debug()
|
70 |
+
get_flags_f77(), get_flags_opt_f77(), get_flags_arch_f77(),
|
71 |
+
get_flags_debug_f77(), get_flags_f90(), get_flags_opt_f90(),
|
72 |
+
get_flags_arch_f90(), get_flags_debug_f90(),
|
73 |
+
get_flags_fix(), get_flags_linker_so()
|
74 |
+
|
75 |
+
DON'T call these methods (except get_version) after
|
76 |
+
constructing a compiler instance or inside any other method.
|
77 |
+
All methods, except update_executables() and find_executables(),
|
78 |
+
may call the get_version() method.
|
79 |
+
|
80 |
+
After constructing a compiler instance, always call customize(dist=None)
|
81 |
+
method that finalizes compiler construction and makes the following
|
82 |
+
attributes available:
|
83 |
+
compiler_f77
|
84 |
+
compiler_f90
|
85 |
+
compiler_fix
|
86 |
+
linker_so
|
87 |
+
archiver
|
88 |
+
ranlib
|
89 |
+
libraries
|
90 |
+
library_dirs
|
91 |
+
"""
|
92 |
+
|
93 |
+
# These are the environment variables and distutils keys used.
|
94 |
+
# Each configuration description is
|
95 |
+
# (<hook name>, <environment variable>, <key in distutils.cfg>, <convert>, <append>)
|
96 |
+
# The hook names are handled by the self._environment_hook method.
|
97 |
+
# - names starting with 'self.' call methods in this class
|
98 |
+
# - names starting with 'exe.' return the key in the executables dict
|
99 |
+
# - names like 'flags.YYY' return self.get_flag_YYY()
|
100 |
+
# convert is either None or a function to convert a string to the
|
101 |
+
# appropriate type used.
|
102 |
+
|
103 |
+
distutils_vars = EnvironmentConfig(
|
104 |
+
distutils_section='config_fc',
|
105 |
+
noopt = (None, None, 'noopt', str2bool, False),
|
106 |
+
noarch = (None, None, 'noarch', str2bool, False),
|
107 |
+
debug = (None, None, 'debug', str2bool, False),
|
108 |
+
verbose = (None, None, 'verbose', str2bool, False),
|
109 |
+
)
|
110 |
+
|
111 |
+
command_vars = EnvironmentConfig(
|
112 |
+
distutils_section='config_fc',
|
113 |
+
compiler_f77 = ('exe.compiler_f77', 'F77', 'f77exec', None, False),
|
114 |
+
compiler_f90 = ('exe.compiler_f90', 'F90', 'f90exec', None, False),
|
115 |
+
compiler_fix = ('exe.compiler_fix', 'F90', 'f90exec', None, False),
|
116 |
+
version_cmd = ('exe.version_cmd', None, None, None, False),
|
117 |
+
linker_so = ('exe.linker_so', 'LDSHARED', 'ldshared', None, False),
|
118 |
+
linker_exe = ('exe.linker_exe', 'LD', 'ld', None, False),
|
119 |
+
archiver = (None, 'AR', 'ar', None, False),
|
120 |
+
ranlib = (None, 'RANLIB', 'ranlib', None, False),
|
121 |
+
)
|
122 |
+
|
123 |
+
flag_vars = EnvironmentConfig(
|
124 |
+
distutils_section='config_fc',
|
125 |
+
f77 = ('flags.f77', 'F77FLAGS', 'f77flags', flaglist, True),
|
126 |
+
f90 = ('flags.f90', 'F90FLAGS', 'f90flags', flaglist, True),
|
127 |
+
free = ('flags.free', 'FREEFLAGS', 'freeflags', flaglist, True),
|
128 |
+
fix = ('flags.fix', None, None, flaglist, False),
|
129 |
+
opt = ('flags.opt', 'FOPT', 'opt', flaglist, True),
|
130 |
+
opt_f77 = ('flags.opt_f77', None, None, flaglist, False),
|
131 |
+
opt_f90 = ('flags.opt_f90', None, None, flaglist, False),
|
132 |
+
arch = ('flags.arch', 'FARCH', 'arch', flaglist, False),
|
133 |
+
arch_f77 = ('flags.arch_f77', None, None, flaglist, False),
|
134 |
+
arch_f90 = ('flags.arch_f90', None, None, flaglist, False),
|
135 |
+
debug = ('flags.debug', 'FDEBUG', 'fdebug', flaglist, True),
|
136 |
+
debug_f77 = ('flags.debug_f77', None, None, flaglist, False),
|
137 |
+
debug_f90 = ('flags.debug_f90', None, None, flaglist, False),
|
138 |
+
flags = ('self.get_flags', 'FFLAGS', 'fflags', flaglist, True),
|
139 |
+
linker_so = ('flags.linker_so', 'LDFLAGS', 'ldflags', flaglist, True),
|
140 |
+
linker_exe = ('flags.linker_exe', 'LDFLAGS', 'ldflags', flaglist, True),
|
141 |
+
ar = ('flags.ar', 'ARFLAGS', 'arflags', flaglist, True),
|
142 |
+
)
|
143 |
+
|
144 |
+
language_map = {'.f': 'f77',
|
145 |
+
'.for': 'f77',
|
146 |
+
'.F': 'f77', # XXX: needs preprocessor
|
147 |
+
'.ftn': 'f77',
|
148 |
+
'.f77': 'f77',
|
149 |
+
'.f90': 'f90',
|
150 |
+
'.F90': 'f90', # XXX: needs preprocessor
|
151 |
+
'.f95': 'f90',
|
152 |
+
}
|
153 |
+
language_order = ['f90', 'f77']
|
154 |
+
|
155 |
+
|
156 |
+
# These will be set by the subclass
|
157 |
+
|
158 |
+
compiler_type = None
|
159 |
+
compiler_aliases = ()
|
160 |
+
version_pattern = None
|
161 |
+
|
162 |
+
possible_executables = []
|
163 |
+
executables = {
|
164 |
+
'version_cmd': ["f77", "-v"],
|
165 |
+
'compiler_f77': ["f77"],
|
166 |
+
'compiler_f90': ["f90"],
|
167 |
+
'compiler_fix': ["f90", "-fixed"],
|
168 |
+
'linker_so': ["f90", "-shared"],
|
169 |
+
'linker_exe': ["f90"],
|
170 |
+
'archiver': ["ar", "-cr"],
|
171 |
+
'ranlib': None,
|
172 |
+
}
|
173 |
+
|
174 |
+
# If compiler does not support compiling Fortran 90 then it can
|
175 |
+
# suggest using another compiler. For example, gnu would suggest
|
176 |
+
# gnu95 compiler type when there are F90 sources.
|
177 |
+
suggested_f90_compiler = None
|
178 |
+
|
179 |
+
compile_switch = "-c"
|
180 |
+
object_switch = "-o " # Ending space matters! It will be stripped
|
181 |
+
# but if it is missing then object_switch
|
182 |
+
# will be prefixed to object file name by
|
183 |
+
# string concatenation.
|
184 |
+
library_switch = "-o " # Ditto!
|
185 |
+
|
186 |
+
# Switch to specify where module files are created and searched
|
187 |
+
# for USE statement. Normally it is a string and also here ending
|
188 |
+
# space matters. See above.
|
189 |
+
module_dir_switch = None
|
190 |
+
|
191 |
+
# Switch to specify where module files are searched for USE statement.
|
192 |
+
module_include_switch = '-I'
|
193 |
+
|
194 |
+
pic_flags = [] # Flags to create position-independent code
|
195 |
+
|
196 |
+
src_extensions = ['.for', '.ftn', '.f77', '.f', '.f90', '.f95', '.F', '.F90', '.FOR']
|
197 |
+
obj_extension = ".o"
|
198 |
+
|
199 |
+
shared_lib_extension = get_shared_lib_extension()
|
200 |
+
static_lib_extension = ".a" # or .lib
|
201 |
+
static_lib_format = "lib%s%s" # or %s%s
|
202 |
+
shared_lib_format = "%s%s"
|
203 |
+
exe_extension = ""
|
204 |
+
|
205 |
+
_exe_cache = {}
|
206 |
+
|
207 |
+
_executable_keys = ['version_cmd', 'compiler_f77', 'compiler_f90',
|
208 |
+
'compiler_fix', 'linker_so', 'linker_exe', 'archiver',
|
209 |
+
'ranlib']
|
210 |
+
|
211 |
+
# This will be set by new_fcompiler when called in
|
212 |
+
# command/{build_ext.py, build_clib.py, config.py} files.
|
213 |
+
c_compiler = None
|
214 |
+
|
215 |
+
# extra_{f77,f90}_compile_args are set by build_ext.build_extension method
|
216 |
+
extra_f77_compile_args = []
|
217 |
+
extra_f90_compile_args = []
|
218 |
+
|
219 |
+
def __init__(self, *args, **kw):
|
220 |
+
CCompiler.__init__(self, *args, **kw)
|
221 |
+
self.distutils_vars = self.distutils_vars.clone(self._environment_hook)
|
222 |
+
self.command_vars = self.command_vars.clone(self._environment_hook)
|
223 |
+
self.flag_vars = self.flag_vars.clone(self._environment_hook)
|
224 |
+
self.executables = self.executables.copy()
|
225 |
+
for e in self._executable_keys:
|
226 |
+
if e not in self.executables:
|
227 |
+
self.executables[e] = None
|
228 |
+
|
229 |
+
# Some methods depend on .customize() being called first, so
|
230 |
+
# this keeps track of whether that's happened yet.
|
231 |
+
self._is_customised = False
|
232 |
+
|
233 |
+
def __copy__(self):
|
234 |
+
obj = self.__new__(self.__class__)
|
235 |
+
obj.__dict__.update(self.__dict__)
|
236 |
+
obj.distutils_vars = obj.distutils_vars.clone(obj._environment_hook)
|
237 |
+
obj.command_vars = obj.command_vars.clone(obj._environment_hook)
|
238 |
+
obj.flag_vars = obj.flag_vars.clone(obj._environment_hook)
|
239 |
+
obj.executables = obj.executables.copy()
|
240 |
+
return obj
|
241 |
+
|
242 |
+
def copy(self):
|
243 |
+
return self.__copy__()
|
244 |
+
|
245 |
+
# Use properties for the attributes used by CCompiler. Setting them
|
246 |
+
# as attributes from the self.executables dictionary is error-prone,
|
247 |
+
# so we get them from there each time.
|
248 |
+
def _command_property(key):
|
249 |
+
def fget(self):
|
250 |
+
assert self._is_customised
|
251 |
+
return self.executables[key]
|
252 |
+
return property(fget=fget)
|
253 |
+
version_cmd = _command_property('version_cmd')
|
254 |
+
compiler_f77 = _command_property('compiler_f77')
|
255 |
+
compiler_f90 = _command_property('compiler_f90')
|
256 |
+
compiler_fix = _command_property('compiler_fix')
|
257 |
+
linker_so = _command_property('linker_so')
|
258 |
+
linker_exe = _command_property('linker_exe')
|
259 |
+
archiver = _command_property('archiver')
|
260 |
+
ranlib = _command_property('ranlib')
|
261 |
+
|
262 |
+
# Make our terminology consistent.
|
263 |
+
def set_executable(self, key, value):
|
264 |
+
self.set_command(key, value)
|
265 |
+
|
266 |
+
def set_commands(self, **kw):
|
267 |
+
for k, v in kw.items():
|
268 |
+
self.set_command(k, v)
|
269 |
+
|
270 |
+
def set_command(self, key, value):
|
271 |
+
if not key in self._executable_keys:
|
272 |
+
raise ValueError(
|
273 |
+
"unknown executable '%s' for class %s" %
|
274 |
+
(key, self.__class__.__name__))
|
275 |
+
if is_string(value):
|
276 |
+
value = split_quoted(value)
|
277 |
+
assert value is None or is_sequence_of_strings(value[1:]), (key, value)
|
278 |
+
self.executables[key] = value
|
279 |
+
|
280 |
+
######################################################################
|
281 |
+
## Methods that subclasses may redefine. But don't call these methods!
|
282 |
+
## They are private to FCompiler class and may return unexpected
|
283 |
+
## results if used elsewhere. So, you have been warned..
|
284 |
+
|
285 |
+
def find_executables(self):
|
286 |
+
"""Go through the self.executables dictionary, and attempt to
|
287 |
+
find and assign appropriate executables.
|
288 |
+
|
289 |
+
Executable names are looked for in the environment (environment
|
290 |
+
variables, the distutils.cfg, and command line), the 0th-element of
|
291 |
+
the command list, and the self.possible_executables list.
|
292 |
+
|
293 |
+
Also, if the 0th element is "<F77>" or "<F90>", the Fortran 77
|
294 |
+
or the Fortran 90 compiler executable is used, unless overridden
|
295 |
+
by an environment setting.
|
296 |
+
|
297 |
+
Subclasses should call this if overridden.
|
298 |
+
"""
|
299 |
+
assert self._is_customised
|
300 |
+
exe_cache = self._exe_cache
|
301 |
+
def cached_find_executable(exe):
|
302 |
+
if exe in exe_cache:
|
303 |
+
return exe_cache[exe]
|
304 |
+
fc_exe = find_executable(exe)
|
305 |
+
exe_cache[exe] = exe_cache[fc_exe] = fc_exe
|
306 |
+
return fc_exe
|
307 |
+
def verify_command_form(name, value):
|
308 |
+
if value is not None and not is_sequence_of_strings(value):
|
309 |
+
raise ValueError(
|
310 |
+
"%s value %r is invalid in class %s" %
|
311 |
+
(name, value, self.__class__.__name__))
|
312 |
+
def set_exe(exe_key, f77=None, f90=None):
|
313 |
+
cmd = self.executables.get(exe_key, None)
|
314 |
+
if not cmd:
|
315 |
+
return None
|
316 |
+
# Note that we get cmd[0] here if the environment doesn't
|
317 |
+
# have anything set
|
318 |
+
exe_from_environ = getattr(self.command_vars, exe_key)
|
319 |
+
if not exe_from_environ:
|
320 |
+
possibles = [f90, f77] + self.possible_executables
|
321 |
+
else:
|
322 |
+
possibles = [exe_from_environ] + self.possible_executables
|
323 |
+
|
324 |
+
seen = set()
|
325 |
+
unique_possibles = []
|
326 |
+
for e in possibles:
|
327 |
+
if e == '<F77>':
|
328 |
+
e = f77
|
329 |
+
elif e == '<F90>':
|
330 |
+
e = f90
|
331 |
+
if not e or e in seen:
|
332 |
+
continue
|
333 |
+
seen.add(e)
|
334 |
+
unique_possibles.append(e)
|
335 |
+
|
336 |
+
for exe in unique_possibles:
|
337 |
+
fc_exe = cached_find_executable(exe)
|
338 |
+
if fc_exe:
|
339 |
+
cmd[0] = fc_exe
|
340 |
+
return fc_exe
|
341 |
+
self.set_command(exe_key, None)
|
342 |
+
return None
|
343 |
+
|
344 |
+
ctype = self.compiler_type
|
345 |
+
f90 = set_exe('compiler_f90')
|
346 |
+
if not f90:
|
347 |
+
f77 = set_exe('compiler_f77')
|
348 |
+
if f77:
|
349 |
+
log.warn('%s: no Fortran 90 compiler found' % ctype)
|
350 |
+
else:
|
351 |
+
raise CompilerNotFound('%s: f90 nor f77' % ctype)
|
352 |
+
else:
|
353 |
+
f77 = set_exe('compiler_f77', f90=f90)
|
354 |
+
if not f77:
|
355 |
+
log.warn('%s: no Fortran 77 compiler found' % ctype)
|
356 |
+
set_exe('compiler_fix', f90=f90)
|
357 |
+
|
358 |
+
set_exe('linker_so', f77=f77, f90=f90)
|
359 |
+
set_exe('linker_exe', f77=f77, f90=f90)
|
360 |
+
set_exe('version_cmd', f77=f77, f90=f90)
|
361 |
+
set_exe('archiver')
|
362 |
+
set_exe('ranlib')
|
363 |
+
|
364 |
+
def update_executables(self):
|
365 |
+
"""Called at the beginning of customisation. Subclasses should
|
366 |
+
override this if they need to set up the executables dictionary.
|
367 |
+
|
368 |
+
Note that self.find_executables() is run afterwards, so the
|
369 |
+
self.executables dictionary values can contain <F77> or <F90> as
|
370 |
+
the command, which will be replaced by the found F77 or F90
|
371 |
+
compiler.
|
372 |
+
"""
|
373 |
+
pass
|
374 |
+
|
375 |
+
def get_flags(self):
|
376 |
+
"""List of flags common to all compiler types."""
|
377 |
+
return [] + self.pic_flags
|
378 |
+
|
379 |
+
def _get_command_flags(self, key):
|
380 |
+
cmd = self.executables.get(key, None)
|
381 |
+
if cmd is None:
|
382 |
+
return []
|
383 |
+
return cmd[1:]
|
384 |
+
|
385 |
+
def get_flags_f77(self):
|
386 |
+
"""List of Fortran 77 specific flags."""
|
387 |
+
return self._get_command_flags('compiler_f77')
|
388 |
+
def get_flags_f90(self):
|
389 |
+
"""List of Fortran 90 specific flags."""
|
390 |
+
return self._get_command_flags('compiler_f90')
|
391 |
+
def get_flags_free(self):
|
392 |
+
"""List of Fortran 90 free format specific flags."""
|
393 |
+
return []
|
394 |
+
def get_flags_fix(self):
|
395 |
+
"""List of Fortran 90 fixed format specific flags."""
|
396 |
+
return self._get_command_flags('compiler_fix')
|
397 |
+
def get_flags_linker_so(self):
|
398 |
+
"""List of linker flags to build a shared library."""
|
399 |
+
return self._get_command_flags('linker_so')
|
400 |
+
def get_flags_linker_exe(self):
|
401 |
+
"""List of linker flags to build an executable."""
|
402 |
+
return self._get_command_flags('linker_exe')
|
403 |
+
def get_flags_ar(self):
|
404 |
+
"""List of archiver flags. """
|
405 |
+
return self._get_command_flags('archiver')
|
406 |
+
def get_flags_opt(self):
|
407 |
+
"""List of architecture independent compiler flags."""
|
408 |
+
return []
|
409 |
+
def get_flags_arch(self):
|
410 |
+
"""List of architecture dependent compiler flags."""
|
411 |
+
return []
|
412 |
+
def get_flags_debug(self):
|
413 |
+
"""List of compiler flags to compile with debugging information."""
|
414 |
+
return []
|
415 |
+
|
416 |
+
get_flags_opt_f77 = get_flags_opt_f90 = get_flags_opt
|
417 |
+
get_flags_arch_f77 = get_flags_arch_f90 = get_flags_arch
|
418 |
+
get_flags_debug_f77 = get_flags_debug_f90 = get_flags_debug
|
419 |
+
|
420 |
+
def get_libraries(self):
|
421 |
+
"""List of compiler libraries."""
|
422 |
+
return self.libraries[:]
|
423 |
+
def get_library_dirs(self):
|
424 |
+
"""List of compiler library directories."""
|
425 |
+
return self.library_dirs[:]
|
426 |
+
|
427 |
+
def get_version(self, force=False, ok_status=[0]):
|
428 |
+
assert self._is_customised
|
429 |
+
version = CCompiler.get_version(self, force=force, ok_status=ok_status)
|
430 |
+
if version is None:
|
431 |
+
raise CompilerNotFound()
|
432 |
+
return version
|
433 |
+
|
434 |
+
|
435 |
+
############################################################
|
436 |
+
|
437 |
+
## Public methods:
|
438 |
+
|
439 |
+
def customize(self, dist = None):
|
440 |
+
"""Customize Fortran compiler.
|
441 |
+
|
442 |
+
This method gets Fortran compiler specific information from
|
443 |
+
(i) class definition, (ii) environment, (iii) distutils config
|
444 |
+
files, and (iv) command line (later overrides earlier).
|
445 |
+
|
446 |
+
This method should be always called after constructing a
|
447 |
+
compiler instance. But not in __init__ because Distribution
|
448 |
+
instance is needed for (iii) and (iv).
|
449 |
+
"""
|
450 |
+
log.info('customize %s' % (self.__class__.__name__))
|
451 |
+
|
452 |
+
self._is_customised = True
|
453 |
+
|
454 |
+
self.distutils_vars.use_distribution(dist)
|
455 |
+
self.command_vars.use_distribution(dist)
|
456 |
+
self.flag_vars.use_distribution(dist)
|
457 |
+
|
458 |
+
self.update_executables()
|
459 |
+
|
460 |
+
# find_executables takes care of setting the compiler commands,
|
461 |
+
# version_cmd, linker_so, linker_exe, ar, and ranlib
|
462 |
+
self.find_executables()
|
463 |
+
|
464 |
+
noopt = self.distutils_vars.get('noopt', False)
|
465 |
+
noarch = self.distutils_vars.get('noarch', noopt)
|
466 |
+
debug = self.distutils_vars.get('debug', False)
|
467 |
+
|
468 |
+
f77 = self.command_vars.compiler_f77
|
469 |
+
f90 = self.command_vars.compiler_f90
|
470 |
+
|
471 |
+
f77flags = []
|
472 |
+
f90flags = []
|
473 |
+
freeflags = []
|
474 |
+
fixflags = []
|
475 |
+
|
476 |
+
if f77:
|
477 |
+
f77 = _shell_utils.NativeParser.split(f77)
|
478 |
+
f77flags = self.flag_vars.f77
|
479 |
+
if f90:
|
480 |
+
f90 = _shell_utils.NativeParser.split(f90)
|
481 |
+
f90flags = self.flag_vars.f90
|
482 |
+
freeflags = self.flag_vars.free
|
483 |
+
# XXX Assuming that free format is default for f90 compiler.
|
484 |
+
fix = self.command_vars.compiler_fix
|
485 |
+
# NOTE: this and similar examples are probably just
|
486 |
+
# excluding --coverage flag when F90 = gfortran --coverage
|
487 |
+
# instead of putting that flag somewhere more appropriate
|
488 |
+
# this and similar examples where a Fortran compiler
|
489 |
+
# environment variable has been customized by CI or a user
|
490 |
+
# should perhaps eventually be more thoroughly tested and more
|
491 |
+
# robustly handled
|
492 |
+
if fix:
|
493 |
+
fix = _shell_utils.NativeParser.split(fix)
|
494 |
+
fixflags = self.flag_vars.fix + f90flags
|
495 |
+
|
496 |
+
oflags, aflags, dflags = [], [], []
|
497 |
+
# examine get_flags_<tag>_<compiler> for extra flags
|
498 |
+
# only add them if the method is different from get_flags_<tag>
|
499 |
+
def get_flags(tag, flags):
|
500 |
+
# note that self.flag_vars.<tag> calls self.get_flags_<tag>()
|
501 |
+
flags.extend(getattr(self.flag_vars, tag))
|
502 |
+
this_get = getattr(self, 'get_flags_' + tag)
|
503 |
+
for name, c, flagvar in [('f77', f77, f77flags),
|
504 |
+
('f90', f90, f90flags),
|
505 |
+
('f90', fix, fixflags)]:
|
506 |
+
t = '%s_%s' % (tag, name)
|
507 |
+
if c and this_get is not getattr(self, 'get_flags_' + t):
|
508 |
+
flagvar.extend(getattr(self.flag_vars, t))
|
509 |
+
if not noopt:
|
510 |
+
get_flags('opt', oflags)
|
511 |
+
if not noarch:
|
512 |
+
get_flags('arch', aflags)
|
513 |
+
if debug:
|
514 |
+
get_flags('debug', dflags)
|
515 |
+
|
516 |
+
fflags = self.flag_vars.flags + dflags + oflags + aflags
|
517 |
+
|
518 |
+
if f77:
|
519 |
+
self.set_commands(compiler_f77=f77+f77flags+fflags)
|
520 |
+
if f90:
|
521 |
+
self.set_commands(compiler_f90=f90+freeflags+f90flags+fflags)
|
522 |
+
if fix:
|
523 |
+
self.set_commands(compiler_fix=fix+fixflags+fflags)
|
524 |
+
|
525 |
+
|
526 |
+
#XXX: Do we need LDSHARED->SOSHARED, LDFLAGS->SOFLAGS
|
527 |
+
linker_so = self.linker_so
|
528 |
+
if linker_so:
|
529 |
+
linker_so_flags = self.flag_vars.linker_so
|
530 |
+
if sys.platform.startswith('aix'):
|
531 |
+
python_lib = get_python_lib(standard_lib=1)
|
532 |
+
ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
|
533 |
+
python_exp = os.path.join(python_lib, 'config', 'python.exp')
|
534 |
+
linker_so = [ld_so_aix] + linker_so + ['-bI:'+python_exp]
|
535 |
+
if sys.platform.startswith('os400'):
|
536 |
+
from distutils.sysconfig import get_config_var
|
537 |
+
python_config = get_config_var('LIBPL')
|
538 |
+
ld_so_aix = os.path.join(python_config, 'ld_so_aix')
|
539 |
+
python_exp = os.path.join(python_config, 'python.exp')
|
540 |
+
linker_so = [ld_so_aix] + linker_so + ['-bI:'+python_exp]
|
541 |
+
self.set_commands(linker_so=linker_so+linker_so_flags)
|
542 |
+
|
543 |
+
linker_exe = self.linker_exe
|
544 |
+
if linker_exe:
|
545 |
+
linker_exe_flags = self.flag_vars.linker_exe
|
546 |
+
self.set_commands(linker_exe=linker_exe+linker_exe_flags)
|
547 |
+
|
548 |
+
ar = self.command_vars.archiver
|
549 |
+
if ar:
|
550 |
+
arflags = self.flag_vars.ar
|
551 |
+
self.set_commands(archiver=[ar]+arflags)
|
552 |
+
|
553 |
+
self.set_library_dirs(self.get_library_dirs())
|
554 |
+
self.set_libraries(self.get_libraries())
|
555 |
+
|
556 |
+
def dump_properties(self):
|
557 |
+
"""Print out the attributes of a compiler instance."""
|
558 |
+
props = []
|
559 |
+
for key in list(self.executables.keys()) + \
|
560 |
+
['version', 'libraries', 'library_dirs',
|
561 |
+
'object_switch', 'compile_switch']:
|
562 |
+
if hasattr(self, key):
|
563 |
+
v = getattr(self, key)
|
564 |
+
props.append((key, None, '= '+repr(v)))
|
565 |
+
props.sort()
|
566 |
+
|
567 |
+
pretty_printer = FancyGetopt(props)
|
568 |
+
for l in pretty_printer.generate_help("%s instance properties:" \
|
569 |
+
% (self.__class__.__name__)):
|
570 |
+
if l[:4]==' --':
|
571 |
+
l = ' ' + l[4:]
|
572 |
+
print(l)
|
573 |
+
|
574 |
+
###################
|
575 |
+
|
576 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
577 |
+
"""Compile 'src' to product 'obj'."""
|
578 |
+
src_flags = {}
|
579 |
+
if Path(src).suffix.lower() in FORTRAN_COMMON_FIXED_EXTENSIONS \
|
580 |
+
and not has_f90_header(src):
|
581 |
+
flavor = ':f77'
|
582 |
+
compiler = self.compiler_f77
|
583 |
+
src_flags = get_f77flags(src)
|
584 |
+
extra_compile_args = self.extra_f77_compile_args or []
|
585 |
+
elif is_free_format(src):
|
586 |
+
flavor = ':f90'
|
587 |
+
compiler = self.compiler_f90
|
588 |
+
if compiler is None:
|
589 |
+
raise DistutilsExecError('f90 not supported by %s needed for %s'\
|
590 |
+
% (self.__class__.__name__, src))
|
591 |
+
extra_compile_args = self.extra_f90_compile_args or []
|
592 |
+
else:
|
593 |
+
flavor = ':fix'
|
594 |
+
compiler = self.compiler_fix
|
595 |
+
if compiler is None:
|
596 |
+
raise DistutilsExecError('f90 (fixed) not supported by %s needed for %s'\
|
597 |
+
% (self.__class__.__name__, src))
|
598 |
+
extra_compile_args = self.extra_f90_compile_args or []
|
599 |
+
if self.object_switch[-1]==' ':
|
600 |
+
o_args = [self.object_switch.strip(), obj]
|
601 |
+
else:
|
602 |
+
o_args = [self.object_switch.strip()+obj]
|
603 |
+
|
604 |
+
assert self.compile_switch.strip()
|
605 |
+
s_args = [self.compile_switch, src]
|
606 |
+
|
607 |
+
if extra_compile_args:
|
608 |
+
log.info('extra %s options: %r' \
|
609 |
+
% (flavor[1:], ' '.join(extra_compile_args)))
|
610 |
+
|
611 |
+
extra_flags = src_flags.get(self.compiler_type, [])
|
612 |
+
if extra_flags:
|
613 |
+
log.info('using compile options from source: %r' \
|
614 |
+
% ' '.join(extra_flags))
|
615 |
+
|
616 |
+
command = compiler + cc_args + extra_flags + s_args + o_args \
|
617 |
+
+ extra_postargs + extra_compile_args
|
618 |
+
|
619 |
+
display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,
|
620 |
+
src)
|
621 |
+
try:
|
622 |
+
self.spawn(command, display=display)
|
623 |
+
except DistutilsExecError as e:
|
624 |
+
msg = str(e)
|
625 |
+
raise CompileError(msg) from None
|
626 |
+
|
627 |
+
def module_options(self, module_dirs, module_build_dir):
|
628 |
+
options = []
|
629 |
+
if self.module_dir_switch is not None:
|
630 |
+
if self.module_dir_switch[-1]==' ':
|
631 |
+
options.extend([self.module_dir_switch.strip(), module_build_dir])
|
632 |
+
else:
|
633 |
+
options.append(self.module_dir_switch.strip()+module_build_dir)
|
634 |
+
else:
|
635 |
+
print('XXX: module_build_dir=%r option ignored' % (module_build_dir))
|
636 |
+
print('XXX: Fix module_dir_switch for ', self.__class__.__name__)
|
637 |
+
if self.module_include_switch is not None:
|
638 |
+
for d in [module_build_dir]+module_dirs:
|
639 |
+
options.append('%s%s' % (self.module_include_switch, d))
|
640 |
+
else:
|
641 |
+
print('XXX: module_dirs=%r option ignored' % (module_dirs))
|
642 |
+
print('XXX: Fix module_include_switch for ', self.__class__.__name__)
|
643 |
+
return options
|
644 |
+
|
645 |
+
def library_option(self, lib):
|
646 |
+
return "-l" + lib
|
647 |
+
def library_dir_option(self, dir):
|
648 |
+
return "-L" + dir
|
649 |
+
|
650 |
+
def link(self, target_desc, objects,
|
651 |
+
output_filename, output_dir=None, libraries=None,
|
652 |
+
library_dirs=None, runtime_library_dirs=None,
|
653 |
+
export_symbols=None, debug=0, extra_preargs=None,
|
654 |
+
extra_postargs=None, build_temp=None, target_lang=None):
|
655 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
656 |
+
libraries, library_dirs, runtime_library_dirs = \
|
657 |
+
self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
|
658 |
+
|
659 |
+
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
|
660 |
+
libraries)
|
661 |
+
if is_string(output_dir):
|
662 |
+
output_filename = os.path.join(output_dir, output_filename)
|
663 |
+
elif output_dir is not None:
|
664 |
+
raise TypeError("'output_dir' must be a string or None")
|
665 |
+
|
666 |
+
if self._need_link(objects, output_filename):
|
667 |
+
if self.library_switch[-1]==' ':
|
668 |
+
o_args = [self.library_switch.strip(), output_filename]
|
669 |
+
else:
|
670 |
+
o_args = [self.library_switch.strip()+output_filename]
|
671 |
+
|
672 |
+
if is_string(self.objects):
|
673 |
+
ld_args = objects + [self.objects]
|
674 |
+
else:
|
675 |
+
ld_args = objects + self.objects
|
676 |
+
ld_args = ld_args + lib_opts + o_args
|
677 |
+
if debug:
|
678 |
+
ld_args[:0] = ['-g']
|
679 |
+
if extra_preargs:
|
680 |
+
ld_args[:0] = extra_preargs
|
681 |
+
if extra_postargs:
|
682 |
+
ld_args.extend(extra_postargs)
|
683 |
+
self.mkpath(os.path.dirname(output_filename))
|
684 |
+
if target_desc == CCompiler.EXECUTABLE:
|
685 |
+
linker = self.linker_exe[:]
|
686 |
+
else:
|
687 |
+
linker = self.linker_so[:]
|
688 |
+
command = linker + ld_args
|
689 |
+
try:
|
690 |
+
self.spawn(command)
|
691 |
+
except DistutilsExecError as e:
|
692 |
+
msg = str(e)
|
693 |
+
raise LinkError(msg) from None
|
694 |
+
else:
|
695 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
696 |
+
|
697 |
+
def _environment_hook(self, name, hook_name):
|
698 |
+
if hook_name is None:
|
699 |
+
return None
|
700 |
+
if is_string(hook_name):
|
701 |
+
if hook_name.startswith('self.'):
|
702 |
+
hook_name = hook_name[5:]
|
703 |
+
hook = getattr(self, hook_name)
|
704 |
+
return hook()
|
705 |
+
elif hook_name.startswith('exe.'):
|
706 |
+
hook_name = hook_name[4:]
|
707 |
+
var = self.executables[hook_name]
|
708 |
+
if var:
|
709 |
+
return var[0]
|
710 |
+
else:
|
711 |
+
return None
|
712 |
+
elif hook_name.startswith('flags.'):
|
713 |
+
hook_name = hook_name[6:]
|
714 |
+
hook = getattr(self, 'get_flags_' + hook_name)
|
715 |
+
return hook()
|
716 |
+
else:
|
717 |
+
return hook_name()
|
718 |
+
|
719 |
+
def can_ccompiler_link(self, ccompiler):
|
720 |
+
"""
|
721 |
+
Check if the given C compiler can link objects produced by
|
722 |
+
this compiler.
|
723 |
+
"""
|
724 |
+
return True
|
725 |
+
|
726 |
+
def wrap_unlinkable_objects(self, objects, output_dir, extra_dll_dir):
|
727 |
+
"""
|
728 |
+
Convert a set of object files that are not compatible with the default
|
729 |
+
linker, to a file that is compatible.
|
730 |
+
|
731 |
+
Parameters
|
732 |
+
----------
|
733 |
+
objects : list
|
734 |
+
List of object files to include.
|
735 |
+
output_dir : str
|
736 |
+
Output directory to place generated object files.
|
737 |
+
extra_dll_dir : str
|
738 |
+
Output directory to place extra DLL files that need to be
|
739 |
+
included on Windows.
|
740 |
+
|
741 |
+
Returns
|
742 |
+
-------
|
743 |
+
converted_objects : list of str
|
744 |
+
List of converted object files.
|
745 |
+
Note that the number of output files is not necessarily
|
746 |
+
the same as inputs.
|
747 |
+
|
748 |
+
"""
|
749 |
+
raise NotImplementedError()
|
750 |
+
|
751 |
+
## class FCompiler
|
752 |
+
|
753 |
+
_default_compilers = (
|
754 |
+
# sys.platform mappings
|
755 |
+
('win32', ('gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95',
|
756 |
+
'intelvem', 'intelem', 'flang')),
|
757 |
+
('cygwin.*', ('gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95')),
|
758 |
+
('linux.*', ('arm', 'gnu95', 'intel', 'lahey', 'pg', 'nv', 'absoft', 'nag',
|
759 |
+
'vast', 'compaq', 'intele', 'intelem', 'gnu', 'g95',
|
760 |
+
'pathf95', 'nagfor', 'fujitsu')),
|
761 |
+
('darwin.*', ('gnu95', 'nag', 'nagfor', 'absoft', 'ibm', 'intel', 'gnu',
|
762 |
+
'g95', 'pg')),
|
763 |
+
('sunos.*', ('sun', 'gnu', 'gnu95', 'g95')),
|
764 |
+
('irix.*', ('mips', 'gnu', 'gnu95',)),
|
765 |
+
('aix.*', ('ibm', 'gnu', 'gnu95',)),
|
766 |
+
# os.name mappings
|
767 |
+
('posix', ('gnu', 'gnu95',)),
|
768 |
+
('nt', ('gnu', 'gnu95',)),
|
769 |
+
('mac', ('gnu95', 'gnu', 'pg')),
|
770 |
+
)
|
771 |
+
|
772 |
+
fcompiler_class = None
|
773 |
+
fcompiler_aliases = None
|
774 |
+
|
775 |
+
def load_all_fcompiler_classes():
|
776 |
+
"""Cache all the FCompiler classes found in modules in the
|
777 |
+
numpy.distutils.fcompiler package.
|
778 |
+
"""
|
779 |
+
from glob import glob
|
780 |
+
global fcompiler_class, fcompiler_aliases
|
781 |
+
if fcompiler_class is not None:
|
782 |
+
return
|
783 |
+
pys = os.path.join(os.path.dirname(__file__), '*.py')
|
784 |
+
fcompiler_class = {}
|
785 |
+
fcompiler_aliases = {}
|
786 |
+
for fname in glob(pys):
|
787 |
+
module_name, ext = os.path.splitext(os.path.basename(fname))
|
788 |
+
module_name = 'numpy.distutils.fcompiler.' + module_name
|
789 |
+
__import__ (module_name)
|
790 |
+
module = sys.modules[module_name]
|
791 |
+
if hasattr(module, 'compilers'):
|
792 |
+
for cname in module.compilers:
|
793 |
+
klass = getattr(module, cname)
|
794 |
+
desc = (klass.compiler_type, klass, klass.description)
|
795 |
+
fcompiler_class[klass.compiler_type] = desc
|
796 |
+
for alias in klass.compiler_aliases:
|
797 |
+
if alias in fcompiler_aliases:
|
798 |
+
raise ValueError("alias %r defined for both %s and %s"
|
799 |
+
% (alias, klass.__name__,
|
800 |
+
fcompiler_aliases[alias][1].__name__))
|
801 |
+
fcompiler_aliases[alias] = desc
|
802 |
+
|
803 |
+
def _find_existing_fcompiler(compiler_types,
|
804 |
+
osname=None, platform=None,
|
805 |
+
requiref90=False,
|
806 |
+
c_compiler=None):
|
807 |
+
from numpy.distutils.core import get_distribution
|
808 |
+
dist = get_distribution(always=True)
|
809 |
+
for compiler_type in compiler_types:
|
810 |
+
v = None
|
811 |
+
try:
|
812 |
+
c = new_fcompiler(plat=platform, compiler=compiler_type,
|
813 |
+
c_compiler=c_compiler)
|
814 |
+
c.customize(dist)
|
815 |
+
v = c.get_version()
|
816 |
+
if requiref90 and c.compiler_f90 is None:
|
817 |
+
v = None
|
818 |
+
new_compiler = c.suggested_f90_compiler
|
819 |
+
if new_compiler:
|
820 |
+
log.warn('Trying %r compiler as suggested by %r '
|
821 |
+
'compiler for f90 support.' % (compiler_type,
|
822 |
+
new_compiler))
|
823 |
+
c = new_fcompiler(plat=platform, compiler=new_compiler,
|
824 |
+
c_compiler=c_compiler)
|
825 |
+
c.customize(dist)
|
826 |
+
v = c.get_version()
|
827 |
+
if v is not None:
|
828 |
+
compiler_type = new_compiler
|
829 |
+
if requiref90 and c.compiler_f90 is None:
|
830 |
+
raise ValueError('%s does not support compiling f90 codes, '
|
831 |
+
'skipping.' % (c.__class__.__name__))
|
832 |
+
except DistutilsModuleError:
|
833 |
+
log.debug("_find_existing_fcompiler: compiler_type='%s' raised DistutilsModuleError", compiler_type)
|
834 |
+
except CompilerNotFound:
|
835 |
+
log.debug("_find_existing_fcompiler: compiler_type='%s' not found", compiler_type)
|
836 |
+
if v is not None:
|
837 |
+
return compiler_type
|
838 |
+
return None
|
839 |
+
|
840 |
+
def available_fcompilers_for_platform(osname=None, platform=None):
|
841 |
+
if osname is None:
|
842 |
+
osname = os.name
|
843 |
+
if platform is None:
|
844 |
+
platform = sys.platform
|
845 |
+
matching_compiler_types = []
|
846 |
+
for pattern, compiler_type in _default_compilers:
|
847 |
+
if re.match(pattern, platform) or re.match(pattern, osname):
|
848 |
+
for ct in compiler_type:
|
849 |
+
if ct not in matching_compiler_types:
|
850 |
+
matching_compiler_types.append(ct)
|
851 |
+
if not matching_compiler_types:
|
852 |
+
matching_compiler_types.append('gnu')
|
853 |
+
return matching_compiler_types
|
854 |
+
|
855 |
+
def get_default_fcompiler(osname=None, platform=None, requiref90=False,
|
856 |
+
c_compiler=None):
|
857 |
+
"""Determine the default Fortran compiler to use for the given
|
858 |
+
platform."""
|
859 |
+
matching_compiler_types = available_fcompilers_for_platform(osname,
|
860 |
+
platform)
|
861 |
+
log.info("get_default_fcompiler: matching types: '%s'",
|
862 |
+
matching_compiler_types)
|
863 |
+
compiler_type = _find_existing_fcompiler(matching_compiler_types,
|
864 |
+
osname=osname,
|
865 |
+
platform=platform,
|
866 |
+
requiref90=requiref90,
|
867 |
+
c_compiler=c_compiler)
|
868 |
+
return compiler_type
|
869 |
+
|
870 |
+
# Flag to avoid rechecking for Fortran compiler every time
|
871 |
+
failed_fcompilers = set()
|
872 |
+
|
873 |
+
def new_fcompiler(plat=None,
|
874 |
+
compiler=None,
|
875 |
+
verbose=0,
|
876 |
+
dry_run=0,
|
877 |
+
force=0,
|
878 |
+
requiref90=False,
|
879 |
+
c_compiler = None):
|
880 |
+
"""Generate an instance of some FCompiler subclass for the supplied
|
881 |
+
platform/compiler combination.
|
882 |
+
"""
|
883 |
+
global failed_fcompilers
|
884 |
+
fcompiler_key = (plat, compiler)
|
885 |
+
if fcompiler_key in failed_fcompilers:
|
886 |
+
return None
|
887 |
+
|
888 |
+
load_all_fcompiler_classes()
|
889 |
+
if plat is None:
|
890 |
+
plat = os.name
|
891 |
+
if compiler is None:
|
892 |
+
compiler = get_default_fcompiler(plat, requiref90=requiref90,
|
893 |
+
c_compiler=c_compiler)
|
894 |
+
if compiler in fcompiler_class:
|
895 |
+
module_name, klass, long_description = fcompiler_class[compiler]
|
896 |
+
elif compiler in fcompiler_aliases:
|
897 |
+
module_name, klass, long_description = fcompiler_aliases[compiler]
|
898 |
+
else:
|
899 |
+
msg = "don't know how to compile Fortran code on platform '%s'" % plat
|
900 |
+
if compiler is not None:
|
901 |
+
msg = msg + " with '%s' compiler." % compiler
|
902 |
+
msg = msg + " Supported compilers are: %s)" \
|
903 |
+
% (','.join(fcompiler_class.keys()))
|
904 |
+
log.warn(msg)
|
905 |
+
failed_fcompilers.add(fcompiler_key)
|
906 |
+
return None
|
907 |
+
|
908 |
+
compiler = klass(verbose=verbose, dry_run=dry_run, force=force)
|
909 |
+
compiler.c_compiler = c_compiler
|
910 |
+
return compiler
|
911 |
+
|
912 |
+
def show_fcompilers(dist=None):
|
913 |
+
"""Print list of available compilers (used by the "--help-fcompiler"
|
914 |
+
option to "config_fc").
|
915 |
+
"""
|
916 |
+
if dist is None:
|
917 |
+
from distutils.dist import Distribution
|
918 |
+
from numpy.distutils.command.config_compiler import config_fc
|
919 |
+
dist = Distribution()
|
920 |
+
dist.script_name = os.path.basename(sys.argv[0])
|
921 |
+
dist.script_args = ['config_fc'] + sys.argv[1:]
|
922 |
+
try:
|
923 |
+
dist.script_args.remove('--help-fcompiler')
|
924 |
+
except ValueError:
|
925 |
+
pass
|
926 |
+
dist.cmdclass['config_fc'] = config_fc
|
927 |
+
dist.parse_config_files()
|
928 |
+
dist.parse_command_line()
|
929 |
+
compilers = []
|
930 |
+
compilers_na = []
|
931 |
+
compilers_ni = []
|
932 |
+
if not fcompiler_class:
|
933 |
+
load_all_fcompiler_classes()
|
934 |
+
platform_compilers = available_fcompilers_for_platform()
|
935 |
+
for compiler in platform_compilers:
|
936 |
+
v = None
|
937 |
+
log.set_verbosity(-2)
|
938 |
+
try:
|
939 |
+
c = new_fcompiler(compiler=compiler, verbose=dist.verbose)
|
940 |
+
c.customize(dist)
|
941 |
+
v = c.get_version()
|
942 |
+
except (DistutilsModuleError, CompilerNotFound) as e:
|
943 |
+
log.debug("show_fcompilers: %s not found" % (compiler,))
|
944 |
+
log.debug(repr(e))
|
945 |
+
|
946 |
+
if v is None:
|
947 |
+
compilers_na.append(("fcompiler="+compiler, None,
|
948 |
+
fcompiler_class[compiler][2]))
|
949 |
+
else:
|
950 |
+
c.dump_properties()
|
951 |
+
compilers.append(("fcompiler="+compiler, None,
|
952 |
+
fcompiler_class[compiler][2] + ' (%s)' % v))
|
953 |
+
|
954 |
+
compilers_ni = list(set(fcompiler_class.keys()) - set(platform_compilers))
|
955 |
+
compilers_ni = [("fcompiler="+fc, None, fcompiler_class[fc][2])
|
956 |
+
for fc in compilers_ni]
|
957 |
+
|
958 |
+
compilers.sort()
|
959 |
+
compilers_na.sort()
|
960 |
+
compilers_ni.sort()
|
961 |
+
pretty_printer = FancyGetopt(compilers)
|
962 |
+
pretty_printer.print_help("Fortran compilers found:")
|
963 |
+
pretty_printer = FancyGetopt(compilers_na)
|
964 |
+
pretty_printer.print_help("Compilers available for this "
|
965 |
+
"platform, but not found:")
|
966 |
+
if compilers_ni:
|
967 |
+
pretty_printer = FancyGetopt(compilers_ni)
|
968 |
+
pretty_printer.print_help("Compilers not available on this platform:")
|
969 |
+
print("For compiler details, run 'config_fc --verbose' setup command.")
|
970 |
+
|
971 |
+
|
972 |
+
def dummy_fortran_file():
|
973 |
+
fo, name = make_temp_file(suffix='.f')
|
974 |
+
fo.write(" subroutine dummy()\n end\n")
|
975 |
+
fo.close()
|
976 |
+
return name[:-2]
|
977 |
+
|
978 |
+
|
979 |
+
_has_f_header = re.compile(r'-\*-\s*fortran\s*-\*-', re.I).search
|
980 |
+
_has_f90_header = re.compile(r'-\*-\s*f90\s*-\*-', re.I).search
|
981 |
+
_has_fix_header = re.compile(r'-\*-\s*fix\s*-\*-', re.I).search
|
982 |
+
_free_f90_start = re.compile(r'[^c*!]\s*[^\s\d\t]', re.I).match
|
983 |
+
|
984 |
+
def is_free_format(file):
|
985 |
+
"""Check if file is in free format Fortran."""
|
986 |
+
# f90 allows both fixed and free format, assuming fixed unless
|
987 |
+
# signs of free format are detected.
|
988 |
+
result = 0
|
989 |
+
with open(file, encoding='latin1') as f:
|
990 |
+
line = f.readline()
|
991 |
+
n = 10000 # the number of non-comment lines to scan for hints
|
992 |
+
if _has_f_header(line) or _has_fix_header(line):
|
993 |
+
n = 0
|
994 |
+
elif _has_f90_header(line):
|
995 |
+
n = 0
|
996 |
+
result = 1
|
997 |
+
while n>0 and line:
|
998 |
+
line = line.rstrip()
|
999 |
+
if line and line[0]!='!':
|
1000 |
+
n -= 1
|
1001 |
+
if (line[0]!='\t' and _free_f90_start(line[:5])) or line[-1:]=='&':
|
1002 |
+
result = 1
|
1003 |
+
break
|
1004 |
+
line = f.readline()
|
1005 |
+
return result
|
1006 |
+
|
1007 |
+
def has_f90_header(src):
|
1008 |
+
with open(src, encoding='latin1') as f:
|
1009 |
+
line = f.readline()
|
1010 |
+
return _has_f90_header(line) or _has_fix_header(line)
|
1011 |
+
|
1012 |
+
_f77flags_re = re.compile(r'(c|)f77flags\s*\(\s*(?P<fcname>\w+)\s*\)\s*=\s*(?P<fflags>.*)', re.I)
|
1013 |
+
def get_f77flags(src):
|
1014 |
+
"""
|
1015 |
+
Search the first 20 lines of fortran 77 code for line pattern
|
1016 |
+
`CF77FLAGS(<fcompiler type>)=<f77 flags>`
|
1017 |
+
Return a dictionary {<fcompiler type>:<f77 flags>}.
|
1018 |
+
"""
|
1019 |
+
flags = {}
|
1020 |
+
with open(src, encoding='latin1') as f:
|
1021 |
+
i = 0
|
1022 |
+
for line in f:
|
1023 |
+
i += 1
|
1024 |
+
if i>20: break
|
1025 |
+
m = _f77flags_re.match(line)
|
1026 |
+
if not m: continue
|
1027 |
+
fcname = m.group('fcname').strip()
|
1028 |
+
fflags = m.group('fflags').strip()
|
1029 |
+
flags[fcname] = split_quoted(fflags)
|
1030 |
+
return flags
|
1031 |
+
|
1032 |
+
# TODO: implement get_f90flags and use it in _compile similarly to get_f77flags
|
1033 |
+
|
1034 |
+
if __name__ == '__main__':
|
1035 |
+
show_fcompilers()
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (28.6 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/arm.cpython-310.pyc
ADDED
Binary file (2.75 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/g95.cpython-310.pyc
ADDED
Binary file (1.52 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/gnu.cpython-310.pyc
ADDED
Binary file (13 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/hpux.cpython-310.pyc
ADDED
Binary file (1.82 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/intel.cpython-310.pyc
ADDED
Binary file (6.44 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/nag.cpython-310.pyc
ADDED
Binary file (3.18 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/none.cpython-310.pyc
ADDED
Binary file (1.01 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/sun.cpython-310.pyc
ADDED
Binary file (2.07 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/vast.cpython-310.pyc
ADDED
Binary file (1.87 kB). View file
|
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/absoft.py
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# Absoft Corporation ceased operations on 12/31/2022.
|
3 |
+
# Thus, all links to <http://www.absoft.com> are invalid.
|
4 |
+
|
5 |
+
# Notes:
|
6 |
+
# - when using -g77 then use -DUNDERSCORE_G77 to compile f2py
|
7 |
+
# generated extension modules (works for f2py v2.45.241_1936 and up)
|
8 |
+
import os
|
9 |
+
|
10 |
+
from numpy.distutils.cpuinfo import cpu
|
11 |
+
from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file
|
12 |
+
from numpy.distutils.misc_util import cyg2win32
|
13 |
+
|
14 |
+
compilers = ['AbsoftFCompiler']
|
15 |
+
|
16 |
+
class AbsoftFCompiler(FCompiler):
|
17 |
+
|
18 |
+
compiler_type = 'absoft'
|
19 |
+
description = 'Absoft Corp Fortran Compiler'
|
20 |
+
#version_pattern = r'FORTRAN 77 Compiler (?P<version>[^\s*,]*).*?Absoft Corp'
|
21 |
+
version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version|Copyright Absoft Corporation.*?Version))'+\
|
22 |
+
r' (?P<version>[^\s*,]*)(.*?Absoft Corp|)'
|
23 |
+
|
24 |
+
# on windows: f90 -V -c dummy.f
|
25 |
+
# f90: Copyright Absoft Corporation 1994-1998 mV2; Cray Research, Inc. 1994-1996 CF90 (2.x.x.x f36t87) Version 2.3 Wed Apr 19, 2006 13:05:16
|
26 |
+
|
27 |
+
# samt5735(8)$ f90 -V -c dummy.f
|
28 |
+
# f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0
|
29 |
+
# Note that fink installs g77 as f77, so need to use f90 for detection.
|
30 |
+
|
31 |
+
executables = {
|
32 |
+
'version_cmd' : None, # set by update_executables
|
33 |
+
'compiler_f77' : ["f77"],
|
34 |
+
'compiler_fix' : ["f90"],
|
35 |
+
'compiler_f90' : ["f90"],
|
36 |
+
'linker_so' : ["<F90>"],
|
37 |
+
'archiver' : ["ar", "-cr"],
|
38 |
+
'ranlib' : ["ranlib"]
|
39 |
+
}
|
40 |
+
|
41 |
+
if os.name=='nt':
|
42 |
+
library_switch = '/out:' #No space after /out:!
|
43 |
+
|
44 |
+
module_dir_switch = None
|
45 |
+
module_include_switch = '-p'
|
46 |
+
|
47 |
+
def update_executables(self):
|
48 |
+
f = cyg2win32(dummy_fortran_file())
|
49 |
+
self.executables['version_cmd'] = ['<F90>', '-V', '-c',
|
50 |
+
f+'.f', '-o', f+'.o']
|
51 |
+
|
52 |
+
def get_flags_linker_so(self):
|
53 |
+
if os.name=='nt':
|
54 |
+
opt = ['/dll']
|
55 |
+
# The "-K shared" switches are being left in for pre-9.0 versions
|
56 |
+
# of Absoft though I don't think versions earlier than 9 can
|
57 |
+
# actually be used to build shared libraries. In fact, version
|
58 |
+
# 8 of Absoft doesn't recognize "-K shared" and will fail.
|
59 |
+
elif self.get_version() >= '9.0':
|
60 |
+
opt = ['-shared']
|
61 |
+
else:
|
62 |
+
opt = ["-K", "shared"]
|
63 |
+
return opt
|
64 |
+
|
65 |
+
def library_dir_option(self, dir):
|
66 |
+
if os.name=='nt':
|
67 |
+
return ['-link', '/PATH:%s' % (dir)]
|
68 |
+
return "-L" + dir
|
69 |
+
|
70 |
+
def library_option(self, lib):
|
71 |
+
if os.name=='nt':
|
72 |
+
return '%s.lib' % (lib)
|
73 |
+
return "-l" + lib
|
74 |
+
|
75 |
+
def get_library_dirs(self):
|
76 |
+
opt = FCompiler.get_library_dirs(self)
|
77 |
+
d = os.environ.get('ABSOFT')
|
78 |
+
if d:
|
79 |
+
if self.get_version() >= '10.0':
|
80 |
+
# use shared libraries, the static libraries were not compiled -fPIC
|
81 |
+
prefix = 'sh'
|
82 |
+
else:
|
83 |
+
prefix = ''
|
84 |
+
if cpu.is_64bit():
|
85 |
+
suffix = '64'
|
86 |
+
else:
|
87 |
+
suffix = ''
|
88 |
+
opt.append(os.path.join(d, '%slib%s' % (prefix, suffix)))
|
89 |
+
return opt
|
90 |
+
|
91 |
+
def get_libraries(self):
|
92 |
+
opt = FCompiler.get_libraries(self)
|
93 |
+
if self.get_version() >= '11.0':
|
94 |
+
opt.extend(['af90math', 'afio', 'af77math', 'amisc'])
|
95 |
+
elif self.get_version() >= '10.0':
|
96 |
+
opt.extend(['af90math', 'afio', 'af77math', 'U77'])
|
97 |
+
elif self.get_version() >= '8.0':
|
98 |
+
opt.extend(['f90math', 'fio', 'f77math', 'U77'])
|
99 |
+
else:
|
100 |
+
opt.extend(['fio', 'f90math', 'fmath', 'U77'])
|
101 |
+
if os.name =='nt':
|
102 |
+
opt.append('COMDLG32')
|
103 |
+
return opt
|
104 |
+
|
105 |
+
def get_flags(self):
|
106 |
+
opt = FCompiler.get_flags(self)
|
107 |
+
if os.name != 'nt':
|
108 |
+
opt.extend(['-s'])
|
109 |
+
if self.get_version():
|
110 |
+
if self.get_version()>='8.2':
|
111 |
+
opt.append('-fpic')
|
112 |
+
return opt
|
113 |
+
|
114 |
+
def get_flags_f77(self):
|
115 |
+
opt = FCompiler.get_flags_f77(self)
|
116 |
+
opt.extend(['-N22', '-N90', '-N110'])
|
117 |
+
v = self.get_version()
|
118 |
+
if os.name == 'nt':
|
119 |
+
if v and v>='8.0':
|
120 |
+
opt.extend(['-f', '-N15'])
|
121 |
+
else:
|
122 |
+
opt.append('-f')
|
123 |
+
if v:
|
124 |
+
if v<='4.6':
|
125 |
+
opt.append('-B108')
|
126 |
+
else:
|
127 |
+
# Though -N15 is undocumented, it works with
|
128 |
+
# Absoft 8.0 on Linux
|
129 |
+
opt.append('-N15')
|
130 |
+
return opt
|
131 |
+
|
132 |
+
def get_flags_f90(self):
|
133 |
+
opt = FCompiler.get_flags_f90(self)
|
134 |
+
opt.extend(["-YCFRL=1", "-YCOM_NAMES=LCS", "-YCOM_PFX", "-YEXT_PFX",
|
135 |
+
"-YCOM_SFX=_", "-YEXT_SFX=_", "-YEXT_NAMES=LCS"])
|
136 |
+
if self.get_version():
|
137 |
+
if self.get_version()>'4.6':
|
138 |
+
opt.extend(["-YDEALLOC=ALL"])
|
139 |
+
return opt
|
140 |
+
|
141 |
+
def get_flags_fix(self):
|
142 |
+
opt = FCompiler.get_flags_fix(self)
|
143 |
+
opt.extend(["-YCFRL=1", "-YCOM_NAMES=LCS", "-YCOM_PFX", "-YEXT_PFX",
|
144 |
+
"-YCOM_SFX=_", "-YEXT_SFX=_", "-YEXT_NAMES=LCS"])
|
145 |
+
opt.extend(["-f", "fixed"])
|
146 |
+
return opt
|
147 |
+
|
148 |
+
def get_flags_opt(self):
|
149 |
+
opt = ['-O']
|
150 |
+
return opt
|
151 |
+
|
152 |
+
if __name__ == '__main__':
|
153 |
+
from distutils import log
|
154 |
+
log.set_verbosity(2)
|
155 |
+
from numpy.distutils import customized_fcompiler
|
156 |
+
print(customized_fcompiler(compiler='absoft').get_version())
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/arm.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
+
from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file
|
4 |
+
from sys import platform
|
5 |
+
from os.path import join, dirname, normpath
|
6 |
+
|
7 |
+
compilers = ['ArmFlangCompiler']
|
8 |
+
|
9 |
+
import functools
|
10 |
+
|
11 |
+
class ArmFlangCompiler(FCompiler):
|
12 |
+
compiler_type = 'arm'
|
13 |
+
description = 'Arm Compiler'
|
14 |
+
version_pattern = r'\s*Arm.*version (?P<version>[\d.-]+).*'
|
15 |
+
|
16 |
+
ar_exe = 'lib.exe'
|
17 |
+
possible_executables = ['armflang']
|
18 |
+
|
19 |
+
executables = {
|
20 |
+
'version_cmd': ["", "--version"],
|
21 |
+
'compiler_f77': ["armflang", "-fPIC"],
|
22 |
+
'compiler_fix': ["armflang", "-fPIC", "-ffixed-form"],
|
23 |
+
'compiler_f90': ["armflang", "-fPIC"],
|
24 |
+
'linker_so': ["armflang", "-fPIC", "-shared"],
|
25 |
+
'archiver': ["ar", "-cr"],
|
26 |
+
'ranlib': None
|
27 |
+
}
|
28 |
+
|
29 |
+
pic_flags = ["-fPIC", "-DPIC"]
|
30 |
+
c_compiler = 'arm'
|
31 |
+
module_dir_switch = '-module ' # Don't remove ending space!
|
32 |
+
|
33 |
+
def get_libraries(self):
|
34 |
+
opt = FCompiler.get_libraries(self)
|
35 |
+
opt.extend(['flang', 'flangrti', 'ompstub'])
|
36 |
+
return opt
|
37 |
+
|
38 |
+
@functools.lru_cache(maxsize=128)
|
39 |
+
def get_library_dirs(self):
|
40 |
+
"""List of compiler library directories."""
|
41 |
+
opt = FCompiler.get_library_dirs(self)
|
42 |
+
flang_dir = dirname(self.executables['compiler_f77'][0])
|
43 |
+
opt.append(normpath(join(flang_dir, '..', 'lib')))
|
44 |
+
|
45 |
+
return opt
|
46 |
+
|
47 |
+
def get_flags(self):
|
48 |
+
return []
|
49 |
+
|
50 |
+
def get_flags_free(self):
|
51 |
+
return []
|
52 |
+
|
53 |
+
def get_flags_debug(self):
|
54 |
+
return ['-g']
|
55 |
+
|
56 |
+
def get_flags_opt(self):
|
57 |
+
return ['-O3']
|
58 |
+
|
59 |
+
def get_flags_arch(self):
|
60 |
+
return []
|
61 |
+
|
62 |
+
def runtime_library_dir_option(self, dir):
|
63 |
+
return '-Wl,-rpath=%s' % dir
|
64 |
+
|
65 |
+
|
66 |
+
if __name__ == '__main__':
|
67 |
+
from distutils import log
|
68 |
+
log.set_verbosity(2)
|
69 |
+
from numpy.distutils import customized_fcompiler
|
70 |
+
print(customized_fcompiler(compiler='armflang').get_version())
|
71 |
+
|
venv/lib/python3.10/site-packages/numpy/distutils/fcompiler/compaq.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
#http://www.compaq.com/fortran/docs/
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
|
6 |
+
from numpy.distutils.fcompiler import FCompiler
|
7 |
+
from distutils.errors import DistutilsPlatformError
|
8 |
+
|
9 |
+
compilers = ['CompaqFCompiler']
|
10 |
+
if os.name != 'posix' or sys.platform[:6] == 'cygwin' :
|
11 |
+
# Otherwise we'd get a false positive on posix systems with
|
12 |
+
# case-insensitive filesystems (like darwin), because we'll pick
|
13 |
+
# up /bin/df
|
14 |
+
compilers.append('CompaqVisualFCompiler')
|
15 |
+
|
16 |
+
class CompaqFCompiler(FCompiler):
|
17 |
+
|
18 |
+
compiler_type = 'compaq'
|
19 |
+
description = 'Compaq Fortran Compiler'
|
20 |
+
version_pattern = r'Compaq Fortran (?P<version>[^\s]*).*'
|
21 |
+
|
22 |
+
if sys.platform[:5]=='linux':
|
23 |
+
fc_exe = 'fort'
|
24 |
+
else:
|
25 |
+
fc_exe = 'f90'
|
26 |
+
|
27 |
+
executables = {
|
28 |
+
'version_cmd' : ['<F90>', "-version"],
|
29 |
+
'compiler_f77' : [fc_exe, "-f77rtl", "-fixed"],
|
30 |
+
'compiler_fix' : [fc_exe, "-fixed"],
|
31 |
+
'compiler_f90' : [fc_exe],
|
32 |
+
'linker_so' : ['<F90>'],
|
33 |
+
'archiver' : ["ar", "-cr"],
|
34 |
+
'ranlib' : ["ranlib"]
|
35 |
+
}
|
36 |
+
|
37 |
+
module_dir_switch = '-module ' # not tested
|
38 |
+
module_include_switch = '-I'
|
39 |
+
|
40 |
+
def get_flags(self):
|
41 |
+
return ['-assume no2underscore', '-nomixed_str_len_arg']
|
42 |
+
def get_flags_debug(self):
|
43 |
+
return ['-g', '-check bounds']
|
44 |
+
def get_flags_opt(self):
|
45 |
+
return ['-O4', '-align dcommons', '-assume bigarrays',
|
46 |
+
'-assume nozsize', '-math_library fast']
|
47 |
+
def get_flags_arch(self):
|
48 |
+
return ['-arch host', '-tune host']
|
49 |
+
def get_flags_linker_so(self):
|
50 |
+
if sys.platform[:5]=='linux':
|
51 |
+
return ['-shared']
|
52 |
+
return ['-shared', '-Wl,-expect_unresolved,*']
|
53 |
+
|
54 |
+
class CompaqVisualFCompiler(FCompiler):
|
55 |
+
|
56 |
+
compiler_type = 'compaqv'
|
57 |
+
description = 'DIGITAL or Compaq Visual Fortran Compiler'
|
58 |
+
version_pattern = (r'(DIGITAL|Compaq) Visual Fortran Optimizing Compiler'
|
59 |
+
r' Version (?P<version>[^\s]*).*')
|
60 |
+
|
61 |
+
compile_switch = '/compile_only'
|
62 |
+
object_switch = '/object:'
|
63 |
+
library_switch = '/OUT:' #No space after /OUT:!
|
64 |
+
|
65 |
+
static_lib_extension = ".lib"
|
66 |
+
static_lib_format = "%s%s"
|
67 |
+
module_dir_switch = '/module:'
|
68 |
+
module_include_switch = '/I'
|
69 |
+
|
70 |
+
ar_exe = 'lib.exe'
|
71 |
+
fc_exe = 'DF'
|
72 |
+
|
73 |
+
if sys.platform=='win32':
|
74 |
+
from numpy.distutils.msvccompiler import MSVCCompiler
|
75 |
+
|
76 |
+
try:
|
77 |
+
m = MSVCCompiler()
|
78 |
+
m.initialize()
|
79 |
+
ar_exe = m.lib
|
80 |
+
except DistutilsPlatformError:
|
81 |
+
pass
|
82 |
+
except AttributeError as e:
|
83 |
+
if '_MSVCCompiler__root' in str(e):
|
84 |
+
print('Ignoring "%s" (I think it is msvccompiler.py bug)' % (e))
|
85 |
+
else:
|
86 |
+
raise
|
87 |
+
except OSError as e:
|
88 |
+
if not "vcvarsall.bat" in str(e):
|
89 |
+
print("Unexpected OSError in", __file__)
|
90 |
+
raise
|
91 |
+
except ValueError as e:
|
92 |
+
if not "'path'" in str(e):
|
93 |
+
print("Unexpected ValueError in", __file__)
|
94 |
+
raise
|
95 |
+
|
96 |
+
executables = {
|
97 |
+
'version_cmd' : ['<F90>', "/what"],
|
98 |
+
'compiler_f77' : [fc_exe, "/f77rtl", "/fixed"],
|
99 |
+
'compiler_fix' : [fc_exe, "/fixed"],
|
100 |
+
'compiler_f90' : [fc_exe],
|
101 |
+
'linker_so' : ['<F90>'],
|
102 |
+
'archiver' : [ar_exe, "/OUT:"],
|
103 |
+
'ranlib' : None
|
104 |
+
}
|
105 |
+
|
106 |
+
def get_flags(self):
|
107 |
+
return ['/nologo', '/MD', '/WX', '/iface=(cref,nomixed_str_len_arg)',
|
108 |
+
'/names:lowercase', '/assume:underscore']
|
109 |
+
def get_flags_opt(self):
|
110 |
+
return ['/Ox', '/fast', '/optimize:5', '/unroll:0', '/math_library:fast']
|
111 |
+
def get_flags_arch(self):
|
112 |
+
return ['/threads']
|
113 |
+
def get_flags_debug(self):
|
114 |
+
return ['/debug']
|
115 |
+
|
116 |
+
if __name__ == '__main__':
|
117 |
+
from distutils import log
|
118 |
+
log.set_verbosity(2)
|
119 |
+
from numpy.distutils import customized_fcompiler
|
120 |
+
print(customized_fcompiler(compiler='compaq').get_version())
|