Running custom setuptools build during install

╄→尐↘猪︶ㄣ 提交于 2019-11-30 19:24:29

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!