2016-01-10 41 views
0

如何在setup()參數中傳遞自定義鍵值對?我需要他們進行自定義build_scripts步驟。setup.py中的自定義分發選項

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')], 
     }, 
) 

這給 「UserWarning:未知分發選項」,在setup.py install(其變成誤差--strict

c:\python27\Lib\distutils\dist.py:267: UserWarning: Unknown distribution 
option: 'custom_pairs' 
warnings.warn(msg) 

UPDATE

  • 的distutils沒有致電build_scripts全部如果scripts kwarg爲空
+0

IIRC你應該直接在'setup()'調用中使用它們作爲參數,而不是打包成字典。 – Lav

+0

@Lav他們仍然都是'未知的分佈選項' –

+0

嗯,實際上你在哪裏找到這些選項?我沒有很多distutils的經驗,但我已經檢查了distutils和setuptools的參考資料,以及它們的源代碼,並且無法在任何地方找到這些選項。 – Lav

回答

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')], 
      }, 
     }, 
)