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

Move to using protogen's .pyi file generator #6096

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 16 additions & 14 deletions .github/workflows/main.yml
Expand Up @@ -2,15 +2,15 @@ name: CI

on:
schedule:
- cron: '0 0 * * *' # every day at midnight for reporting code coverage to codecov
- cron: "0 0 * * *" # every day at midnight for reporting code coverage to codecov
push:
branches:
- main
pull_request:
merge_group:
workflow_dispatch:

permissions: # set top-level default permissions as security best practice
permissions: # set top-level default permissions as security best practice
contents: read

concurrency:
Expand All @@ -23,34 +23,34 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest,macos-latest]
python_version: ['3.12', '3.11', '3.10', '3.9', '3.8']
os: [ubuntu-latest, windows-latest, macos-latest]
python_version: ["3.12", "3.11", "3.10", "3.9", "3.8"]
include:
- python_version: '3.12'
- python_version: "3.12"
onnx_ml: 1
debug_build: 1
documentation: 1
protobuf_type: 'Internal'
- python_version: '3.11'
protobuf_type: "Internal"
- python_version: "3.11"
onnx_ml: 1
debug_build: 0
documentation: 0
protobuf_type: 'External'
- python_version: '3.10'
protobuf_type: "External"
- python_version: "3.10"
onnx_ml: 0
debug_build: 0
documentation: 0
protobuf_type: 'Internal'
- python_version: '3.9'
protobuf_type: "Internal"
- python_version: "3.9"
onnx_ml: 1
debug_build: 0
documentation: 0
protobuf_type: 'External'
- python_version: '3.8'
protobuf_type: "External"
- python_version: "3.8"
onnx_ml: 0
debug_build: 0
documentation: 0
protobuf_type: 'Internal'
protobuf_type: "Internal"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
Expand All @@ -70,6 +70,8 @@ jobs:
if: matrix.protobuf_type == 'External' && matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install libprotobuf-dev protobuf-compiler
env:
CMAKE_ARGS: "-DONNX_GEN_PB_TYPE_STUBS=OFF"

- name: Install external protobuf - MacOS
if: matrix.protobuf_type == 'External' && matrix.os == 'macos-latest'
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -81,7 +81,6 @@ compile_commands.json
# generated files
onnx/version.py
compile_commands.json
tools/protoc-gen-mypy.sh

# test generated files
.cache
Expand Down Expand Up @@ -112,4 +111,4 @@ docs/docsgen/**/*.onnx
docs/docsgen/**/*.pb

# PyEnv files
.python-version
.python-version
4 changes: 2 additions & 2 deletions .reuse/dep5
Expand Up @@ -130,11 +130,11 @@ Files: cmake/ONNXConfig*.in CMakeLists.txt cmake/*cmake cmake/
COPYRIGHT: Copyright (c) ONNX Project Contributors
License: Apache-2.0

Files: .vscode/settings.json docs/docsgen/source/_templates/layout.html docs/docsgen/source/_templates/sidebar-nav-bs.html docs/images/onnx_hub_arch.svg docs/onnx-horizontal-color.png tools/protoc-gen-mypy.sh.in
Files: .vscode/settings.json docs/docsgen/source/_templates/layout.html docs/docsgen/source/_templates/sidebar-nav-bs.html docs/images/onnx_hub_arch.svg docs/onnx-horizontal-color.png
COPYRIGHT: Copyright (c) ONNX Project Contributors
License: Apache-2.0

Files: onnx/gen_proto.py tools/protoc-gen-mypy.bat onnx/reference/op_run.py
Files: onnx/gen_proto.py onnx/reference/op_run.py
COPYRIGHT: Copyright (c) ONNX Project Contributors
License: Apache-2.0

Expand Down
26 changes: 4 additions & 22 deletions CMakeLists.txt
Expand Up @@ -373,29 +373,11 @@ function(RELATIVE_PROTOBUF_GENERATE_CPP NAME SRCS HDRS ROOT_DIR DEPEND)
--cpp_out
${ONNX_DLLEXPORT_STR}${CMAKE_CURRENT_BINARY_DIR})
if(BUILD_ONNX_PYTHON)
list(APPEND PROTOC_ARGS --python_out
${CMAKE_CURRENT_BINARY_DIR})
list(APPEND PROTOC_ARGS --python_out)
if(ONNX_GEN_PB_TYPE_STUBS)
if(NOT WIN32)
# use PYTHON_EXECUTABLE to python protoc-gen-mypy.py
configure_file(
${ROOT_DIR}/tools/protoc-gen-mypy.sh.in
${PROJECT_BINARY_DIR}/tools/protoc-gen-mypy.sh
@ONLY)
execute_process(COMMAND chmod +x ${PROJECT_BINARY_DIR}/tools/protoc-gen-mypy.sh)
configure_file(
${ROOT_DIR}/tools/protoc-gen-mypy.py
${PROJECT_BINARY_DIR}/tools/protoc-gen-mypy.py
COPYONLY)
set(PROTOC_MYPY_PLUGIN_FILE ${PROJECT_BINARY_DIR}/tools/protoc-gen-mypy.sh)
else()
set(PROTOC_MYPY_PLUGIN_FILE ${ROOT_DIR}/tools/protoc-gen-mypy.bat)
endif()
list(APPEND PROTOC_ARGS
--plugin
protoc-gen-mypy=${PROTOC_MYPY_PLUGIN_FILE}
--mypy_out
${ONNX_DLLEXPORT_STR}${CMAKE_CURRENT_BINARY_DIR})
list(APPEND PROTOC_ARGS pyi_out:${CMAKE_CURRENT_BINARY_DIR})
else()
list(APPEND PROTOC_ARGS ${CMAKE_CURRENT_BINARY_DIR})
endif()
endif()
if(NOT ONNX_PROTOC_EXECUTABLE)
Expand Down
4 changes: 0 additions & 4 deletions tools/protoc-gen-mypy.bat

This file was deleted.

3 changes: 3 additions & 0 deletions tools/protoc-gen-mypy.py
kumar-ish marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -6,6 +6,9 @@
#
# SPDX-License-Identifier: Apache-2.0

# NOTE: This is presently deprecated in favour of protogen's own .pyi generation method.

Check warning on line 9 in tools/protoc-gen-mypy.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "favour" is a misspelling of "favor" Raw Output: ./tools/protoc-gen-mypy.py:9:40: "favour" is a misspelling of "favor"
# See: https://github.com/onnx/onnx/pull/6096

# Taken from https://github.com/dropbox/mypy-protobuf/blob/d984389124eae6dbbb517f766b9266bb32171510/python/protoc-gen-mypy
# (Apache 2.0 License)
# with own fixes to
Expand Down
4 changes: 0 additions & 4 deletions tools/protoc-gen-mypy.sh.in

This file was deleted.