From 08a60c09b97fe666d0b5805c4cde560e6315d42f Mon Sep 17 00:00:00 2001 From: yexiaochuan Date: Sun, 31 Aug 2025 08:53:08 +0800 Subject: [PATCH 1/3] build: add pyproject.toml for PEP 517/518 support Signed-off-by: yexiaochuan --- pyproject.toml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..d2fbb4ac4 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[build-system] +requires = [ + "setuptools>=68", + "wheel", + "cmake>=3.22", + "protobuf>=4.25.1" +] +build-backend = "setuptools.build_meta" From 854a951bfb7904943bc0dc8a35e952e17fb87d0b Mon Sep 17 00:00:00 2001 From: take-cheeze Date: Thu, 23 Oct 2025 15:27:47 +0900 Subject: [PATCH 2/3] Remove setup.cfg Signed-off-by: take-cheeze --- .github/workflows/build-and-test.yml | 6 +- MANIFEST.in | 4 +- pyproject.toml | 105 +++++++++++++++++++++++++++ setup.cfg | 76 ------------------- setup.py | 41 ----------- 5 files changed, 110 insertions(+), 122 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index a25ba0171..5685dc1cf 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -22,12 +22,12 @@ jobs: CIBW_BEFORE_BUILD_LINUX: pip install protobuf CIBW_BEFORE_BUILD_WINDOWS: python -m pip install protobuf CIBW_BEFORE_BUILD_MACOS: pip install protobuf - CIBW_TEST_REQUIRES_LINUX: pytest pytest-xdist flake8 mypy onnxruntime + CIBW_TEST_REQUIRES_LINUX: pytest pytest-xdist flake8-pyproject mypy onnxruntime CIBW_TEST_REQUIRES_MACOS: pytest pytest-xdist CIBW_TEST_REQUIRES_WINDOWS: pytest pytest-xdist CIBW_BEFORE_TEST_LINUX: pip install torch==2.6.0+cpu torchvision==0.21.0+cpu --index-url https://download.pytorch.org/whl/cpu CIBW_TEST_COMMAND: pytest {project}/onnxoptimizer/test - CIBW_TEST_COMMAND_LINUX: cd {project} && flake8 && pytest + CIBW_TEST_COMMAND_LINUX: cd {project} && flake8p && pytest CIBW_TEST_SKIP: " *_arm64" CIBW_ENVIRONMENT: CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5" CIBW_ENVIRONMENT_WINDOWS: USE_MSVC_STATIC_RUNTIME=0 CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON" @@ -64,8 +64,6 @@ jobs: with: submodules: recursive - - run: python3 -m pip install protobuf - - name: Build sdist run: pipx run build --sdist diff --git a/MANIFEST.in b/MANIFEST.in index ef3760982..bdcd21977 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,9 @@ -recursive-include onnxoptimizer *.h *.c *.cc *.proto +recursive-include onnxoptimizer *.h *.cc recursive-include examples * recursive-include cmake * recursive-include tools * recursive-include third_party * include VERSION_NUMBER include CMakeLists.txt + +recursive-exclude third_party *.onnx *.pb *.cs *.rs diff --git a/pyproject.toml b/pyproject.toml index d2fbb4ac4..fbb036e68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,32 @@ +[project] +dynamic = ["version"] +name = "onnxoptimizer" +description = "ONNX Optimizer" +license = 'Apache-2.0' +license-files = [ + "LICENSE" +] +authors = [ + {name = 'ONNX Optimizer Authors', email = "onnx-technical-discuss@lists.lfai.foundation"}, +] +readme = "README.md" +keywords = [ + "deep-learning", + "ONNX", +] +dependencies = [ + "onnx", +] + +[project.optional-dependencies] +mypy = ['mypy==0.600'] + +[project.urls] +Homepage = 'https://github.com/onnx/optimizer' + +[console_scripts] +onnxoptimizer = "onnxoptimizer:main" + [build-system] requires = [ "setuptools>=68", @@ -6,3 +35,79 @@ requires = [ "protobuf>=4.25.1" ] build-backend = "setuptools.build_meta" + +[tool.pytest.ini_options] +# addopts = --nbval --current-env +addopts = "-n auto" +testpaths = [ + "onnxoptimizer/test/" +] + +[[tool.mypy]] +# follow-imports = silent # TODO remove this +mypy_path = "stubs:third_party/onnx/third_party/pybind11" +strict_optional = true +warn_return_any = true +warn_no_return = true +# TODO warn_unused_ignores = true +warn_redundant_casts = true +warn_incomplete_stub = true +# TODO disallow_untyped_calls = true +check_untyped_defs = true +disallow_any_generics = true +no_implicit_optional = true +# TODO disallow_incomplete_defs = true +# TODO disallow_subclassing_any = true +disallow_untyped_decorators = true +warn_unused_configs = true + +[[tool.mypy.overrides]] +module = "onnxoptimizer.*" +disallow_untyped_defs = true + +[[tool.mypy.overrides]] +module = "onnx_opt_cpp2py_export" +ignore_missing_imports = true + +[[tool.mypy.overrides]] +module = "onnx.*" +disallow_untyped_defs = true +ignore_missing_imports = true + +[[tool.mypy.overrides]] +module = "tools.*" +disallow_untyped_defs = true + +# Ignore errors in setup.py +[[tool.mypy.overrides]] +module = "setup" +ignore_errors = true + +[tool.flake8] +select = ["B","C","E","F","P","T4","W","B9"] +max-line-length = 80 +### DEFAULT IGNORES FOR 4-space INDENTED PROJECTS ### +# E127, E128 are hard to silence in certain nested formatting situations. +# E265, E266 talk about comment formatting which is too opinionated. +# E402 warns on imports coming after statements. There are important use cases +# like demandimport (https://fburl.com/demandimport) that require statements +# before imports. +# E501 is not flexible enough, we're using B950 instead. +# E722 is a duplicate of B001. +# F405 is hard to silence since we indeed do star import +# P207 is a duplicate of B003. +# P208 is a duplicate of C403. +# W503 talks about operator formatting which is too opinionated. +# F401 clashes with PEP484 requiring us to import types that are only used in +# type comments. +ignore = ["E127", "E128", "E265", "E266", "E402", "E501", "E722", "F405", "P207", "P208", "W503", "F401"] +exclude = [ + ".git", + "__pycache__", + "build/*", + "third_party/*", + "*_pb2.py", + ".cache/*", + ".eggs", + ".setuptools-cmake-build*/*", +] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 88b4dfeac..000000000 --- a/setup.cfg +++ /dev/null @@ -1,76 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -[aliases] -test=pytest - -[tool:pytest] -# addopts = --nbval --current-env -addopts = -n auto -testpaths = onnxoptimizer/test/ - -[metadata] -license_file = LICENSE - -[flake8] -select = B,C,E,F,P,T4,W,B9 -max-line-length = 80 -### DEFAULT IGNORES FOR 4-space INDENTED PROJECTS ### -# E127, E128 are hard to silence in certain nested formatting situations. -# E265, E266 talk about comment formatting which is too opinionated. -# E402 warns on imports coming after statements. There are important use cases -# like demandimport (https://fburl.com/demandimport) that require statements -# before imports. -# E501 is not flexible enough, we're using B950 instead. -# E722 is a duplicate of B001. -# F405 is hard to silence since we indeed do star import -# P207 is a duplicate of B003. -# P208 is a duplicate of C403. -# W503 talks about operator formatting which is too opinionated. -# F401 clashes with PEP484 requiring us to import types that are only used in -# type comments. -ignore = E127, E128, E265, E266, E402, E501, E722, F405, P207, P208, W503, F401 -exclude = - .git, - __pycache__, - build/*, - third_party/* - *_pb2.py, - .cache/* - .eggs - .setuptools-cmake-build*/* - -[mypy] -# follow-imports = silent # TODO remove this -mypy_path = stubs:third_party/onnx/third_party/pybind11 -strict_optional = True -warn_return_any = True -warn_no_return = True -# TODO warn_unused_ignores = True -warn_redundant_casts = True -warn_incomplete_stub = True -# TODO disallow_untyped_calls = True -check_untyped_defs = True -disallow_any_generics = True -no_implicit_optional = True -# TODO disallow_incomplete_defs = True -# TODO disallow_subclassing_any = True -disallow_untyped_decorators = True -warn_unused_configs = True - -[mypy-onnxoptimizer.*] -disallow_untyped_defs = True - -[mypy-onnxoptimizer.onnx_opt_cpp2py_export] -ignore_missing_imports = True - -[mypy-onnx.*] -disallow_untyped_defs = True -ignore_missing_imports = True - -[mypy-tools.*] -disallow_untyped_defs = True - -# Ignore errors in setup.py -[mypy-setup] -ignore_errors = True - diff --git a/setup.py b/setup.py index 9df9fb606..2733f9a89 100644 --- a/setup.py +++ b/setup.py @@ -34,10 +34,6 @@ CMAKE = shutil.which('cmake') -install_requires = [] -setup_requires = [] -extras_require = {} - ################################################################################ # Global variables for controlling the build variant ################################################################################ @@ -312,52 +308,15 @@ def run(self): # no need to do fancy stuff so far packages = setuptools.find_packages() -install_requires.extend([ - 'onnx' -]) - ################################################################################ # Test ################################################################################ -setup_requires.append('pytest-runner') -setup_requires.append('protobuf') - -if sys.version_info[0] == 3: - # Mypy doesn't work with Python 2 - extras_require['mypy'] = ['mypy==0.600'] - -################################################################################ -# Final -################################################################################ - -# read the contents of your README file -from pathlib import Path -this_directory = Path(__file__).parent -long_description = (this_directory / "README.md").read_text() - setuptools.setup( - name="onnxoptimizer", version=VersionInfo.version, - description="ONNX Optimizer", ext_modules=ext_modules, cmdclass=cmdclass, packages=packages, - license='Apache License v2.0', include_package_data=True, - install_requires=install_requires, - setup_requires=setup_requires, - extras_require=extras_require, - author='ONNX Optimizer Authors', - author_email='onnx-technical-discuss@lists.lfai.foundation', - url='https://github.com/onnx/optimizer', - keywords='deep-learning ONNX', - long_description=long_description, - long_description_content_type='text/markdown', - entry_points={ - 'console_scripts': [ - 'onnxoptimizer=onnxoptimizer:main', - ], - }, options=setup_opts, ) From 720cd0a0fa2355ea74fb6d3ab8b55b16f46eef92 Mon Sep 17 00:00:00 2001 From: Takeshi Watanabe Date: Fri, 24 Oct 2025 09:00:33 +0900 Subject: [PATCH 3/3] Apply suggestion from @take-cheeze Signed-off-by: Takeshi Watanabe --- pyproject.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fbb036e68..64b11e242 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,9 +18,6 @@ dependencies = [ "onnx", ] -[project.optional-dependencies] -mypy = ['mypy==0.600'] - [project.urls] Homepage = 'https://github.com/onnx/optimizer'