Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Build][Update] Update the project's build process to pyproject. #1221

Merged
merged 11 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 46 additions & 38 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,52 @@ permissions:

jobs:
build:

# For the sake of simplicity in testing, the Paddle2ONNX packaging program will temporarily run on Ubuntu-latest.
# However, to ensure the stability of the packaging system, we will need to fix the Ubuntu version in the future.
runs-on: ubuntu-latest

# For the sake of simplicity in testing, the Paddle2ONNX packaging program will temporarily only package executable files for Python 3.8.
# In the future, we will need to extend support to cover Python 3.8 through Python 3.10.
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Checkout Paddle2ONNX
uses: actions/checkout@v4
with:
submodules: true
path: paddle2onnx

- name: Checkout Protobuf
uses: actions/checkout@v4
with:
repository: protocolbuffers/protobuf
ref: v3.16.0
path: protobuf

- name: Build Protobuf
working-directory: ./protobuf
run: |
#============
cmake ./cmake -B build_wd -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./install_dir
cmake --build ./build_wd
cmake --build ./build_wd -- install
echo "$PWD/install_dir/bin" >> $GITHUB_PATH

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel auditwheel auditwheel-symbols
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Build Paddle2ONNX
working-directory: ./paddle2onnx
run: |
python setup.py install
- name: Setup Python 3.8
uses: actions/setup-python@v5
with:
python-version: '3.8'

# Checkout the latest branch of Paddle2ONNX.
- name: Checkout Paddle2ONNX
uses: actions/checkout@v4
with:
submodules: true
path: paddle2onnx

# Checkout the branch(v3.16.0) of Paddle2ONNX.
- name: Checkout Protobuf
uses: actions/checkout@v4
with:
repository: protocolbuffers/protobuf
ref: v3.16.0
path: protobuf

# Build Protobuf, detailed process can refer to the [Paddle2ONNX construction documentation](https://github.com/PaddlePaddle/Paddle2ONNX/blob/develop/docs/zh/compile.md).
- name: Build Protobuf
working-directory: ./protobuf
run: |
#============
cmake ./cmake -B build_wd -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./install_dir
cmake --build ./build_wd
cmake --build ./build_wd -- install
echo "$PWD/install_dir/bin" >> $GITHUB_PATH

# Install Dependencies for Python
- name: Install Dependencies for Python
run: |
python -m pip install --upgrade pip
pip install setuptools wheel auditwheel auditwheel-symbols
Zheng-Bicheng marked this conversation as resolved.
Show resolved Hide resolved
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

