Skip to content

Commit

Permalink
Setuptools optimization (PaddlePaddle#48770)
Browse files Browse the repository at this point in the history
* optimize setup.py

* modify setup.py

* modify setup.py

* modify setup.py

* modify setup.py after zhangbo reviewed
  • Loading branch information
risemeup1 authored Dec 8, 2022
1 parent 9c8aba8 commit 79a37ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
15 changes: 1 addition & 14 deletions paddle/scripts/paddle_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3467,20 +3467,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/
Expand Down
25 changes: 17 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -583,9 +583,14 @@ 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
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
Expand Down Expand Up @@ -1276,9 +1281,13 @@ 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'
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
Expand Down

0 comments on commit 79a37ca

Please sign in to comment.