强制`sdist`即使在Linux上也可以创建.zip存档

时间:2015-01-17 10:37:35

标签: python distutils sdist

我知道可以强制sdist从命令行生成.zip:

python setup.py sdist --formats=zip

但是如何将此选项设为我的setup.py的默认设置?

我想在Windows和Linux上运行setup.py sdist一致,我选择.zip格式,因为我可以turn .zip into executable

1 个答案:

答案 0 :(得分:2)

我自己来自distutils docs herehere以及来自distutils sources

# Override sdist to always produce .zip archive
from distutils.command.sdist import sdist as _sdist
class sdistzip(_sdist):
    def initialize_options(self):
        _sdist.initialize_options(self)
        self.formats = 'zip'

setup(
    ...
    cmdclass={'sdist': sdistzip},
)