mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
7469868f65
Summary: Our BigSur mactest machines have python3 defaulting to some internal fbprojects python install. This is breaking our OSS builds. Let's change pick_python to avoid that install. Note, sys.stdout was changed to print because during my manual testing on Mac, sys.stdout did not actually print the value, despite the flush. Using print() did work. Reviewed By: quark-zju Differential Revision: D28101632 fbshipit-source-id: 2907d644b2baa8a53a9a2d7da176d33cd83dfbd5
62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2.
|
|
|
|
"""
|
|
Pick a Python that is more likely to be able to build with setup.py.
|
|
|
|
Arguments: Binary name (ex. python2, or python3).
|
|
Stdout: Full path to a system python, or the first argument of the input.
|
|
|
|
This script does not need to be executed using a system Python.
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def main(args):
|
|
dirs = os.environ.get("PATH").split(os.pathsep)
|
|
names = args or ["python3"]
|
|
for dir in dirs:
|
|
for name in names:
|
|
path = os.path.join(dir, name)
|
|
if does_python_look_good(path):
|
|
print(path)
|
|
return
|
|
|
|
# Fallback
|
|
sys.stdout.write(names[0])
|
|
|
|
|
|
def does_python_look_good(path):
|
|
if not os.path.isfile(path):
|
|
return False
|
|
try:
|
|
cflags = subprocess.check_output(
|
|
[path, "-c", "import sysconfig;print(sysconfig.get_config_var('CFLAGS'))"]
|
|
)
|
|
if b"-nostdinc" in cflags.split():
|
|
sys.stderr.write("%s: ignored, lack of C stdlib\n" % path)
|
|
return False
|
|
realpath = subprocess.check_output(
|
|
[path, "-c", "import sys;print(sys.executable)"]
|
|
)
|
|
if b"fbprojects" in realpath:
|
|
sys.stderr.write(
|
|
"%s: ignored, avoid using the fb python for non-fb builds\n" % path
|
|
)
|
|
return False
|
|
return True
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
code = main(sys.argv[1:]) or 0
|
|
sys.stderr.flush()
|
|
sys.stdout.flush()
|
|
sys.exit(code)
|