-
Notifications
You must be signed in to change notification settings - Fork 5
/
defaults.py
52 lines (43 loc) · 1.51 KB
/
defaults.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from subprocess import CalledProcessError, check_output
from hatch_cython.config.platform import PlatformArgs
from hatch_cython.constants import POSIX_CORE
from hatch_cython.utils import aarch, plat
BREW = "brew"
def brew_path():
if plat() == "darwin":
# no user input - S603 is false positive
try:
proc = check_output([BREW, "--prefix"]) # noqa: S603
except (CalledProcessError, FileNotFoundError):
proc = None
dec = proc.decode().replace("\n", "") if proc else None
if dec and dec != "":
return dec
return "/opt/homebrew" if aarch() == "arm64" else "/usr/local"
def get_default_link():
base = [
PlatformArgs(arg="-L/usr/local/lib", platforms=POSIX_CORE, depends_path=True),
PlatformArgs(arg="-L/usr/local/opt", platforms=POSIX_CORE, depends_path=True),
]
brew = brew_path()
if brew:
base.extend(
[
PlatformArgs(arg=f"-L{brew}/opt", platforms=POSIX_CORE, depends_path=True),
PlatformArgs(arg=f"-L{brew}/lib", platforms=POSIX_CORE, depends_path=True),
]
)
return base
def get_default_compile():
base = [
PlatformArgs(arg="-O2"),
PlatformArgs(arg="-I/usr/local/include", platforms=POSIX_CORE, depends_path=True),
]
brew = brew_path()
if brew:
base.extend(
[
PlatformArgs(arg=f"-I{brew}/include", platforms=POSIX_CORE, depends_path=True),
]
)
return base