我想为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和其他依赖项。