如何在setup()
参数中传递自定义键值对?我需要他们进行自定义build_scripts
步骤。
from distutils.core import setup
from somescripts import build_scripts
setup(name='somescripts',
version=__version__,
cmdclass= {
'build_scripts': build_scripts,
},
custom_pairs={
'compile_modules': True,
'use_scons': True,
'modules': [f for f in glob('scripts/[!_]*.spy')],
},
)
这给出了"用户警告:未知的分发选项"在setup.py install
中(与--strict
会产生错误)
c:\python27\Lib\distutils\dist.py:267: UserWarning: Unknown distribution
option: 'custom_pairs'
warnings.warn(msg)
更新:
build_scripts
kwarg为空,则scripts
答案 0 :(得分:0)
找到自己的方式。
from distutils.command.build_scripts import build_scripts as base
from distutils.core import setup
# patch distutils so that it won't skip "build_scripts"
# step if `scripts` list is empty
from distutils.dist import Distribution
def custom_has_scripts(self):
return True
Distribution.has_scripts = custom_has_scripts
class build_scripts(base):
def initialize_options(self):
self.compile_modules = None
self.use_scons = None
self.modules = None
def run(self):
for module in self.modules:
# generate scripts
pass
setup(name='somescripts',
version=__version__,
cmdclass= {
'build_scripts': build_scripts,
},
options={
'build_scripts':{
'compile_modules': True,
'use_scons': True,
'modules': [f for f in glob('scripts/[!_]*.spy')],
},
},
)