From fc5430591bbb5ee479d9e9bf8a1e737e34d9c9e2 Mon Sep 17 00:00:00 2001 From: risemeup1 <515586620@qq.com> Date: Tue, 6 Dec 2022 06:21:34 +0000 Subject: [PATCH 1/5] optimize setup.py --- paddle/scripts/paddle_build.sh | 15 +-------------- setup.py | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index 4e563496d3529..0ef06e0d18a7b 100755 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3468,20 +3468,7 @@ function run_setup(){ SYSTEM=`uname -s` if [ "$SYSTEM" == "Darwin" ]; then echo "Using python abi: $1" - if [ "$1" == "cp36-cp36m" ] || [ "$1" == "" ]; then - if [ -d "/Library/Frameworks/Python.framework/Versions/3.6" ]; then - export LD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.6/lib/ - export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/Library/Frameworks/Python.framework/Versions/3.6/lib/ - export PATH=/Library/Frameworks/Python.framework/Versions/3.6/bin/:${PATH} - #after changing "PYTHON_LIBRARY:FILEPATH" to "PYTHON_LIBRARY" ,we can use export - export PYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3 - export PYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m/ - export PYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6m.dylib - pip3.6 install --user -r ${PADDLE_ROOT}/python/requirements.txt - else - exit 1 - fi - elif [ "$1" == "cp37-cp37m" ]; then + if [ "$1" == "cp37-cp37m" ]; then if [ -d "/Library/Frameworks/Python.framework/Versions/3.7" ]; then export LD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.7/lib/ export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/Library/Frameworks/Python.framework/Versions/3.7/lib/ diff --git a/setup.py b/setup.py index 58458c5470740..9eaaca4d36242 100644 --- a/setup.py +++ b/setup.py @@ -275,7 +275,7 @@ def _mkdir_p(dir_str): try: os.makedirs(dir_str) except OSError as e: - raise RuntimeError("Failed to create folder build/") + raise RuntimeError("Failed to create build folder") def get_major(): @@ -583,9 +583,16 @@ def build_run(args, build_path, envrion_var): def build_steps(): print('------- Building start ------') - if not os.path.exists(TOP_DIR + '/build'): - _mkdir_p(TOP_DIR + '/build') - build_path = TOP_DIR + '/build' + build_dir=os.getenv("BUILD_DIR") + if build_dir is not None: + build_dir=TOP_DIR + '/'+build_dir + if not os.path.exists(build_dir): + _mkdir_p(build_dir) + else: + build_dir=TOP_DIR + '/build' + if not os.path.exists(build_dir): + _mkdir_p(build_dir) + build_path = build_dir # run cmake to generate native build files cmake_cache_file_path = os.path.join(build_path, "CMakeCache.txt") # if rerun_cmake is True,remove CMakeCache.txt and rerun camke @@ -1276,9 +1283,15 @@ def main(): # Execute the build process,cmake and make if cmake_and_build: build_steps() - - sys.path.append(TOP_DIR + "/build/python/") - from build.python.env_dict import env_dict as env_dict + build_dir=os.getenv("BUILD_DIR") + if build_dir is not None: + env_dict_path=TOP_DIR +'/'+build_dir+'/python' + sys.path.append(env_dict_path) + from env_dict import env_dict as env_dict + else: + env_dict_path=TOP_DIR + "/build/python/" + sys.path.append(env_dict_path) + from env_dict import env_dict as env_dict global env_dict global paddle_binary_dir, paddle_source_dir From 07c8f26ac51e0462c62f6b7d73592f54b2ba6042 Mon Sep 17 00:00:00 2001 From: risemeup1 <515586620@qq.com> Date: Tue, 6 Dec 2022 06:26:34 +0000 Subject: [PATCH 2/5] modify setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 9eaaca4d36242..d9e4b1026f2ec 100644 --- a/setup.py +++ b/setup.py @@ -1283,6 +1283,7 @@ def main(): # Execute the build process,cmake and make if cmake_and_build: build_steps() + build_dir=os.getenv("BUILD_DIR") if build_dir is not None: env_dict_path=TOP_DIR +'/'+build_dir+'/python' From 105a7a58af922da3a8ad6779b708cb9bbfc4c35f Mon Sep 17 00:00:00 2001 From: risemeup1 <515586620@qq.com> Date: Tue, 6 Dec 2022 06:28:57 +0000 Subject: [PATCH 3/5] modify setup.py --- setup.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index d9e4b1026f2ec..e2d8f7e7b84fb 100644 --- a/setup.py +++ b/setup.py @@ -583,13 +583,13 @@ def build_run(args, build_path, envrion_var): def build_steps(): print('------- Building start ------') - build_dir=os.getenv("BUILD_DIR") + build_dir = os.getenv("BUILD_DIR") if build_dir is not None: - build_dir=TOP_DIR + '/'+build_dir + build_dir = TOP_DIR + '/' + build_dir if not os.path.exists(build_dir): _mkdir_p(build_dir) else: - build_dir=TOP_DIR + '/build' + build_dir = TOP_DIR + '/build' if not os.path.exists(build_dir): _mkdir_p(build_dir) build_path = build_dir @@ -1283,14 +1283,13 @@ def main(): # Execute the build process,cmake and make if cmake_and_build: build_steps() - - build_dir=os.getenv("BUILD_DIR") + build_dir = os.getenv("BUILD_DIR") if build_dir is not None: - env_dict_path=TOP_DIR +'/'+build_dir+'/python' + env_dict_path = TOP_DIR + '/' + build_dir + '/python' sys.path.append(env_dict_path) from env_dict import env_dict as env_dict else: - env_dict_path=TOP_DIR + "/build/python/" + env_dict_path = TOP_DIR + "/build/python/" sys.path.append(env_dict_path) from env_dict import env_dict as env_dict From 5611e73cc388ee54759a2138851af39af30bb5f5 Mon Sep 17 00:00:00 2001 From: risemeup1 <515586620@qq.com> Date: Tue, 6 Dec 2022 08:11:27 +0000 Subject: [PATCH 4/5] modify setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e2d8f7e7b84fb..0ce5e635e948e 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ from distutils.spawn import find_executable from subprocess import CalledProcessError -from setuptools import Command, Distribution, Extension, setup +from setuptools import Command, Extension, setup from setuptools.command.egg_info import egg_info from setuptools.command.install import install as InstallCommandBase from setuptools.command.install_lib import install_lib From b1baf278f075fe1898bc13cef7d588a0eeea1844 Mon Sep 17 00:00:00 2001 From: risemeup1 <515586620@qq.com> Date: Wed, 7 Dec 2022 06:16:33 +0000 Subject: [PATCH 5/5] modify setup.py after zhangbo reviewed --- setup.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 0ce5e635e948e..6d088750a60b0 100644 --- a/setup.py +++ b/setup.py @@ -586,12 +586,10 @@ def build_steps(): build_dir = os.getenv("BUILD_DIR") if build_dir is not None: build_dir = TOP_DIR + '/' + build_dir - if not os.path.exists(build_dir): - _mkdir_p(build_dir) else: build_dir = TOP_DIR + '/build' - if not os.path.exists(build_dir): - _mkdir_p(build_dir) + if not os.path.exists(build_dir): + _mkdir_p(build_dir) build_path = build_dir # run cmake to generate native build files cmake_cache_file_path = os.path.join(build_path, "CMakeCache.txt") @@ -1286,12 +1284,10 @@ def main(): build_dir = os.getenv("BUILD_DIR") if build_dir is not None: env_dict_path = TOP_DIR + '/' + build_dir + '/python' - sys.path.append(env_dict_path) - from env_dict import env_dict as env_dict else: env_dict_path = TOP_DIR + "/build/python/" - sys.path.append(env_dict_path) - from env_dict import env_dict as env_dict + sys.path.append(env_dict_path) + from env_dict import env_dict as env_dict global env_dict global paddle_binary_dir, paddle_source_dir