Python setuptools 自定义配置

标签 python setup.py

我正在打包一个 Python 模块,我希望用户能够使用一些自定义选项构建该模块。具体来说,如果您为它提供它可以使用的某些可执行文件,该包将发挥一些额外的作用。

理想情况下,用户将运行 setup.py installsetup.py install --magic-doer=/path/to/executable。如果他们使用第二个选项,我会在代码中的某处设置一个变量,然后从那里开始。

使用 Python 的 setuptools 可以吗?如果可以,我该怎么做?

最佳答案

看来你可以......阅读this .

文章摘录:

Commands are simple class that derives from setuptools.Command, and define some minimum elements, which are:

description: describe the command
user_options: a list of options
initialize_options(): called at startup
finalize_options(): called at the end
run(): called to run the command

The setuptools doc is still empty about subclassing Command, but a minimal class will look like this:

 class MyCommand(Command):
     """setuptools Command"""
     description = "run my command"
     user_options = tuple()
     def initialize_options(self):
         """init options"""
         pass

     def finalize_options(self):
         """finalize options"""
         pass

     def run(self):
         """runner"""
         XXX DO THE JOB HERE

The class can then be hook as a command, using an entry point in its setup.py file:

 setup(
     # ...
     entry_points = {
     "distutils.commands": [
     "my_command = mypackage.some_module:MyCommand"]}

关于Python setuptools 自定义配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1887641/

相关文章:

python / Pandas : Search for a word in a DataFrame column and take it's value from a dictionary

python - 创建独立的轮子

python - 为什么我不能导入我自己创建的Python包?

python setup.py 在 osx 上失败并出现 ssl 错误

python - 由于 setup.py egg_info 文件无法安装 pysal

python - 使用 python 和 FFT 计算均方位移

python - 如何在不使用for循环的情况下对python中的数组进行下采样

Python:替换多个列表中出现的项目?

python - python 包安装位置与前缀不一致

python - 在Python中批量启动线程