From e4e3675f4cab407651089369e365b2f2fd39c49f Mon Sep 17 00:00:00 2001 From: risemeup1 <62429225+risemeup1@users.noreply.github.com> Date: Wed, 15 Mar 2023 17:26:32 +0800 Subject: [PATCH] optimizing setup.py develop command (#51528) * optimizing setup.py develop command * add libpaddle.so * modify setup.py * add python/paddle/distributed/fleet/.gitignore * add libpaddle.so to .gitignore * add *.so to python/paddle/libs/.gitignore * add new gitignore --- python/.gitignore | 1 + python/paddle/.gitignore | 2 + python/paddle/distributed/fleet/.gitignore | 1 + python/paddle/fluid/.gitignore | 1 + python/paddle/libs/.gitignore | 1 + setup.py | 65 ++++++++++++++++++---- 6 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 python/paddle/distributed/fleet/.gitignore create mode 100644 python/paddle/libs/.gitignore diff --git a/python/.gitignore b/python/.gitignore index 53a2b7a76b0..d0c7300f8c4 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -7,3 +7,4 @@ paddlepaddle_gpu.egg-info .idea paddle/proto/*.py paddle/proto/*.pyc +_foo.* diff --git a/python/paddle/.gitignore b/python/paddle/.gitignore index 98527864664..b405a11db9a 100644 --- a/python/paddle/.gitignore +++ b/python/paddle/.gitignore @@ -1 +1,3 @@ version.py +cuda_env.py +version diff --git a/python/paddle/distributed/fleet/.gitignore b/python/paddle/distributed/fleet/.gitignore new file mode 100644 index 00000000000..2ff540d5764 --- /dev/null +++ b/python/paddle/distributed/fleet/.gitignore @@ -0,0 +1 @@ +proto diff --git a/python/paddle/fluid/.gitignore b/python/paddle/fluid/.gitignore index 80c1cf3fcb8..0745bad8c67 100644 --- a/python/paddle/fluid/.gitignore +++ b/python/paddle/fluid/.gitignore @@ -1,2 +1,3 @@ proto core.so +*.so diff --git a/python/paddle/libs/.gitignore b/python/paddle/libs/.gitignore new file mode 100644 index 00000000000..8d977535b81 --- /dev/null +++ b/python/paddle/libs/.gitignore @@ -0,0 +1 @@ +*.so* diff --git a/setup.py b/setup.py index 75969c5f41c..c4137d42227 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ from distutils.spawn import find_executable from subprocess import CalledProcessError from setuptools import Command, Extension, setup +from setuptools.command.develop import develop as DevelopCommandBase from setuptools.command.egg_info import egg_info from setuptools.command.install import install as InstallCommandBase from setuptools.command.install_lib import install_lib @@ -222,6 +223,55 @@ class InstallCommand(InstallCommandBase): return ret +class DevelopCommand(DevelopCommandBase): + def run(self): + # copy proto and .so to python_source_dir + fluid_proto_binary_path = ( + paddle_binary_dir + '/python/paddle/fluid/proto/' + ) + fluid_proto_source_path = ( + paddle_source_dir + '/python/paddle/fluid/proto/' + ) + distributed_proto_binary_path = ( + paddle_binary_dir + '/python/paddle/distributed/fleet/proto/' + ) + distributed_proto_source_path = ( + paddle_source_dir + '/python/paddle/distributed/fleet/proto/' + ) + os.system("rm -rf {}".format(fluid_proto_source_path)) + shutil.copytree(fluid_proto_binary_path, fluid_proto_source_path) + os.system("rm -rf {}".format(distributed_proto_source_path)) + shutil.copytree( + distributed_proto_binary_path, distributed_proto_source_path + ) + shutil.copy( + paddle_binary_dir + '/python/paddle/fluid/libpaddle.so', + paddle_source_dir + '/python/paddle/fluid/', + ) + dynamic_library_binary_path = paddle_binary_dir + '/python/paddle/libs/' + dynamic_library_source_path = paddle_source_dir + '/python/paddle/libs/' + for lib_so in os.listdir(dynamic_library_binary_path): + shutil.copy( + dynamic_library_binary_path + lib_so, + dynamic_library_source_path, + ) + # write version.py and cuda_env_config_py to python_source_dir + write_version_py( + filename='{}/python/paddle/version/__init__.py'.format( + paddle_source_dir + ) + ) + write_cuda_env_config_py( + filename='{}/python/paddle/cuda_env.py'.format(paddle_source_dir) + ) + write_parameter_server_version_py( + filename='{}/python/paddle/incubate/distributed/fleet/parameter_server/version.py'.format( + paddle_source_dir + ) + ) + DevelopCommandBase.run(self) + + class EggInfo(egg_info): """Copy license file into `.dist-info` folder.""" @@ -828,18 +878,7 @@ def get_package_data_and_package_dir(): paddle_binary_dir + '/python/paddle/cost_model/static_op_benchmark.json' ] if 'develop' in sys.argv: - package_dir = { - '': paddle_binary_dir.split('/')[-1] + '/python', - # '':'build/python', - # The paddle.fluid.proto will be generated while compiling. - # So that package points to other directory. - 'paddle.fluid.proto.profiler': paddle_binary_dir.split('/')[-1] - + '/paddle/fluid/platform', - 'paddle.fluid.proto': paddle_binary_dir.split('/')[-1] - + '/paddle/fluid/framework', - 'paddle.fluid': paddle_binary_dir.split('/')[-1] - + '/python/paddle/fluid', - } + package_dir = {'': 'python'} else: package_dir = { '': env_dict.get("PADDLE_BINARY_DIR") + '/python', @@ -1470,6 +1509,7 @@ def main(): # preparing parameters for setup() paddle_version = env_dict.get("PADDLE_VERSION") package_name = env_dict.get("PACKAGE_NAME") + write_version_py( filename='{}/python/paddle/version/__init__.py'.format( paddle_binary_dir @@ -1534,6 +1574,7 @@ def main(): 'install': InstallCommand, 'egg_info': EggInfo, 'install_lib': InstallLib, + 'develop': DevelopCommand, }, entry_points={ 'console_scripts': [ -- GitLab