We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
MacOS release action is failing.
### Description

(https://github.com/actions/setup-python/issues/855)

### Motivation and Context
<!-- - Why is this change required? What problem does it solve? -->
<!-- - If it fixes an open issue, please link to the issue here. -->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 # Copyright (c) ONNX Project Contributors
2 #
3 # SPDX-License-Identifier: Apache-2.0
4 
5 # NOTE: Put all metadata in pyproject.toml.
6 # Set the environment variable `ONNX_PREVIEW_BUILD=1` to build the dev preview release.
7 
8 import contextlib
9 import datetime
10 import glob
11 import logging
12 import multiprocessing
13 import os
14 import platform
15 import shlex
16 import shutil
17 import subprocess
18 import sys
19 import sysconfig
20 import textwrap
21 from typing import ClassVar
22 
23 import setuptools
24 import setuptools.command.build_ext
25 import setuptools.command.build_py
26 import setuptools.command.develop
27 
28 TOP_DIR = os.path.realpath(os.path.dirname(__file__))
29 CMAKE_BUILD_DIR = os.path.join(TOP_DIR, ".setuptools-cmake-build")
30 
31 WINDOWS = os.name == "nt"
32 
33 CMAKE = shutil.which("cmake3") or shutil.which("cmake")
34 
35 ################################################################################
36 # Global variables for controlling the build variant
37 ################################################################################
38 
39 # Default value is set to TRUE\1 to keep the settings same as the current ones.
40 # However going forward the recommended way to is to set this to False\0
41 ONNX_ML = os.getenv("ONNX_ML") != "0"
42 ONNX_VERIFY_PROTO3 = os.getenv("ONNX_VERIFY_PROTO3") == "1"
43 ONNX_NAMESPACE = os.getenv("ONNX_NAMESPACE", "onnx")
44 ONNX_BUILD_TESTS = os.getenv("ONNX_BUILD_TESTS") == "1"
45 ONNX_DISABLE_EXCEPTIONS = os.getenv("ONNX_DISABLE_EXCEPTIONS") == "1"
46 ONNX_DISABLE_STATIC_REGISTRATION = os.getenv("ONNX_DISABLE_STATIC_REGISTRATION") == "1"
47 ONNX_PREVIEW_BUILD = os.getenv("ONNX_PREVIEW_BUILD") == "1"
48 
49 USE_MSVC_STATIC_RUNTIME = os.getenv("USE_MSVC_STATIC_RUNTIME", "0") == "1"
50 DEBUG = os.getenv("DEBUG", "0") == "1"
51 COVERAGE = os.getenv("COVERAGE", "0") == "1"
52 
53 # Customize the wheel plat-name, usually needed for MacOS builds.
54 # See usage in .github/workflows/release_mac.yml
55 ONNX_WHEEL_PLATFORM_NAME = os.getenv("ONNX_WHEEL_PLATFORM_NAME")
56 
57 ################################################################################
58 # Pre Check
59 ################################################################################
60 
61 assert CMAKE, "Could not find cmake in PATH"
62 
63 ################################################################################
64 # Version
65 ################################################################################
66 
67 try:
68     _git_version = (
69         subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=TOP_DIR)
70         .decode("ascii")
71         .strip()
72     )
73 except (OSError, subprocess.CalledProcessError):
74     _git_version = ""
75 
76 with open(os.path.join(TOP_DIR, "VERSION_NUMBER"), encoding="utf-8") as version_file:
77     _version = version_file.read().strip()
78     if ONNX_PREVIEW_BUILD:
79         # Create the dev build for weekly releases
80         todays_date = datetime.date.today().strftime("%Y%m%d")
81         _version += ".dev" + todays_date
82     VERSION_INFO = {"version": _version, "git_version": _git_version}
83 
84 ################################################################################
85 # Utilities
86 ################################################################################
87 
88 
89 @contextlib.contextmanager
90 def cd(path):
91     if not os.path.isabs(path):
92         raise RuntimeError(f"Can only cd to absolute path, got: {path}")
93     orig_path = os.getcwd()
94     os.chdir(path)
95     try:
96         yield
97     finally:
98         os.chdir(orig_path)
99 
100 
101 def get_ext_suffix():
102     return sysconfig.get_config_var("EXT_SUFFIX")
103 
104 
105 ################################################################################
106 # Customized commands
107 ################################################################################
108 
109 
110 def create_version(directory: str):
111     """Create version.py based on VERSION_INFO."""
112     version_file_path = os.path.join(directory, "onnx", "version.py")
113     os.makedirs(os.path.dirname(version_file_path), exist_ok=True)
114 
115     with open(version_file_path, "w", encoding="utf-8") as f:
116         f.write(
117             textwrap.dedent(
118                 f"""\
119                 # This file is generated by setup.py. DO NOT EDIT!
120 
121 
122                 version = "{VERSION_INFO['version']}"
123                 git_version = "{VERSION_INFO['git_version']}"
124                 """
125             )
126         )
127 
128 
129 class CmakeBuild(setuptools.Command):
130     """Compiles everything when `python setup.py build` is run using cmake.
131 
132     Custom args can be passed to cmake by specifying the `CMAKE_ARGS`
133     environment variable.
134 
135     The number of CPUs used by `make` can be specified by passing `-j<ncpus>`
136     to `setup.py build`.  By default all CPUs are used.
137     """
138 
139     user_options: ClassVar[list] = [
140         ("jobs=", "j", "Specifies the number of jobs to use with make")
141     ]
142 
143     def initialize_options(self):
144         self.jobs = None
145 
146     def finalize_options(self):
147         self.set_undefined_options("build", ("parallel", "jobs"))
148         if self.jobs is None and os.getenv("MAX_JOBS") is not None:
149             self.jobs = os.getenv("MAX_JOBS")
150         self.jobs = multiprocessing.cpu_count() if self.jobs is None else int(self.jobs)
151 
152     def run(self):
153         os.makedirs(CMAKE_BUILD_DIR, exist_ok=True)
154 
155         with cd(CMAKE_BUILD_DIR):
156             build_type = "Release"
157             # configure
158             cmake_args = [
159                 CMAKE,
160                 f"-DPYTHON_INCLUDE_DIR={sysconfig.get_path('include')}",
161                 f"-DPYTHON_EXECUTABLE={sys.executable}",
162                 "-DBUILD_ONNX_PYTHON=ON",
163                 "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
164                 f"-DONNX_NAMESPACE={ONNX_NAMESPACE}",
165                 f"-DPY_EXT_SUFFIX={get_ext_suffix() or ''}",
166             ]
167             if COVERAGE:
168                 cmake_args.append("-DONNX_COVERAGE=ON")
169             if COVERAGE or DEBUG:
170                 # in order to get accurate coverage information, the
171                 # build needs to turn off optimizations
172                 build_type = "Debug"
173             cmake_args.append(f"-DCMAKE_BUILD_TYPE={build_type}")
174             if WINDOWS:
175                 cmake_args.extend(
176                     [
177                         # we need to link with libpython on windows, so
178                         # passing python version to window in order to
179                         # find python in cmake
180                         f"-DPY_VERSION={'{}.{}'.format(*sys.version_info[:2])}",
181                     ]
182                 )
183                 if USE_MSVC_STATIC_RUNTIME:
184                     cmake_args.append("-DONNX_USE_MSVC_STATIC_RUNTIME=ON")
185                 if platform.architecture()[0] == "64bit":
186                     if "arm" in platform.machine().lower():
187                         cmake_args.extend(["-A", "ARM64"])
188                     else:
189                         cmake_args.extend(["-A", "x64", "-T", "host=x64"])
190                 else:  # noqa: PLR5501
191                     if "arm" in platform.machine().lower():
192                         cmake_args.extend(["-A", "ARM"])
193                     else:
194                         cmake_args.extend(["-A", "Win32", "-T", "host=x86"])
195             if ONNX_ML:
196                 cmake_args.append("-DONNX_ML=1")
197             if ONNX_VERIFY_PROTO3:
198                 cmake_args.append("-DONNX_VERIFY_PROTO3=1")
199             if ONNX_BUILD_TESTS:
200                 cmake_args.append("-DONNX_BUILD_TESTS=ON")
201             if ONNX_DISABLE_EXCEPTIONS:
202                 cmake_args.append("-DONNX_DISABLE_EXCEPTIONS=ON")
203             if ONNX_DISABLE_STATIC_REGISTRATION:
204                 cmake_args.append("-DONNX_DISABLE_STATIC_REGISTRATION=ON")
205             if "CMAKE_ARGS" in os.environ:
206                 extra_cmake_args = shlex.split(os.environ["CMAKE_ARGS"])
207                 # prevent crossfire with downstream scripts
208                 del os.environ["CMAKE_ARGS"]
209                 logging.info("Extra cmake args: %s", extra_cmake_args)
210                 cmake_args.extend(extra_cmake_args)
211             cmake_args.append(TOP_DIR)
212             logging.info("Using cmake args: %s", cmake_args)
213             if "-DONNX_DISABLE_EXCEPTIONS=ON" in cmake_args:
214                 raise RuntimeError(
215                     "-DONNX_DISABLE_EXCEPTIONS=ON option is only available for c++ builds. Python binding require exceptions to be enabled."
216                 )
217             subprocess.check_call(cmake_args)
218 
219             build_args = [CMAKE, "--build", os.curdir]
220             if WINDOWS:
221                 build_args.extend(["--config", build_type])
222                 build_args.extend(["--", f"/maxcpucount:{self.jobs}"])
223             else:
224                 build_args.extend(["--", "-j", str(self.jobs)])
225             subprocess.check_call(build_args)
226 
227 
228 class BuildPy(setuptools.command.build_py.build_py):
229     def run(self):
230         if self.editable_mode:
231             dst_dir = TOP_DIR
232         else:
233             dst_dir = self.build_lib
234         create_version(dst_dir)
235         return super().run()
236 
237 
238 class Develop(setuptools.command.develop.develop):
239     def run(self):
240         create_version(TOP_DIR)
241         return super().run()
242 
243 
244 class BuildExt(setuptools.command.build_ext.build_ext):
245     def run(self):
246         self.run_command("cmake_build")
247         return super().run()
248 
249     def build_extensions(self):
250         # We override this method entirely because the actual building is done
251         # by cmake_build. Here we just copy the built extensions to the final
252         # destination.
253         build_lib = self.build_lib
254         extension_dst_dir = os.path.join(build_lib, "onnx")
255         os.makedirs(extension_dst_dir, exist_ok=True)
256 
257         for ext in self.extensions:
258             fullname = self.get_ext_fullname(ext.name)
259             filename = os.path.basename(self.get_ext_filename(fullname))
260 
261             if not WINDOWS:
262                 lib_dir = CMAKE_BUILD_DIR
263             else:
264                 # Windows compiled extensions are stored in Release/Debug subfolders
265                 debug_lib_dir = os.path.join(CMAKE_BUILD_DIR, "Debug")
266                 release_lib_dir = os.path.join(CMAKE_BUILD_DIR, "Release")
267                 if os.path.exists(debug_lib_dir):
268                     lib_dir = debug_lib_dir
269                 elif os.path.exists(release_lib_dir):
270                     lib_dir = release_lib_dir
271             src = os.path.join(lib_dir, filename)
272             dst = os.path.join(extension_dst_dir, filename)
273             self.copy_file(src, dst)
274 
275         # Copy over the generated python files to build/source dir depending on editable mode
276         if self.editable_mode:
277             dst_dir = TOP_DIR
278         else:
279             dst_dir = build_lib
280 
281         generated_py_files = glob.glob(os.path.join(CMAKE_BUILD_DIR, "onnx", "*.py"))
282         generated_pyi_files = glob.glob(os.path.join(CMAKE_BUILD_DIR, "onnx", "*.pyi"))
283         assert generated_py_files, "Bug: No generated python files found"
284         assert generated_pyi_files, "Bug: No generated python stubs found"
285         for src in (*generated_py_files, *generated_pyi_files):
286             dst = os.path.join(dst_dir, os.path.relpath(src, CMAKE_BUILD_DIR))
287             os.makedirs(os.path.dirname(dst), exist_ok=True)
288             self.copy_file(src, dst)
289 
290 
291 CMD_CLASS = {
292     "cmake_build": CmakeBuild,
293     "build_py": BuildPy,
294     "build_ext": BuildExt,
295     "develop": Develop,
296 }
297 
298 ################################################################################
299 # Extensions
300 ################################################################################
301 
302 EXT_MODULES = [setuptools.Extension(name="onnx.onnx_cpp2py_export", sources=[])]
303 
304 
305 ################################################################################
306 # Final
307 ################################################################################
308 
309 setuptools.setup(
310     ext_modules=EXT_MODULES,
311     cmdclass=CMD_CLASS,
312     version=VERSION_INFO["version"],
313     options={"bdist_wheel": {"plat_name": ONNX_WHEEL_PLATFORM_NAME}}
314     if ONNX_WHEEL_PLATFORM_NAME is not None
315     else {},
316 )
317
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -50,8 +50,8 @@
 DEBUG = os.getenv("DEBUG", "0") == "1"
 COVERAGE = os.getenv("COVERAGE", "0") == "1"
 
