Search code examples
pythondistutilssdist

Force `sdist` to create .zip archive even on Linux


I know it is possible to force sdist to produce .zip from command line:

python setup.py sdist --formats=zip

But how to make this option a default for my setup.py?

I'd like to get consistency for running setup.py sdist on both Windows and Linux, and I choose .zip format, because I can turn .zip into executable.


Solution

  • Found it myself from distutils docs here and here, and from 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},
    )