Skip to content

Commit 06fe442

Browse files
Migrate setup.cfg to pyproject.toml (#217)
Based on #210 closes #209 --------- Signed-off-by: yexiaochuan <[email protected]> Signed-off-by: take-cheeze <[email protected]> Signed-off-by: Takeshi Watanabe <[email protected]> Co-authored-by: yexiaochuan <[email protected]>
1 parent 15e50b7 commit 06fe442

File tree

5 files changed

+115
-122
lines changed

5 files changed

+115
-122
lines changed

.github/workflows/build-and-test.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ jobs:
2222
CIBW_BEFORE_BUILD_LINUX: pip install protobuf
2323
CIBW_BEFORE_BUILD_WINDOWS: python -m pip install protobuf
2424
CIBW_BEFORE_BUILD_MACOS: pip install protobuf
25-
CIBW_TEST_REQUIRES_LINUX: pytest pytest-xdist flake8 mypy onnxruntime
25+
CIBW_TEST_REQUIRES_LINUX: pytest pytest-xdist flake8-pyproject mypy onnxruntime
2626
CIBW_TEST_REQUIRES_MACOS: pytest pytest-xdist
2727
CIBW_TEST_REQUIRES_WINDOWS: pytest pytest-xdist
2828
CIBW_BEFORE_TEST_LINUX: pip install torch==2.6.0+cpu torchvision==0.21.0+cpu --index-url https://download.pytorch.org/whl/cpu
2929
CIBW_TEST_COMMAND: pytest {project}/onnxoptimizer/test
30-
CIBW_TEST_COMMAND_LINUX: cd {project} && flake8 && pytest
30+
CIBW_TEST_COMMAND_LINUX: cd {project} && flake8p && pytest
3131
CIBW_TEST_SKIP: " *_arm64"
3232
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"
3333
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:
6464
with:
6565
submodules: recursive
6666

67-
- run: python3 -m pip install protobuf
68-
6967
- name: Build sdist
7068
run: pipx run build --sdist
7169

MANIFEST.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
recursive-include onnxoptimizer *.h *.c *.cc *.proto
1+
recursive-include onnxoptimizer *.h *.cc
22
recursive-include examples *
33
recursive-include cmake *
44
recursive-include tools *
55
recursive-include third_party *
66
include VERSION_NUMBER
77
include CMakeLists.txt
8+
9+
recursive-exclude third_party *.onnx *.pb *.cs *.rs

pyproject.toml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
[project]
2+
dynamic = ["version"]
3+
name = "onnxoptimizer"
4+
description = "ONNX Optimizer"
5+
license = 'Apache-2.0'
6+
license-files = [
7+
"LICENSE"
8+
]
9+
authors = [
10+
{name = 'ONNX Optimizer Authors', email = "[email protected]"},
11+
]
12+
readme = "README.md"
13+
keywords = [
14+
"deep-learning",
15+
"ONNX",
16+
]
17+
dependencies = [
18+
"onnx",
19+
]
20+
21+
[project.urls]
22+
Homepage = 'https://github.com/onnx/optimizer'
23+
24+
[console_scripts]
25+
onnxoptimizer = "onnxoptimizer:main"
26+
27+
[build-system]
28+
requires = [
29+
"setuptools>=68",
30+
"wheel",
31+
"cmake>=3.22",
32+
"protobuf>=4.25.1"
33+
]
34+
build-backend = "setuptools.build_meta"
35+
36+
[tool.pytest.ini_options]
37+
# addopts = --nbval --current-env
38+
addopts = "-n auto"
39+
testpaths = [
40+
"onnxoptimizer/test/"
41+
]
42+
43+
[[tool.mypy]]
44+
# follow-imports = silent # TODO remove this
45+
mypy_path = "stubs:third_party/onnx/third_party/pybind11"
46+
strict_optional = true
47+
warn_return_any = true
48+
warn_no_return = true
49+
# TODO warn_unused_ignores = true
50+
warn_redundant_casts = true
51+
warn_incomplete_stub = true
52+
# TODO disallow_untyped_calls = true
53+
check_untyped_defs = true
54+
disallow_any_generics = true
55+
no_implicit_optional = true
56+
# TODO disallow_incomplete_defs = true
57+
# TODO disallow_subclassing_any = true
58+
disallow_untyped_decorators = true
59+
warn_unused_configs = true
60+
61+
[[tool.mypy.overrides]]
62+
module = "onnxoptimizer.*"
63+
disallow_untyped_defs = true
64+
65+
[[tool.mypy.overrides]]
66+
module = "onnx_opt_cpp2py_export"
67+
ignore_missing_imports = true
68+
69+
[[tool.mypy.overrides]]
70+
module = "onnx.*"
71+
disallow_untyped_defs = true
72+
ignore_missing_imports = true
73+
74+
[[tool.mypy.overrides]]
75+
module = "tools.*"
76+
disallow_untyped_defs = true
77+
78+
# Ignore errors in setup.py
79+
[[tool.mypy.overrides]]
80+
module = "setup"
81+
ignore_errors = true
82+
83+
[tool.flake8]
84+
select = ["B","C","E","F","P","T4","W","B9"]
85+
max-line-length = 80
86+
### DEFAULT IGNORES FOR 4-space INDENTED PROJECTS ###
87+
# E127, E128 are hard to silence in certain nested formatting situations.
88+
# E265, E266 talk about comment formatting which is too opinionated.
89+
# E402 warns on imports coming after statements. There are important use cases
90+
# like demandimport (https://fburl.com/demandimport) that require statements
91+
# before imports.
92+
# E501 is not flexible enough, we're using B950 instead.
93+
# E722 is a duplicate of B001.
94+
# F405 is hard to silence since we indeed do star import
95+
# P207 is a duplicate of B003.
96+
# P208 is a duplicate of C403.
97+
# W503 talks about operator formatting which is too opinionated.
98+
# F401 clashes with PEP484 requiring us to import types that are only used in
99+
# type comments.
100+
ignore = ["E127", "E128", "E265", "E266", "E402", "E501", "E722", "F405", "P207", "P208", "W503", "F401"]
101+
exclude = [
102+
".git",
103+
"__pycache__",
104+
"build/*",
105+
"third_party/*",
106+
"*_pb2.py",
107+
".cache/*",
108+
".eggs",
109+
".setuptools-cmake-build*/*",
110+
]

setup.cfg

Lines changed: 0 additions & 76 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434

3535
CMAKE = shutil.which('cmake')
3636

37-
install_requires = []
38-
setup_requires = []
39-
extras_require = {}
40-
4137
################################################################################
4238
# Global variables for controlling the build variant
4339
################################################################################
@@ -312,52 +308,15 @@ def run(self):
312308
# no need to do fancy stuff so far
313309
packages = setuptools.find_packages()
314310

315-
install_requires.extend([
316-
'onnx'
317-
])
318-
319311
################################################################################
320312
# Test
321313
################################################################################
322314

323-
setup_requires.append('pytest-runner')
324-
setup_requires.append('protobuf')
325-
326-
if sys.version_info[0] == 3:
327-
# Mypy doesn't work with Python 2
328-
extras_require['mypy'] = ['mypy==0.600']
329-
330-
################################################################################
331-
# Final
332-
################################################################################
333-
334-
# read the contents of your README file
335-
from pathlib import Path
336-
this_directory = Path(__file__).parent
337-
long_description = (this_directory / "README.md").read_text()
338-
339315
setuptools.setup(
340-
name="onnxoptimizer",
341316
version=VersionInfo.version,
342-
description="ONNX Optimizer",
343317
ext_modules=ext_modules,
344318
cmdclass=cmdclass,
345319
packages=packages,
346-
license='Apache License v2.0',
347320
include_package_data=True,
348-
install_requires=install_requires,
349-
setup_requires=setup_requires,
350-
extras_require=extras_require,
351-
author='ONNX Optimizer Authors',
352-
author_email='[email protected]',
353-
url='https://github.com/onnx/optimizer',
354-
keywords='deep-learning ONNX',
355-
long_description=long_description,
356-
long_description_content_type='text/markdown',
357-
entry_points={
358-
'console_scripts': [
359-
'onnxoptimizer=onnxoptimizer:main',
360-
],
361-
},
362321
options=setup_opts,
363322
)

0 commit comments

Comments
 (0)