Running custom setuptools build during install

前端 未结 1 1027
情歌与酒
情歌与酒 2021-01-04 20:23

I\'ve tried to implement Compass compiling during setuptools\' build, but the following code runs compilation during explicit build command and doe

1条回答
  •  鱼传尺愫
    2021-01-04 20:54

    Unfortunatelly, I haven't found the answer. Seems like the ability to run post-install scripts correctly there's only at Distutils 2. Now you can use this work-around:

    Update: Because of setuptools' stack checks, we should override install.do_egg_install, not run method:

    from setuptools.command.install import install
    
    class Install(install):
        def do_egg_install(self):
            self.run_command('build_css')
            install.do_egg_install(self)
    

    Update2: easy_install runs exactly bdist_egg command which is used by install too, so the most correct way (espetially if you want to make easy_install work) is to override bdist_egg command. Whole code:

    #!/usr/bin/env python
    
    import setuptools
    from distutils.command.build import build as _build
    from setuptools.command.bdist_egg import bdist_egg as _bdist_egg
    
    
    class bdist_egg(_bdist_egg):
        def run(self):
            self.run_command('build_css')
            _bdist_egg.run(self)
    
    
    class build_css(setuptools.Command):
        description = 'build CSS from SCSS'
    
        user_options = []
    
        def initialize_options(self):
            pass
    
        def finalize_options(self):
            pass
    
        def run(self):
            pass # Here goes CSS compilation.
    
    
    class build(_build):
        sub_commands = _build.sub_commands + [('build_css', None)]
    
    
    setuptools.setup(
    
        # Here your setup args.
    
        cmdclass={
            'bdist_egg': bdist_egg,
            'build': build,
            'build_css': build_css,
        },
    )
    

    You may see how I've used this here.

    0 讨论(0)
提交回复
热议问题