-# Customize the wheel plat-name, usually needed for MacOS builds.
-# See usage in .github/workflows/release_mac.yml
+# Customize the wheel plat-name; sometimes useful for MacOS builds.
+# See https://github.com/onnx/onnx/pull/6117
 ONNX_WHEEL_PLATFORM_NAME = os.getenv("ONNX_WHEEL_PLATFORM_NAME")
 
 ################################################################################

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -50,8 +50,8 @@\n DEBUG = os.getenv(\"DEBUG\", \"0\") == \"1\"\n COVERAGE = os.getenv(\"COVERAGE\", \"0\") == \"1\"\n \n-# Customize the wheel plat-name, usually needed for MacOS builds.\n-# See usage in .github/workflows/release_mac.yml\n+# Customize the wheel plat-name; sometimes useful for MacOS builds.\n+# See https://github.com/onnx/onnx/pull/6117\n ONNX_WHEEL_PLATFORM_NAME = os.getenv(\"ONNX_WHEEL_PLATFORM_NAME\")\n \n ################################################################################\n", "issue": "MacOS release action is failing.\n### Description\r\n\r\n(https://github.com/actions/setup-python/issues/855)\r\n\r\n### Motivation and Context\r\n<!-- - Why is this change required? What problem does it solve? -->\r\n<!-- - If it fixes an open issue, please link to the issue here. -->\r\n\n", "before_files": [{"content": "# Copyright (c) ONNX Project Contributors\n#\n# SPDX-License-Identifier: Apache-2.0\n\n# NOTE: Put all metadata in pyproject.toml.\n# Set the environment variable `ONNX_PREVIEW_BUILD=1` to build the dev preview release.\n\nimport contextlib\nimport datetime\nimport glob\nimport logging\nimport multiprocessing\nimport os\nimport platform\nimport shlex\nimport shutil\nimport subprocess\nimport sys\nimport sysconfig\nimport textwrap\nfrom typing import ClassVar\n\nimport setuptools\nimport setuptools.command.build_ext\nimport setuptools.command.build_py\nimport setuptools.command.develop\n\nTOP_DIR = os.path.realpath(os.path.dirname(__file__))\nCMAKE_BUILD_DIR = os.path.join(TOP_DIR, \".setuptools-cmake-build\")\n\nWINDOWS = os.name == \"nt\"\n\nCMAKE = shutil.which(\"cmake3\") or shutil.which(\"cmake\")\n\n################################################################################\n# Global variables for controlling the build variant\n################################################################################\n\n# Default value is set to TRUE\\1 to keep the settings same as the current ones.\n# However going forward the recommended way to is to set this to False\\0\nONNX_ML = os.getenv(\"ONNX_ML\") != \"0\"\nONNX_VERIFY_PROTO3 = os.getenv(\"ONNX_VERIFY_PROTO3\") == \"1\"\nONNX_NAMESPACE = os.getenv(\"ONNX_NAMESPACE\", \"onnx\")\nONNX_BUILD_TESTS = os.getenv(\"ONNX_BUILD_TESTS\") == \"1\"\nONNX_DISABLE_EXCEPTIONS = os.getenv(\"ONNX_DISABLE_EXCEPTIONS\") == \"1\"\nONNX_DISABLE_STATIC_REGISTRATION = os.getenv(\"ONNX_DISABLE_STATIC_REGISTRATION\") == \"1\"\nONNX_PREVIEW_BUILD = os.getenv(\"ONNX_PREVIEW_BUILD\") == \"1\"\n\nUSE_MSVC_STATIC_RUNTIME = os.getenv(\"USE_MSVC_STATIC_RUNTIME\", \"0\") == \"1\"\nDEBUG = os.getenv(\"DEBUG\", \"0\") == \"1\"\nCOVERAGE = os.getenv(\"COVERAGE\", \"0\") == \"1\"\n\n# Customize the wheel plat-name, usually needed for MacOS builds.\n# See usage in .github/workflows/release_mac.yml\nONNX_WHEEL_PLATFORM_NAME = os.getenv(\"ONNX_WHEEL_PLATFORM_NAME\")\n\n################################################################################\n# Pre Check\n################################################################################\n\nassert CMAKE, \"Could not find cmake in PATH\"\n\n################################################################################\n# Version\n################################################################################\n\ntry:\n    _git_version = (\n        subprocess.check_output([\"git\", \"rev-parse\", \"HEAD\"], cwd=TOP_DIR)\n        .decode(\"ascii\")\n        .strip()\n    )\nexcept (OSError, subprocess.CalledProcessError):\n    _git_version = \"\"\n\nwith open(os.path.join(TOP_DIR, \"VERSION_NUMBER\"), encoding=\"utf-8\") as version_file:\n    _version = version_file.read().strip()\n    if ONNX_PREVIEW_BUILD:\n        # Create the dev build for weekly releases\n        todays_date = datetime.date.today().strftime(\"%Y%m%d\")\n        _version += \".dev\" + todays_date\n    VERSION_INFO = {\"version\": _version, \"git_version\": _git_version}\n\n################################################################################\n# Utilities\n################################################################################\n\n\n@contextlib.contextmanager\ndef cd(path):\n    if not os.path.isabs(path):\n        raise RuntimeError(f\"Can only cd to absolute path, got: {path}\")\n    orig_path = os.getcwd()\n    os.chdir(path)\n    try:\n        yield\n    finally:\n        os.chdir(orig_path)\n\n\ndef get_ext_suffix():\n    return sysconfig.get_config_var(\"EXT_SUFFIX\")\n\n\n################################################################################\n# Customized commands\n################################################################################\n\n\ndef create_version(directory: str):\n    \"\"\"Create version.py based on VERSION_INFO.\"\"\"\n    version_file_path = os.path.join(directory, \"onnx\", \"version.py\")\n    os.makedirs(os.path.dirname(version_file_path), exist_ok=True)\n\n    with open(version_file_path, \"w\", encoding=\"utf-8\") as f:\n        f.write(\n            textwrap.dedent(\n                f\"\"\"\\\n                # This file is generated by setup.py. DO NOT EDIT!\n\n\n                version = \"{VERSION_INFO['version']}\"\n                git_version = \"{VERSION_INFO['git_version']}\"\n                \"\"\"\n            )\n        )\n\n\nclass CmakeBuild(setuptools.Command):\n    \"\"\"Compiles everything when `python setup.py build` is run using cmake.\n\n    Custom args can be passed to cmake by specifying the `CMAKE_ARGS`\n    environment variable.\n\n    The number of CPUs used by `make` can be specified by passing `-j<ncpus>`\n    to `setup.py build`.  By default all CPUs are used.\n    \"\"\"\n\n    user_options: ClassVar[list] = [\n        (\"jobs=\", \"j\", \"Specifies the number of jobs to use with make\")\n    ]\n\n    def initialize_options(self):\n        self.jobs = None\n\n    def finalize_options(self):\n        self.set_undefined_options(\"build\", (\"parallel\", \"jobs\"))\n        if self.jobs is None and os.getenv(\"MAX_JOBS\") is not None:\n            self.jobs = os.getenv(\"MAX_JOBS\")\n        self.jobs = multiprocessing.cpu_count() if self.jobs is None else int(self.jobs)\n\n    def run(self):\n        os.makedirs(CMAKE_BUILD_DIR, exist_ok=True)\n\n        with cd(CMAKE_BUILD_DIR):\n            build_type = \"Release\"\n            # configure\n            cmake_args = [\n                CMAKE,\n                f\"-DPYTHON_INCLUDE_DIR={sysconfig.get_path('include')}\",\n                f\"-DPYTHON_EXECUTABLE={sys.executable}\",\n                \"-DBUILD_ONNX_PYTHON=ON\",\n                \"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON\",\n                f\"-DONNX_NAMESPACE={ONNX_NAMESPACE}\",\n                f\"-DPY_EXT_SUFFIX={get_ext_suffix() or ''}\",\n            ]\n            if COVERAGE:\n                cmake_args.append(\"-DONNX_COVERAGE=ON\")\n            if COVERAGE or DEBUG:\n                # in order to get accurate coverage information, the\n                # build needs to turn off optimizations\n                build_type = \"Debug\"\n            cmake_args.append(f\"-DCMAKE_BUILD_TYPE={build_type}\")\n            if WINDOWS:\n                cmake_args.extend(\n                    [\n                        # we need to link with libpython on windows, so\n                        # passing python version to window in order to\n                        # find python in cmake\n                        f\"-DPY_VERSION={'{}.{}'.format(*sys.version_info[:2])}\",\n                    ]\n                )\n                if USE_MSVC_STATIC_RUNTIME:\n                    cmake_args.append(\"-DONNX_USE_MSVC_STATIC_RUNTIME=ON\")\n                if platform.architecture()[0] == \"64bit\":\n                    if \"arm\" in platform.machine().lower():\n                        cmake_args.extend([\"-A\", \"ARM64\"])\n                    else:\n                        cmake_args.extend([\"-A\", \"x64\", \"-T\", \"host=x64\"])\n                else:  # noqa: PLR5501\n                    if \"arm\" in platform.machine().lower():\n                        cmake_args.extend([\"-A\", \"ARM\"])\n                    else:\n                        cmake_args.extend([\"-A\", \"Win32\", \"-T\", \"host=x86\"])\n            if ONNX_ML:\n                cmake_args.append(\"-DONNX_ML=1\")\n            if ONNX_VERIFY_PROTO3:\n                cmake_args.append(\"-DONNX_VERIFY_PROTO3=1\")\n            if ONNX_BUILD_TESTS:\n                cmake_args.append(\"-DONNX_BUILD_TESTS=ON\")\n            if ONNX_DISABLE_EXCEPTIONS:\n                cmake_args.append(\"-DONNX_DISABLE_EXCEPTIONS=ON\")\n            if ONNX_DISABLE_STATIC_REGISTRATION:\n                cmake_args.append(\"-DONNX_DISABLE_STATIC_REGISTRATION=ON\")\n            if \"CMAKE_ARGS\" in os.environ:\n                extra_cmake_args = shlex.split(os.environ[\"CMAKE_ARGS\"])\n                # prevent crossfire with downstream scripts\n                del os.environ[\"CMAKE_ARGS\"]\n                logging.info(\"Extra cmake args: %s\", extra_cmake_args)\n                cmake_args.extend(extra_cmake_args)\n            cmake_args.append(TOP_DIR)\n            logging.info(\"Using cmake args: %s\", cmake_args)\n            if \"-DONNX_DISABLE_EXCEPTIONS=ON\" in cmake_args:\n                raise RuntimeError(\n                    \"-DONNX_DISABLE_EXCEPTIONS=ON option is only available for c++ builds. Python binding require exceptions to be enabled.\"\n                )\n            subprocess.check_call(cmake_args)\n\n            build_args = [CMAKE, \"--build\", os.curdir]\n            if WINDOWS:\n                build_args.extend([\"--config\", build_type])\n                build_args.extend([\"--\", f\"/maxcpucount:{self.jobs}\"])\n            else:\n                build_args.extend([\"--\", \"-j\", str(self.jobs)])\n            subprocess.check_call(build_args)\n\n\nclass BuildPy(setuptools.command.build_py.build_py):\n    def run(self):\n        if self.editable_mode:\n            dst_dir = TOP_DIR\n        else:\n            dst_dir = self.build_lib\n        create_version(dst_dir)\n        return super().run()\n\n\nclass Develop(setuptools.command.develop.develop):\n    def run(self):\n        create_version(TOP_DIR)\n        return super().run()\n\n\nclass BuildExt(setuptools.command.build_ext.build_ext):\n    def run(self):\n        self.run_command(\"cmake_build\")\n        return super().run()\n\n    def build_extensions(self):\n        # We override this method entirely because the actual building is done\n        # by cmake_build. Here we just copy the built extensions to the final\n        # destination.\n        build_lib = self.build_lib\n        extension_dst_dir = os.path.join(build_lib, \"onnx\")\n        os.makedirs(extension_dst_dir, exist_ok=True)\n\n        for ext in self.extensions:\n            fullname = self.get_ext_fullname(ext.name)\n            filename = os.path.basename(self.get_ext_filename(fullname))\n\n            if not WINDOWS:\n                lib_dir = CMAKE_BUILD_DIR\n            else:\n                # Windows compiled extensions are stored in Release/Debug subfolders\n                debug_lib_dir = os.path.join(CMAKE_BUILD_DIR, \"Debug\")\n                release_lib_dir = os.path.join(CMAKE_BUILD_DIR, \"Release\")\n                if os.path.exists(debug_lib_dir):\n                    lib_dir = debug_lib_dir\n                elif os.path.exists(release_lib_dir):\n                    lib_dir = release_lib_dir\n            src = os.path.join(lib_dir, filename)\n            dst = os.path.join(extension_dst_dir, filename)\n            self.copy_file(src, dst)\n\n        # Copy over the generated python files to build/source dir depending on editable mode\n        if self.editable_mode:\n            dst_dir = TOP_DIR\n        else:\n            dst_dir = build_lib\n\n        generated_py_files = glob.glob(os.path.join(CMAKE_BUILD_DIR, \"onnx\", \"*.py\"))\n        generated_pyi_files = glob.glob(os.path.join(CMAKE_BUILD_DIR, \"onnx\", \"*.pyi\"))\n        assert generated_py_files, \"Bug: No generated python files found\"\n        assert generated_pyi_files, \"Bug: No generated python stubs found\"\n        for src in (*generated_py_files, *generated_pyi_files):\n            dst = os.path.join(dst_dir, os.path.relpath(src, CMAKE_BUILD_DIR))\n            os.makedirs(os.path.dirname(dst), exist_ok=True)\n            self.copy_file(src, dst)\n\n\nCMD_CLASS = {\n    \"cmake_build\": CmakeBuild,\n    \"build_py\": BuildPy,\n    \"build_ext\": BuildExt,\n    \"develop\": Develop,\n}\n\n################################################################################\n# Extensions\n################################################################################\n\nEXT_MODULES = [setuptools.Extension(name=\"onnx.onnx_cpp2py_export\", sources=[])]\n\n\n################################################################################\n# Final\n################################################################################\n\nsetuptools.setup(\n    ext_modules=EXT_MODULES,\n    cmdclass=CMD_CLASS,\n    version=VERSION_INFO[\"version\"],\n    options={\"bdist_wheel\": {\"plat_name\": ONNX_WHEEL_PLATFORM_NAME}}\n    if ONNX_WHEEL_PLATFORM_NAME is not None\n    else {},\n)\n", "path": "setup.py"}], "after_files": [{"content": "# Copyright (c) ONNX Project Contributors\n#\n# SPDX-License-Identifier: Apache-2.0\n\n# NOTE: Put all metadata in pyproject.toml.\n# Set the environment variable `ONNX_PREVIEW_BUILD=1` to build the dev preview release.\n\nimport contextlib\nimport datetime\nimport glob\nimport logging\nimport multiprocessing\nimport os\nimport platform\nimport shlex\nimport shutil\nimport subprocess\nimport sys\nimport sysconfig\nimport textwrap\nfrom typing import ClassVar\n\nimport setuptools\nimport setuptools.command.build_ext\nimport setuptools.command.build_py\nimport setuptools.command.develop\n\nTOP_DIR = os.path.realpath(os.path.dirname(__file__))\nCMAKE_BUILD_DIR = os.path.join(TOP_DIR, \".setuptools-cmake-build\")\n\nWINDOWS = os.name == \"nt\"\n\nCMAKE = shutil.which(\"cmake3\") or shutil.which(\"cmake\")\n\n################################################################################\n# Global variables for controlling the build variant\n################################################################################\n\n# Default value is set to TRUE\\1 to keep the settings same as the current ones.\n# However going forward the recommended way to is to set this to False\\0\nONNX_ML = os.getenv(\"ONNX_ML\") != \"0\"\nONNX_VERIFY_PROTO3 = os.getenv(\"ONNX_VERIFY_PROTO3\") == \"1\"\nONNX_NAMESPACE = os.getenv(\"ONNX_NAMESPACE\", \"onnx\")\nONNX_BUILD_TESTS = os.getenv(\"ONNX_BUILD_TESTS\") == \"1\"\nONNX_DISABLE_EXCEPTIONS = os.getenv(\"ONNX_DISABLE_EXCEPTIONS\") == \"1\"\nONNX_DISABLE_STATIC_REGISTRATION = os.getenv(\"ONNX_DISABLE_STATIC_REGISTRATION\") == \"1\"\nONNX_PREVIEW_BUILD = os.getenv(\"ONNX_PREVIEW_BUILD\") == \"1\"\n\nUSE_MSVC_STATIC_RUNTIME = os.getenv(\"USE_MSVC_STATIC_RUNTIME\", \"0\") == \"1\"\nDEBUG = os.getenv(\"DEBUG\", \"0\") == \"1\"\nCOVERAGE = os.getenv(\"COVERAGE\", \"0\") == \"1\"\n\n# Customize the wheel plat-name; sometimes useful for MacOS builds.\n# See https://github.com/onnx/onnx/pull/6117\nONNX_WHEEL_PLATFORM_NAME = os.getenv(\"ONNX_WHEEL_PLATFORM_NAME\")\n\n################################################################################\n# Pre Check\n################################################################################\n\nassert CMAKE, \"Could not find cmake in PATH\"\n\n################################################################################\n# Version\n################################################################################\n\ntry:\n    _git_version = (\n        subprocess.check_output([\"git\", \"rev-parse\", \"HEAD\"], cwd=TOP_DIR)\n        .decode(\"ascii\")\n        .strip()\n    )\nexcept (OSError, subprocess.CalledProcessError):\n    _git_version = \"\"\n\nwith open(os.path.join(TOP_DIR, \"VERSION_NUMBER\"), encoding=\"utf-8\") as version_file:\n    _version = version_file.read().strip()\n    if ONNX_PREVIEW_BUILD:\n        # Create the dev build for weekly releases\n        todays_date = datetime.date.today().strftime(\"%Y%m%d\")\n        _version += \".dev\" + todays_date\n    VERSION_INFO = {\"version\": _version, \"git_version\": _git_version}\n\n################################################################################\n# Utilities\n################################################################################\n\n\n@contextlib.contextmanager\ndef cd(path):\n    if not os.path.isabs(path):\n        raise RuntimeError(f\"Can only cd to absolute path, got: {path}\")\n    orig_path = os.getcwd()\n    os.chdir(path)\n    try:\n        yield\n    finally:\n        os.chdir(orig_path)\n\n\ndef get_ext_suffix():\n    return sysconfig.get_config_var(\"EXT_SUFFIX\")\n\n\n################################################################################\n# Customized commands\n################################################################################\n\n\ndef create_version(directory: str):\n    \"\"\"Create version.py based on VERSION_INFO.\"\"\"\n    version_file_path = os.path.join(directory, \"onnx\", \"version.py\")\n    os.makedirs(os.path.dirname(version_file_path), exist_ok=True)\n\n    with open(version_file_path, \"w\", encoding=\"utf-8\") as f:\n        f.write(\n            textwrap.dedent(\n                f\"\"\"\\\n                # This file is generated by setup.py. DO NOT EDIT!\n\n\n                version = \"{VERSION_INFO['version']}\"\n                git_version = \"{VERSION_INFO['git_version']}\"\n                \"\"\"\n            )\n        )\n\n\nclass CmakeBuild(setuptools.Command):\n    \"\"\"Compiles everything when `python setup.py build` is run using cmake.\n\n    Custom args can be passed to cmake by specifying the `CMAKE_ARGS`\n    environment variable.\n\n    The number of CPUs used by `make` can be specified by passing `-j<ncpus>`\n    to `setup.py build`.  By default all CPUs are used.\n    \"\"\"\n\n    user_options: ClassVar[list] = [\n        (\"jobs=\", \"j\", \"Specifies the number of jobs to use with make\")\n    ]\n\n    def initialize_options(self):\n        self.jobs = None\n\n    def finalize_options(self):\n        self.set_undefined_options(\"build\", (\"parallel\", \"jobs\"))\n        if self.jobs is None and os.getenv(\"MAX_JOBS\") is not None:\n            self.jobs = os.getenv(\"MAX_JOBS\")\n        self.jobs = multiprocessing.cpu_count() if self.jobs is None else int(self.jobs)\n\n    def run(self):\n        os.makedirs(CMAKE_BUILD_DIR, exist_ok=True)\n\n        with cd(CMAKE_BUILD_DIR):\n            build_type = \"Release\"\n            # configure\n            cmake_args = [\n                CMAKE,\n                f\"-DPYTHON_INCLUDE_DIR={sysconfig.get_path('include')}\",\n                f\"-DPYTHON_EXECUTABLE={sys.executable}\",\n                \"-DBUILD_ONNX_PYTHON=ON\",\n                \"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON\",\n                f\"-DONNX_NAMESPACE={ONNX_NAMESPACE}\",\n                f\"-DPY_EXT_SUFFIX={get_ext_suffix() or ''}\",\n            ]\n            if COVERAGE:\n                cmake_args.append(\"-DONNX_COVERAGE=ON\")\n            if COVERAGE or DEBUG:\n                # in order to get accurate coverage information, the\n                # build needs to turn off optimizations\n                build_type = \"Debug\"\n            cmake_args.append(f\"-DCMAKE_BUILD_TYPE={build_type}\")\n            if WINDOWS:\n                cmake_args.extend(\n                    [\n                        # we need to link with libpython on windows, so\n                        # passing python version to window in order to\n                        # find python in cmake\n                        f\"-DPY_VERSION={'{}.{}'.format(*sys.version_info[:2])}\",\n                    ]\n                )\n                if USE_MSVC_STATIC_RUNTIME:\n                    cmake_args.append(\"-DONNX_USE_MSVC_STATIC_RUNTIME=ON\")\n                if platform.architecture()[0] == \"64bit\":\n                    if \"arm\" in platform.machine().lower():\n                        cmake_args.extend([\"-A\", \"ARM64\"])\n                    else:\n                        cmake_args.extend([\"-A\", \"x64\", \"-T\", \"host=x64\"])\n                else:  # noqa: PLR5501\n                    if \"arm\" in platform.machine().lower():\n                        cmake_args.extend([\"-A\", \"ARM\"])\n                    else:\n                        cmake_args.extend([\"-A\", \"Win32\", \"-T\", \"host=x86\"])\n            if ONNX_ML:\n                cmake_args.append(\"-DONNX_ML=1\")\n            if ONNX_VERIFY_PROTO3:\n                cmake_args.append(\"-DONNX_VERIFY_PROTO3=1\")\n            if ONNX_BUILD_TESTS:\n                cmake_args.append(\"-DONNX_BUILD_TESTS=ON\")\n            if ONNX_DISABLE_EXCEPTIONS:\n                cmake_args.append(\"-DONNX_DISABLE_EXCEPTIONS=ON\")\n            if ONNX_DISABLE_STATIC_REGISTRATION:\n                cmake_args.append(\"-DONNX_DISABLE_STATIC_REGISTRATION=ON\")\n            if \"CMAKE_ARGS\" in os.environ:\n                extra_cmake_args = shlex.split(os.environ[\"CMAKE_ARGS\"])\n                # prevent crossfire with downstream scripts\n                del os.environ[\"CMAKE_ARGS\"]\n                logging.info(\"Extra cmake args: %s\", extra_cmake_args)\n                cmake_args.extend(extra_cmake_args)\n            cmake_args.append(TOP_DIR)\n            logging.info(\"Using cmake args: %s\", cmake_args)\n            if \"-DONNX_DISABLE_EXCEPTIONS=ON\" in cmake_args:\n                raise RuntimeError(\n                    \"-DONNX_DISABLE_EXCEPTIONS=ON option is only available for c++ builds. Python binding require exceptions to be enabled.\"\n                )\n            subprocess.check_call(cmake_args)\n\n            build_args = [CMAKE, \"--build\", os.curdir]\n            if WINDOWS:\n                build_args.extend([\"--config\", build_type])\n                build_args.extend([\"--\", f\"/maxcpucount:{self.jobs}\"])\n            else:\n                build_args.extend([\"--\", \"-j\", str(self.jobs)])\n            subprocess.check_call(build_args)\n\n\nclass BuildPy(setuptools.command.build_py.build_py):\n    def run(self):\n        if self.editable_mode:\n            dst_dir = TOP_DIR\n        else:\n            dst_dir = self.build_lib\n        create_version(dst_dir)\n        return super().run()\n\n\nclass Develop(setuptools.command.develop.develop):\n    def run(self):\n        create_version(TOP_DIR)\n        return super().run()\n\n\nclass BuildExt(setuptools.command.build_ext.build_ext):\n    def run(self):\n        self.run_command(\"cmake_build\")\n        return super().run()\n\n    def build_extensions(self):\n        # We override this method entirely because the actual building is done\n        # by cmake_build. Here we just copy the built extensions to the final\n        # destination.\n        build_lib = self.build_lib\n        extension_dst_dir = os.path.join(build_lib, \"onnx\")\n        os.makedirs(extension_dst_dir, exist_ok=True)\n\n        for ext in self.extensions:\n            fullname = self.get_ext_fullname(ext.name)\n            filename = os.path.basename(self.get_ext_filename(fullname))\n\n            if not WINDOWS:\n                lib_dir = CMAKE_BUILD_DIR\n            else:\n                # Windows compiled extensions are stored in Release/Debug subfolders\n                debug_lib_dir = os.path.join(CMAKE_BUILD_DIR, \"Debug\")\n                release_lib_dir = os.path.join(CMAKE_BUILD_DIR, \"Release\")\n                if os.path.exists(debug_lib_dir):\n                    lib_dir = debug_lib_dir\n                elif os.path.exists(release_lib_dir):\n                    lib_dir = release_lib_dir\n            src = os.path.join(lib_dir, filename)\n            dst = os.path.join(extension_dst_dir, filename)\n            self.copy_file(src, dst)\n\n        # Copy over the generated python files to build/source dir depending on editable mode\n        if self.editable_mode:\n            dst_dir = TOP_DIR\n        else:\n            dst_dir = build_lib\n\n        generated_py_files = glob.glob(os.path.join(CMAKE_BUILD_DIR, \"onnx\", \"*.py\"))\n        generated_pyi_files = glob.glob(os.path.join(CMAKE_BUILD_DIR, \"onnx\", \"*.pyi\"))\n        assert generated_py_files, \"Bug: No generated python files found\"\n        assert generated_pyi_files, \"Bug: No generated python stubs found\"\n        for src in (*generated_py_files, *generated_pyi_files):\n            dst = os.path.join(dst_dir, os.path.relpath(src, CMAKE_BUILD_DIR))\n            os.makedirs(os.path.dirname(dst), exist_ok=True)\n            self.copy_file(src, dst)\n\n\nCMD_CLASS = {\n    \"cmake_build\": CmakeBuild,\n    \"build_py\": BuildPy,\n    \"build_ext\": BuildExt,\n    \"develop\": Develop,\n}\n\n################################################################################\n# Extensions\n################################################################################\n\nEXT_MODULES = [setuptools.Extension(name=\"onnx.onnx_cpp2py_export\", sources=[])]\n\n\n################################################################################\n# Final\n################################################################################\n\nsetuptools.setup(\n    ext_modules=EXT_MODULES,\n    cmdclass=CMD_CLASS,\n    version=VERSION_INFO[\"version\"],\n    options={\"bdist_wheel\": {\"plat_name\": ONNX_WHEEL_PLATFORM_NAME}}\n    if ONNX_WHEEL_PLATFORM_NAME is not None\n    else {},\n)\n", "path": "setup.py"}]}