#!/usr/bin/env pythonimport distutilsfrom distutils.command.build import build as _buildfrom setuptools.command.develop import develop as _developfrom wheel.bdist_wheel import bdist_wheel as _bdist_wheelfrom setuptools import Distributionfrom setuptools import setup, Commandimport os# Disable SourceLink during the build until it can read repo-format v1, #1613os.environ["EnableSourceControlManagerQueries"] = "false"class DotnetLib:def __init__(self, name, path, **kwargs):self.name = nameself.path = pathself.args = kwargsclass build_dotnet(Command):"""Build command for dotnet-cli based builds"""description = "Build DLLs with dotnet-cli"user_options = [("dotnet-config=", None, "dotnet build configuration"),("inplace","i","ignore build-lib and put compiled extensions into the source "+ "directory alongside your pure Python modules",),]def initialize_options(self):self.dotnet_config = Noneself.build_lib = Noneself.inplace = Falsedef finalize_options(self):if self.dotnet_config is None:self.dotnet_config = "release"build = self.distribution.get_command_obj("build")build.ensure_finalized()if self.inplace:self.build_lib = "."else:self.build_lib = build.build_libdef run(self):dotnet_modules = self.distribution.dotnet_libsfor lib in dotnet_modules:output = os.path.join(os.path.abspath(self.build_lib), lib.args.pop("output"))rename = lib.args.pop("rename", {})opts = sum([["--" + name.replace("_", "-"), value]for name, value in lib.args.items()],[],)opts.extend(["--configuration", self.dotnet_config])opts.extend(["--output", output])self.announce("Running dotnet build...", level=distutils.log.INFO)self.spawn(["dotnet", "build", lib.path] + opts)for k, v in rename.items():source = os.path.join(output, k)dest = os.path.join(output, v)if os.path.isfile(source):try:os.remove(dest)except OSError:passself.move_file(src=source, dst=dest, level=distutils.log.INFO)else:self.warn("Can't find file to rename: {}, current dir: {}".format(source, os.getcwd()))# Add build_dotnet to the build tasks:class build(_build):sub_commands = _build.sub_commands + [("build_dotnet", None)]class develop(_develop):def install_for_development(self):# Build extensions in-placeself.reinitialize_command("build_dotnet", inplace=1)self.run_command("build_dotnet")return super().install_for_development()class bdist_wheel(_bdist_wheel):def finalize_options(self):# Monkey patch bdist_wheel to think the package is pure even though we# include DLLssuper().finalize_options()self.root_is_pure = True# Monkey-patch Distribution s.t. it supports the dotnet_libs attributeDistribution.dotnet_libs = Nonecmdclass = {"build": build,"build_dotnet": build_dotnet,"develop": develop,"bdist_wheel": bdist_wheel,}dotnet_libs = [DotnetLib("python-runtime","src/runtime/Python.Runtime.csproj",output="pythonnet/runtime",)]setup(cmdclass=cmdclass,dotnet_libs=dotnet_libs,)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。