提交 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()
SET(PACKAGE_NAME "paddlepaddle")
endif()
set(SETUP_LOG_FILE "setup.py.log")
set(FLUID_CORE_NAME "core")
if(WITH_AVX AND AVX_FOUND)
set(FLUID_CORE_NAME "${FLUID_CORE_NAME}_avx")
......@@ -74,7 +76,6 @@ IF(WIN32)
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 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})
ELSE(WIN32)
add_custom_command(OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
......@@ -82,8 +83,6 @@ ELSE(WIN32)
COMMAND cp -r ${PADDLE_SOURCE_DIR}/python/paddle ${PADDLE_BINARY_DIR}/python
COMMAND env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel
COMMAND ${CMAKE_COMMAND} -E touch ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PADDLE_PYTHON_BUILD_DIR}/lib-python
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()
......
import subprocess
import os
import os.path
import re
import shutil
import sys
import fnmatch
from contextlib import contextmanager
from setuptools import Command
from setuptools import setup, Distribution, Extension
from setuptools.command.install import install as InstallCommandBase
......@@ -358,15 +360,22 @@ class InstallHeaders(Command):
def get_outputs(self):
return self.outfiles
# Saving the installation log generated from setup.py to log_file.
# The log_file is ${PADDLE_BINARY_DIR}/python/setup.py.log.
stdout = sys.stdout
stderr = sys.stderr
log_file = open('setup.py.log', 'w')
sys.stdout = log_file
sys.stderr = log_file
# we redirect setuptools log for non-windows
if sys.platform != 'win32':
@contextmanager
def redirect_stdout():
with open('${SETUP_LOG_FILE}', 'w') as f:
origin_stdout = sys.stdout
sys.stdout = f
yield
sys.stdout = origin_stdout
else:
@contextmanager
def redirect_stdout():
yield
setup(name='${PACKAGE_NAME}',
with redirect_stdout():
setup(name='${PACKAGE_NAME}',
version='${PADDLE_VERSION}',
description='Parallel Distributed Deep Learning',
install_requires=setup_requires,
......@@ -381,13 +390,10 @@ setup(name='${PACKAGE_NAME}',
'install_headers': InstallHeaders,
'install': InstallCommand,
}
)
)
log_file.close()
# Revert back the stdout/stderr to their default references.
sys.stdout = stdout
sys.stderr = stderr
# 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`
# 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.
先完成此消息的编辑!
想要评论请 注册