Python setuptools: custom targets

From wikinotes

Setuptools is extensible, and similar to make you can define your own build targets.

Documentation

Tutorials

add custom build steps to setup.py https://jichu4n.com/posts/how-to-add-custom-build-steps-and-commands-to-setuppy/

Examples

taskmage https://github.com/willjp/vim-taskmage

Syntax

Custom targets are expressed as setuptools.Command subclasses.

class VimTest(setuptools.Command):
    """ ``python setup.py vimtest`` installs vader/jellybeans vim plugins and executes tests.
    """
    description = 'run vimfile tests (using Vader.vim)'

    # --interactive/-i
    # --xml
    user_options = [
        ('interactive', 'i', 'instead of printing to stdout, runs vader interactively in vim'),
        ('xml', None, 'in addition to measuring both source-coverage types, produces coverage.xml file'),
    ]

    def initialize_options(self):
        """ pre-hook to change options
        """
        self.interactive = False
        self.xml = False

    def finalize_options(self):
        """ post-hook to change options
        """
        pass

    def run(self):
        """ run command
        """
        print('hi')
setuptools.setup(
    cmdclass={
        "test_vim": VimTest,
    }
)
python setup.py test_vim -i