可以使用setuptools以编程方式打包和分发Python包,并创建安装程序或客户端安装脚本。以下是一个示例,显示如何在安装程序或客户端安装脚本中指定自定义构建选项以从远程仓库安装Python包:
from setuptools import setup, Command
from distutils.command.build import build
class MyBuildCommand(build):
def run(self):
# Your custom build commands here:
self.run_command('build_ext')
build.run(self)
class InstallCommand(Command):
user_options = []
def initialize_options(self):
# Your custom initialization options here:
pass
def finalize_options(self):
# Your custom finalization options here:
pass
def run(self):
# Your custom install commands here:
self.run_command('build')
self.run_command('bdist_wheel')
self.run_command('bdist_wininst')
self.run_command('bdist_msi')
setup(
# Your package information here:
name='my_package',
version='1.0.0',
description='My awesome package',
url='https://github.com/my_package',
author='Me',
author_email='me@my_package.com',
license='MIT',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
keywords='example documentation tutorial',
packages=['my_package'],
install_requires=['requests', 'numpy'],
# Your custom build options here:
cmdclass={
'build': MyBuildCommand,
'install': InstallCommand
}
)
在此示例中,“MyBuildCommand”和“InstallCommand”是自定义命令类。您可以使用任何名称来指定这些类,并在“cmdclass”字典