Python setuptools自定义安装传递设置选项以运行方法

时间:2013-10-10 12:41:06

标签: python setuptools

我想为Python包创建一个安装脚本,它在不同的体系结构上表现不同。

我从以下开始:

class CustomInstallCommand(install):
    def run(self):
        if 'win32' in sys.platform:
            if not os.path.exists('./.setup'):
               os.mkdir('./.setup')
            urllib.urlretrieve(("http://www.voidspace.org.uk/downloads/"
                              "pycrypto26/pycrypto-2.6.win32-py2.7.exe"),
                               os.path.join('./.setup',
                                            ('pycrypto-2.6.win32-py2.7.exe')))
            os.system('easy_install '
                      + os.path.join('./.setup',
                                     'pycrypto-2.6.win32-py2.7.exe'))
        ### here should come more windows specific instructions
        ### how do I get my setup script to download all the dependecies given below???

        install.run(self)
    else:
        install.run(self)


setup(... trimmed ...

      zip_safe=False,
      install_requires=['pycrypto>=2.6',
                        'colorama>=0.2.4',
                        'dependency1>=0.1,
                        'dependency2>=0.0.1],
      classifiers=[
          'Environment :: Console',
          'Intended Audience :: End Users/Desktop',
          'Intended Audience :: Developers',
          'Intended Audience :: System Administrators',
          'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
          'Operating System :: MacOS :: MacOS X',
          'Operating System :: Microsoft :: Windows',
          'Operating System :: POSIX',
          'Programming Language :: Python',
          'Programming Language :: Python :: 2.7'
      ],
      cmdclass={'install': CustomInstallCommand},

      )

我可以使用sys.platfrom来检测架构,但是如何让CustomInstallCommand知道设置选项呢?

更新

self.distribution.install_requires处查看run方法时,我发现了这个self。现在我只需要弄清楚如何安装依赖项。因为似乎只是调用install.run(self)不会安装colorama和其他依赖项。

0 个答案:

没有答案