提交 2dd9bc71 编写于 作者: L liuwei1031 提交者: kolinwei

fix windows python setup issue caused by (#20641) (#20928)

* fix windows python setup issue caused by #20641, test=develop

* tweak python/CMakeLists.txt, test=develop

* redirect log inside setup.py, test=develop

* fix typo, test=develop
上级 c5341496
...@@ -10,6 +10,8 @@ else() ...@@ -10,6 +10,8 @@ else()
SET(PACKAGE_NAME "paddlepaddle") SET(PACKAGE_NAME "paddlepaddle")
endif() endif()
set(SETUP_LOG_FILE "setup.py.log")
set(FLUID_CORE_NAME "core") set(FLUID_CORE_NAME "core")
if(WITH_AVX AND AVX_FOUND) if(WITH_AVX AND AVX_FOUND)
set(FLUID_CORE_NAME "${FLUID_CORE_NAME}_avx") set(FLUID_CORE_NAME "${FLUID_CORE_NAME}_avx")
...@@ -70,21 +72,18 @@ add_custom_command(OUTPUT ${FLUID_CORE} ...@@ -70,21 +72,18 @@ add_custom_command(OUTPUT ${FLUID_CORE}
add_custom_target(copy_paddle_pybind ALL DEPENDS ${FLUID_CORE_DEPS}) add_custom_target(copy_paddle_pybind ALL DEPENDS ${FLUID_CORE_DEPS})
IF(WIN32) IF(WIN32)
add_custom_command(OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp add_custom_command(OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PADDLE_SOURCE_DIR}/python/paddle ${PADDLE_BINARY_DIR}/python/paddle/ COMMAND ${CMAKE_COMMAND} -E copy_directory ${PADDLE_SOURCE_DIR}/python/paddle ${PADDLE_BINARY_DIR}/python/paddle/
COMMAND ${CMAKE_COMMAND} -E env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel COMMAND ${CMAKE_COMMAND} -E env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel
COMMAND ${CMAKE_COMMAND} -E touch ${PADDLE_PYTHON_BUILD_DIR}/.timestamp COMMAND ${CMAKE_COMMAND} -E touch ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PADDLE_PYTHON_BUILD_DIR}/lib-python DEPENDS copy_paddle_pybind ${FLUID_CORE} framework_py_proto profiler_py_proto ${PY_FILES})
DEPENDS copy_paddle_pybind ${FLUID_CORE} framework_py_proto profiler_py_proto ${PY_FILES})
ELSE(WIN32) ELSE(WIN32)
add_custom_command(OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp add_custom_command(OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
COMMAND touch stub.cc COMMAND touch stub.cc
COMMAND cp -r ${PADDLE_SOURCE_DIR}/python/paddle ${PADDLE_BINARY_DIR}/python COMMAND cp -r ${PADDLE_SOURCE_DIR}/python/paddle ${PADDLE_BINARY_DIR}/python
COMMAND env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel COMMAND env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel
COMMAND ${CMAKE_COMMAND} -E touch ${PADDLE_PYTHON_BUILD_DIR}/.timestamp COMMAND ${CMAKE_COMMAND} -E touch ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PADDLE_PYTHON_BUILD_DIR}/lib-python DEPENDS copy_paddle_pybind ${FLUID_CORE} framework_py_proto profiler_py_proto ${PY_FILES})
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PADDLE_PYTHON_BUILD_DIR}/lib* ${PADDLE_PYTHON_BUILD_DIR}/lib-python
DEPENDS copy_paddle_pybind ${FLUID_CORE} framework_py_proto profiler_py_proto ${PY_FILES})
ENDIF() ENDIF()
add_custom_target(paddle_python ALL DEPENDS ${PADDLE_PYTHON_BUILD_DIR}/.timestamp) add_custom_target(paddle_python ALL DEPENDS ${PADDLE_PYTHON_BUILD_DIR}/.timestamp)
......
import subprocess import subprocess
import os import os
import os.path
import re import re
import shutil import shutil
import sys import sys
import fnmatch import fnmatch
from contextlib import contextmanager
from setuptools import Command from setuptools import Command
from setuptools import setup, Distribution, Extension from setuptools import setup, Distribution, Extension
from setuptools.command.install import install as InstallCommandBase from setuptools.command.install import install as InstallCommandBase
...@@ -358,36 +360,40 @@ class InstallHeaders(Command): ...@@ -358,36 +360,40 @@ class InstallHeaders(Command):
def get_outputs(self): def get_outputs(self):
return self.outfiles return self.outfiles
# Saving the installation log generated from setup.py to log_file. # we redirect setuptools log for non-windows
# The log_file is ${PADDLE_BINARY_DIR}/python/setup.py.log. if sys.platform != 'win32':
stdout = sys.stdout @contextmanager
stderr = sys.stderr def redirect_stdout():
log_file = open('setup.py.log', 'w') with open('${SETUP_LOG_FILE}', 'w') as f:
sys.stdout = log_file origin_stdout = sys.stdout
sys.stderr = log_file sys.stdout = f
yield
setup(name='${PACKAGE_NAME}', sys.stdout = origin_stdout
version='${PADDLE_VERSION}', else:
description='Parallel Distributed Deep Learning', @contextmanager
install_requires=setup_requires, def redirect_stdout():
packages=packages, yield
ext_modules=ext_modules,
package_data=package_data, with redirect_stdout():
package_dir=package_dir, setup(name='${PACKAGE_NAME}',
scripts=paddle_bins, version='${PADDLE_VERSION}',
distclass=BinaryDistribution, description='Parallel Distributed Deep Learning',
headers=headers, install_requires=setup_requires,
cmdclass={ packages=packages,
'install_headers': InstallHeaders, ext_modules=ext_modules,
'install': InstallCommand, package_data=package_data,
} package_dir=package_dir,
) scripts=paddle_bins,
distclass=BinaryDistribution,
log_file.close() headers=headers,
# Revert back the stdout/stderr to their default references. cmdclass={
sys.stdout = stdout 'install_headers': InstallHeaders,
sys.stderr = stderr 'install': InstallCommand,
}
)
# As there are a lot of files in purelib which causes many logs, # As there are a lot of files in purelib which causes many logs,
# we don't print them on the screen, and you can open `setup.py.log` # we don't print them on the screen, and you can open `setup.py.log`
# for the full logs. # for the full logs.
os.system('grep -v "purelib" setup.py.log') if os.path.exists('${SETUP_LOG_FILE}'):
os.system('grep -v "purelib" ${SETUP_LOG_FILE}')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册