Replace distutils by setuptools to import build_ext (#14108)

### Description
Uses setuptools instead of distutils.



### Motivation and Context
Fixes #14107.
This commit is contained in:
Xavier Dupré 2023-01-09 11:48:01 +01:00 committed by GitHub
parent 64541a587d
commit 79dc39600f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 13 deletions

View file

@ -1,10 +1,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# pylint: disable=W0622
"""Test export of PyTorch operators using ONNX Runtime contrib ops."""
import copy
import distutils.version
import io
import unittest
@ -18,7 +18,9 @@ from onnxruntime.tools import pytorch_export_contrib_ops
def _torch_version_lower_than(version: str):
return distutils.version.LooseVersion(torch.__version__) < distutils.version.LooseVersion(version)
from packaging.version import Version as LooseVersion # pylint: disable=C0415
return LooseVersion(torch.__version__) < LooseVersion(version)
def ort_test_with_input(ort_sess, input, output, rtol, atol):

View file

@ -1,7 +1,7 @@
import io
import os
import warnings
from distutils.version import LooseVersion
from packaging.version import Version as LooseVersion
import numpy as np
import onnx

View file

@ -12,8 +12,8 @@ import random
import traceback
import types
import warnings
from distutils.version import LooseVersion
from typing import List
from packaging.version import Version as LooseVersion
import numpy as np
import torch

View file

@ -1,10 +1,8 @@
import inspect
import math
import os
import tempfile
from distutils.version import StrictVersion
from functools import partial
from packaging.version import Version as StrictVersion
import _test_commons
import _test_helpers
import onnx

View file

@ -2,13 +2,13 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# ------------------------------------------------------------------------
# pylint: disable=C0103
import datetime
import logging
import platform
import subprocess
import sys
from distutils import log as logger
from distutils.command.build_ext import build_ext as _build_ext
from glob import glob, iglob
from os import environ, getcwd, path, popen, remove
from pathlib import Path
@ -16,11 +16,13 @@ from shutil import copyfile
from packaging.tags import sys_tags
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.install import install as InstallCommandBase
nightly_build = False
package_name = "onnxruntime"
wheel_name_suffix = None
logger = logging.getLogger()
def parse_arg_remove_boolean(argv, arg_name):
@ -162,7 +164,7 @@ try:
f.write(' os.environ["ORT_CUDA_UNAVAILABLE"] = "1"\n')
def _rewrite_ld_preload_tensorrt(self, to_preload):
with open("onnxruntime/capi/_ld_preload.py", "a") as f:
with open("onnxruntime/capi/_ld_preload.py", "a", encoding="ascii") as f:
if len(to_preload) > 0:
f.write("from ctypes import CDLL, RTLD_GLOBAL\n")
f.write("try:\n")
@ -447,8 +449,8 @@ if not path.exists(README):
if not path.exists(README):
raise FileNotFoundError("Unable to find 'README.rst'")
with open(README) as f:
long_description = f.read()
with open(README, "r", encoding="utf-8") as fdesc:
long_description = fdesc.read()
# Include files in onnxruntime/external if --enable_external_custom_op_schemas build.sh command
# line option is specified.

View file

@ -11,9 +11,15 @@ import shlex
import shutil
import subprocess
import sys
from distutils.version import LooseVersion
from pathlib import Path
try:
from packaging.version import Version as LooseVersion
except ImportError:
# This is deprecated and will be removed in Python 3.12.
# See https://docs.python.org/3/library/distutils.html.
from distutils.version import LooseVersion # pylint: disable=W4901
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", ".."))

View file

@ -1,4 +1,5 @@
# packages used by transformers tool test
packaging
protobuf==3.20.1
numpy==1.23.5
coloredlogs==15.0