# Build Paddle2ONNX
- name: Build Paddle2ONNX
working-directory: ./paddle2onnx
run: |
python -m build
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ paddle2onnx.egg-info/*
*_*.onnx
*.log
version.py
paddle2onnx/mappers_registry.h
paddle2onnx/mappers_registry.h
13 changes: 6 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[submodule "third/onnx"]
path = third/onnx
[submodule "third_party/onnx"]
path = third_party/onnx
url = https://github.com/onnx/onnx.git
branch = da889e6b95750350726d149bf447bf0cd1245964
[submodule "third/optimizer"]
path = third/optimizer
[submodule "third_party/optimizer"]
path = third_party/optimizer
url = https://github.com/onnx/optimizer.git
branch = a37748b2c3a80dad4274401c45c5026c7a506730
[submodule "third/pybind11"]
path = third/pybind11
[submodule "third_party/pybind11"]
path = third_party/pybind11
url = https://github.com/pybind/pybind11.git
branch = master
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ if(NOT TARGET onnx_proto)
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(${PROJECT_SOURCE_DIR}/third/onnx)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/onnx)
endif()

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR}/third/optimizer)
include_directories(${PROJECT_SOURCE_DIR}/third_party/optimizer)
add_subdirectory(${PROJECT_SOURCE_DIR}/paddle2onnx/proto)

file(GLOB_RECURSE ALL_SRCS ${PROJECT_SOURCE_DIR}/paddle2onnx/*.cc ${PROJECT_SOURCE_DIR}/third/optimizer/onnxoptimizer/*.cc)
file(GLOB_RECURSE ALL_SRCS ${PROJECT_SOURCE_DIR}/paddle2onnx/*.cc ${PROJECT_SOURCE_DIR}/third_party/optimizer/onnxoptimizer/*.cc)
list(REMOVE_ITEM ALL_SRCS ${PROJECT_SOURCE_DIR}/paddle2onnx/cpp2py_export.cc)
list(REMOVE_ITEM ALL_SRCS ${PROJECT_SOURCE_DIR}/third/optimizer/onnxoptimizer/cpp2py_export.cc)
list(REMOVE_ITEM ALL_SRCS ${PROJECT_SOURCE_DIR}/third_party/optimizer/onnxoptimizer/cpp2py_export.cc)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
file(READ "${PROJECT_SOURCE_DIR}/VERSION_NUMBER" PADDLE2ONNX_VERSION)
Expand Down Expand Up @@ -189,9 +189,9 @@ if(BUILD_PADDLE2ONNX_PYTHON)
target_include_directories(paddle2onnx_cpp2py_export PUBLIC
${pybind11_INCLUDE_DIRS})
else()
if(EXISTS ${PROJECT_SOURCE_DIR}/third/pybind11/include/pybind11/pybind11.h)
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/pybind11/include/pybind11/pybind11.h)
target_include_directories(paddle2onnx_cpp2py_export PUBLIC
${PROJECT_SOURCE_DIR}/third/pybind11/include)
${PROJECT_SOURCE_DIR}/third_party/pybind11/include)
else()
message(FATAL_ERROR "cannot find pybind")
endif()
Expand Down
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
recursive-include cmake *
recursive-include paddle2onnx *
recursive-include third_party *
recursive-include tools *

include LICENSE
include VERSION_NUMBER
include CMakeLists.txt
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"cmake>=3.16",
]
build-backend = "setuptools.build_meta"

[tool.poetry.dependencies.files]
version = { path = "version.txt" }

[tool.mypy]
files = "setup.py"
python_version = "3.8"
strict = true
show_error_codes = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
warn_unreachable = true
Empty file removed requirements.txt
Empty file.
19 changes: 5 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,9 @@
# Version
################################################################################

try:
git_version = subprocess.check_output(
['git', 'rev-parse', 'HEAD'], cwd=TOP_DIR).decode('ascii').strip()
except (OSError, subprocess.CalledProcessError):
git_version = None

with open(os.path.join(TOP_DIR, 'VERSION_NUMBER')) as version_file:
VersionInfo = namedtuple('VersionInfo', ['version', 'git_version'])(
version=version_file.read().strip(), git_version=git_version)
_version = version_file.read().strip()
VERSION_INFO = {"version": _version}
Zheng-Bicheng marked this conversation as resolved.
Show resolved Hide resolved

################################################################################
# Pre Check
Expand Down Expand Up @@ -119,8 +113,7 @@ def run(self):
from __future__ import print_function
from __future__ import unicode_literals
version = '{version}'
git_version = '{git_version}'
'''.format(**dict(VersionInfo._asdict()))))
'''.format(**VERSION_INFO)))


class cmake_build(setuptools.Command):
Expand Down Expand Up @@ -164,8 +157,7 @@ def run(self):
'-DBUILD_PADDLE2ONNX_PYTHON=ON',
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
'-DONNX_NAMESPACE={}'.format(ONNX_NAMESPACE),
'-DPY_EXT_SUFFIX={}'.format(
sysconfig.get_config_var('EXT_SUFFIX') or ''),
'-DPY_EXT_SUFFIX={}'.format(sysconfig.get_config_var('EXT_SUFFIX') or ''),
]
cmake_args.append('-DCMAKE_BUILD_TYPE=%s' % build_type)
if WINDOWS:
Expand Down Expand Up @@ -298,7 +290,7 @@ def run(self):

setuptools.setup(
name="paddle2onnx",
version=VersionInfo.version,
version=VERSION_INFO["version"],
description="Export PaddlePaddle to ONNX",
ext_modules=ext_modules,
cmdclass=cmdclass,
Expand All @@ -309,7 +301,6 @@ def run(self):
author='paddle-infer',
author_email='[email protected]',
url='https://github.com/PaddlePaddle/Paddle2ONNX.git',
# install_requires=['six', 'protobuf', 'onnx<=1.9.0'],
install_requires=['six'],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
Loading
Loading