2020-10-20 22:53:14 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
|
|
# license information.
|
|
|
|
###########################################################################
|
|
|
|
|
|
|
|
import os
|
2021-01-12 00:44:17 +03:00
|
|
|
import sys
|
|
|
|
import pathlib
|
2023-11-28 02:39:52 +03:00
|
|
|
import setuptools
|
2021-01-12 00:44:17 +03:00
|
|
|
|
2023-11-28 02:39:52 +03:00
|
|
|
from setuptools import setup, find_packages
|
2021-01-12 00:44:17 +03:00
|
|
|
|
2021-09-25 10:40:12 +03:00
|
|
|
TOP_DIR = os.path.dirname(__file__) or os.getcwd()
|
2024-02-16 01:09:04 +03:00
|
|
|
PACKAGE_NAME = "onnxruntime_extensions"
|
2021-01-12 00:44:17 +03:00
|
|
|
|
2023-11-28 02:39:52 +03:00
|
|
|
# setup.py cannot be debugged in pip command line, so the command classes are refactored into another file
|
2024-02-16 01:09:04 +03:00
|
|
|
cmds_dir = pathlib.Path(TOP_DIR) / ".pyproject"
|
2023-11-28 02:39:52 +03:00
|
|
|
sys.path.append(str(cmds_dir))
|
|
|
|
# noinspection PyUnresolvedReferences
|
|
|
|
import cmdclass as _cmds # noqa: E402
|
2023-05-22 07:40:11 +03:00
|
|
|
|
2023-11-28 02:39:52 +03:00
|
|
|
_cmds.prepare_env(TOP_DIR)
|
2023-01-24 00:52:18 +03:00
|
|
|
|
|
|
|
|
2020-10-20 22:53:14 +03:00
|
|
|
# read version from the package file.
|
2021-01-12 00:44:17 +03:00
|
|
|
def read_version():
|
2024-02-16 01:09:04 +03:00
|
|
|
version_str = "0.1.0"
|
|
|
|
with open(os.path.join(TOP_DIR, "version.txt"), "r") as f:
|
2023-01-13 01:28:32 +03:00
|
|
|
version_str = f.readline().strip()
|
2021-09-25 10:40:12 +03:00
|
|
|
|
2023-03-03 01:12:31 +03:00
|
|
|
# special handling for Onebranch building
|
2024-02-16 01:09:04 +03:00
|
|
|
if os.getenv("BUILD_SOURCEBRANCHNAME", "").startswith("rel-"):
|
2023-03-03 01:12:31 +03:00
|
|
|
return version_str
|
|
|
|
|
2021-09-29 23:18:36 +03:00
|
|
|
# is it a dev build or release?
|
2024-02-16 01:09:04 +03:00
|
|
|
rel_br, cid = _cmds.read_git_refs(TOP_DIR) if os.path.isdir(os.path.join(TOP_DIR, ".git")) else (True, None)
|
2023-03-03 01:12:31 +03:00
|
|
|
|
|
|
|
if rel_br:
|
|
|
|
return version_str
|
|
|
|
|
2024-02-16 01:09:04 +03:00
|
|
|
build_id = os.getenv("BUILD_BUILDID", None)
|
2022-08-25 00:39:33 +03:00
|
|
|
if build_id is not None:
|
2024-02-16 01:09:04 +03:00
|
|
|
version_str += ".{}".format(build_id)
|
2022-08-25 00:39:33 +03:00
|
|
|
else:
|
2024-02-16 01:09:04 +03:00
|
|
|
version_str += "+" + cid[:7]
|
2021-01-12 00:44:17 +03:00
|
|
|
return version_str
|
|
|
|
|
2023-01-24 00:52:18 +03:00
|
|
|
|
2023-11-28 02:39:52 +03:00
|
|
|
def write_py_version(ext_version):
|
2024-02-16 01:09:04 +03:00
|
|
|
text = ["# Generated by setup.py, DON'T MANUALLY UPDATE IT!\n", '__version__ = "{}"\n'.format(ext_version)]
|
|
|
|
with open(os.path.join(TOP_DIR, "onnxruntime_extensions/_version.py"), "w") as _fver:
|
2023-11-28 02:39:52 +03:00
|
|
|
_fver.writelines(text)
|
2023-01-24 00:52:18 +03:00
|
|
|
|
2021-01-12 00:44:17 +03:00
|
|
|
|
2024-02-16 01:09:04 +03:00
|
|
|
ext_modules = [setuptools.extension.Extension(name=str("onnxruntime_extensions._extensions_pydll"), sources=[])]
|
2020-10-20 22:53:14 +03:00
|
|
|
|
2021-04-13 00:27:10 +03:00
|
|
|
packages = find_packages()
|
2024-02-16 01:09:04 +03:00
|
|
|
package_dir = {k: os.path.join(".", k.replace(".", "/")) for k in packages}
|
2021-04-13 00:27:10 +03:00
|
|
|
package_data = {
|
2021-09-29 23:18:36 +03:00
|
|
|
"onnxruntime_extensions": ["*.so", "*.pyd"],
|
2021-04-13 00:27:10 +03:00
|
|
|
}
|
2020-10-20 22:53:14 +03:00
|
|
|
|
2024-02-16 01:09:04 +03:00
|
|
|
long_description = ""
|
|
|
|
with open(os.path.join(TOP_DIR, "README.md"), "r", encoding="utf-8") as _f:
|
2022-05-12 02:51:59 +03:00
|
|
|
long_description += _f.read()
|
2024-02-16 01:09:04 +03:00
|
|
|
start_pos = long_description.find("# Introduction")
|
2021-06-02 00:02:55 +03:00
|
|
|
start_pos = 0 if start_pos < 0 else start_pos
|
2024-02-16 01:09:04 +03:00
|
|
|
end_pos = long_description.find("# Contributing")
|
2021-06-02 00:02:55 +03:00
|
|
|
long_description = long_description[start_pos:end_pos]
|
2023-01-13 01:28:32 +03:00
|
|
|
ortx_version = read_version()
|
|
|
|
write_py_version(ortx_version)
|
2021-06-02 00:02:55 +03:00
|
|
|
|
2020-10-20 22:53:14 +03:00
|
|
|
setup(
|
2021-06-10 19:57:49 +03:00
|
|
|
name=PACKAGE_NAME,
|
2023-01-13 01:28:32 +03:00
|
|
|
version=ortx_version,
|
2021-04-13 00:27:10 +03:00
|
|
|
packages=packages,
|
|
|
|
package_dir=package_dir,
|
|
|
|
package_data=package_data,
|
2021-06-02 00:02:55 +03:00
|
|
|
description="ONNXRuntime Extensions",
|
|
|
|
long_description=long_description,
|
2024-02-16 01:09:04 +03:00
|
|
|
long_description_content_type="text/markdown",
|
|
|
|
license="MIT License",
|
|
|
|
author="Microsoft Corporation",
|
|
|
|
author_email="onnxruntime@microsoft.com",
|
|
|
|
url="https://github.com/microsoft/onnxruntime-extensions",
|
2021-01-12 00:44:17 +03:00
|
|
|
ext_modules=ext_modules,
|
2023-11-28 02:39:52 +03:00
|
|
|
cmdclass=_cmds.ortx_cmdclass,
|
2020-10-20 22:53:14 +03:00
|
|
|
include_package_data=True,
|
2024-02-16 01:09:04 +03:00
|
|
|
install_requires=[],
|
2020-10-20 22:53:14 +03:00
|
|
|
classifiers=[
|
2024-02-16 01:09:04 +03:00
|
|
|
"Development Status :: 4 - Beta",
|
|
|
|
"Environment :: Console",
|
|
|
|
"Intended Audience :: Developers",
|
|
|
|
"Operating System :: MacOS :: MacOS X",
|
|
|
|
"Operating System :: Microsoft :: Windows",
|
|
|
|
"Operating System :: POSIX :: Linux",
|
2021-01-12 00:44:17 +03:00
|
|
|
"Programming Language :: C++",
|
2024-02-16 01:09:04 +03:00
|
|
|
"Programming Language :: Python",
|
2021-01-12 00:44:17 +03:00
|
|
|
"Programming Language :: Python :: Implementation :: CPython",
|
2024-02-16 01:09:04 +03:00
|
|
|
"License :: OSI Approved :: MIT License",
|
|
|
|
],
|
2020-10-20 22:53:14 +03:00
|
|
|
)
|